Loge: RDF smoke test
root = Path.expand("..", __DIR__)
Mix.install([
{:loge, path: Path.join(root, "loge"), override: true},
{:loge_turtle, path: Path.join(root, "loge_turtle")},
{:loge_sparql, path: Path.join(root, "loge_sparql")},
{:loge_shex, path: Path.join(root, "loge_shex")},
{:kino_loge, path: Path.join(root, "kino_loge")}
])
Data
A Logic Source cell binds a graph in Turtle to people. Expected: no diagnostics.
people =
Loge.source(
:turtle,
"@prefix : <http://example.org/> .\n\n:alice :name \"Alice\" ; :age 30 ; :knows :bob .\n:bob :name \"Bob\" ; :age \"unknown\" ; :knows :carol .\n:carol :name \"Carol\" .\n"
)
Querying
A query is asked of a graph: the cell's Data select is the query's role, here
people. Expected: Yes, a table of who knows whom: Alice knows Bob, Bob knows Carol.
Loge.run!(
Loge.Sparql.Engines.Query,
"PREFIX : <http://example.org/>\n\nSELECT ?person ?friend WHERE {\n ?p :knows ?f .\n ?p :name ?person .\n ?f :name ?friend\n}\nORDER BY ?person\n",
data: people,
time_limit: 30
)
A CONSTRUCT builds a graph, bound to acquaintances. Expected: Success, the graph
in Turtle under the Result tab.
acquaintances =
Loge.run!(
Loge.Sparql.Engines.Query,
"PREFIX : <http://example.org/>\n\nCONSTRUCT { ?b :knownBy ?a } WHERE { ?a :knows ?b }\n",
data: people,
time_limit: 30
)
That graph is the data of the next query. Expected: Yes, two rows.
Loge.run!(
Loge.Sparql.Engines.Query,
"PREFIX : <http://example.org/>\n\nSELECT ?x ?y WHERE { ?x :knownBy ?y }\n",
data: acquaintances,
time_limit: 30
)
Expected: No: Carol knows nobody.
Loge.run!(
Loge.Sparql.Engines.Query,
"PREFIX : <http://example.org/>\n\nASK { :carol :knows ?anyone }\n",
data: people,
time_limit: 30
)
Validating with SHACL
The cell holds the shapes and its Data role the graph they validate. Expected: Nonconformant, one result: Bob's age is not an integer.
Loge.run!(
Loge.Turtle.Engines.Shacl,
"@prefix : <http://example.org/> .\n@prefix sh: <http://www.w3.org/ns/shacl#> .\n@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n\n:Person a sh:NodeShape ;\n sh:targetSubjectsOf :name ;\n sh:property [ sh:path :name ; sh:datatype xsd:string ; sh:minCount 1 ] ;\n sh:property [ sh:path :age ; sh:datatype xsd:integer ; sh:maxCount 1 ] .\n",
data: people,
time_limit: 30
)
Without data, a graph is validated against the shapes it contains. Expected: Conformant.
Loge.run!(
Loge.Turtle.Engines.Shacl,
"@prefix : <http://example.org/> .\n@prefix sh: <http://www.w3.org/ns/shacl#> .\n@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n\n:Book a sh:NodeShape ;\n sh:targetClass :Book ;\n sh:property [ sh:path :title ; sh:datatype xsd:string ; sh:minCount 1 ] .\n\n:dune a :Book ; :title \"Dune\" .\n:solaris a :Book ; :title \"Solaris\" .\n",
time_limit: 30
)
Validating with ShEx
A ShEx schema in a Logic Source cell, bound to schema:
schema =
Loge.source(
:shex,
"PREFIX : <http://example.org/>\nPREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n\n:Person {\n :name xsd:string ;\n :age xsd:integer ? ;\n :knows IRI *\n}\n"
)
A shape map says which nodes are validated against which shapes; its roles are the schema and the data. Expected: Conformant, Alice and Carol.
Loge.run!(Loge.Shex.Engines.Validate, ":alice@:Person, :carol@:Person\n",
schema: schema,
data: people,
time_limit: 30
)
Expected: Nonconformant, with the reason: Bob's age is a string.
Loge.run!(Loge.Shex.Engines.Validate, ":bob@:Person\n",
schema: schema,
data: people,
time_limit: 30
)
An endpoint
A query on a public endpoint, here Wikidata, chosen in the Endpoint field. It needs the network. Expected: Yes, three cats.
Loge.run!(
Loge.Sparql.Engines.Endpoint,
"SELECT ?cat WHERE {\n ?cat <http://www.wikidata.org/prop/direct/P31> <http://www.wikidata.org/entity/Q146>\n}\nLIMIT 3\n",
endpoint: "Wikidata",
time_limit: 30
)
Linting
Expected: under the editor, a syntax error where the reader stopped, at the end of the
pattern ?x ?y; evaluating raises Loge.Error with it.
Loge.run!(Loge.Sparql.Engines.Query, "SELECT * WHERE { ?x ?y }\n", data: people, time_limit: 30)
A shape map is read with the data's and the schema's prefixes. Expected: under the
editor, ex is not declared.
Loge.run!(Loge.Shex.Engines.Validate, "ex:alice@:Person\n",
schema: schema,
data: people,
time_limit: 30
)