Command-line tools
Seven executables ship with LeanRDF. Run them with lake exe NAME in their package directory, or call the binary in .lake/build/bin/ after lake build. They share one convention for exit codes:
| Code | Meaning |
|---|---|
0 | everything the tool reports was proven, or the query ran |
1 | something was not derived, or the data does not conform |
2 | a certificate was rejected by the verified checker: a bug on the untrusted side |
3 | a usage, input, parse or process error: no verdict |
A 1 is never a claim that something is false. LeanRDF proves that certified things hold, but its rules are not proven complete, so "not derived" only reports that the search found nothing.
Input formats are chosen by file extension: .nt is N-Triples, .nq N-Quads, .trig TriG, and anything else is read as Turtle with the file's file:// path as base IRI. The demo reads N-Triples only; leanrdf-check reads Turtle for .ttl and N-Triples otherwise.
leanrdf-demo
leanrdf-demo DATA.nt QUERY.nt [--profile rdfs|owl] [--cert OUT.json] [--datalog OUT.json] [--countermodel OUT.json]
Is the query graph RDFS-entailed by the data? Blank nodes in the query are existential, so _:x rdf:type ex:Animal asks whether something is an animal. The demo saturates the data in Elpi under the 80 RDFS rules, finds an instance of the query in the closure, cuts out a certificate, checks it with the compiled verified checker and prints:
- the number of data and query triples, and the size of the closure;
- the instance found, one
Query instance: _:b ↦ termline per blank node; - the certificate, one node per line, with its rule and premises;
- the verdict:
ENTAILED,REFUTED,NOT DERIVED,REJECTEDorINCONSISTENT.
When no instance is derived under the RDFS profile, the demo builds a candidate countermodel from the closure. REFUTED (exit 5) is printed only when the verified model checker accepts it, with the regime and D = {xsd:string, rdf:langString, rdf:dirLangString}. Otherwise the verdict stays NOT DERIVED, with the condition the candidate failed.
Before any entailment, the demo looks for a clash in the closure. When the verified checker accepts a clash certificate, the data has no model and every query follows from it. The demo then prints the clash and its certificate, says INCONSISTENT, reports no entailment and exits 4. No clash found is not a claim of consistency.
| Option | Effect |
|---|---|
--profile owl | reason with the 140 RDFS and OWL 2 RL rules and the OWL clash rules instead of the 80 RDFS rules |
--cert OUT.json | write the certificate as JSON (format), or the clash certificate when the data is inconsistent |
--countermodel OUT.json | write the accepted countermodel with its envelope (format) |
--datalog OUT.json | write it as a CertifyingDatalog GraphProblemInput, for an independent check |
Exit codes: 0 entailed and checked, 1 not derived, 2 certificate rejected or search failed, 3 input error, 4 inconsistent, 5 refuted.
cd elpi
lake exe leanrdf-demo examples/pets.nt examples/query-mammal-owner.nt --cert cert.json
lake exe leanrdf-demo ../examples/rdfs-university/university.nt \
../examples/rdfs-university/query-staff-teaches.nt
leanrdf-oxilite
leanrdf-oxilite DATA PATTERN [--oxilite PATH] [--profile rdfs|owl] [--mode elpi|why|both]
[--results FILE] [--why-dir DIR] [--record DIR]
leanrdf-oxilite DATA --materialized [--oxilite PATH] [--inferred FILE] [--record DIR]
Answers. The first form loads DATA into a fresh oxilite store in a temporary directory, asks oxilite for the solutions of PATTERN (a graph whose blank nodes are the variables), and certifies each answer. For every solution it prints the bindings, the result of each route and a verdict:
[1] ?unit = <http://example.org/org#compilers>
elpi: certified
why: untranslated (oxilite gave no rule: explained above)
verdict: CERTIFIED
| Option | Default | Effect |
|---|---|---|
--oxilite PATH | oxilite | the oxilite binary |
--profile rdfs | yes | oxilite reasons with RDFS at query time; certificates are checked against the 80 RDFS rules |
--profile owl | oxilite materializes its OWL 2 RL closure; certificates are checked against owlRules (140 rules) | |
--mode elpi | certify by Elpi search only | |
--mode why | certify from oxilite's why trees only | |
--mode both | yes | both routes; an answer is certified when either certificate is accepted |
--record DIR | save oxilite's results.json and why-N.json in DIR | |
--results FILE | replay recorded results instead of running oxilite | |
--why-dir DIR | replay recorded why-N.json trees |
A route reports certified, not derived, untranslated (the tree could not be turned into a certificate, with the reason) or REJECTED. Exit codes: 0 every answer certified, 1 some answer not certified and none rejected, 2 a certificate rejected, 3 an input or process error, 4 the data is inconsistent (a checked clash, found before any answer is certified; no answer is certified then).
Materialized closure. The second form runs oxilite's OWL 2 RL materialization and certifies every inferred triple it stored, each as its own query. It prints the totals (oxilite inferences: 31, certified: 16) and, per triple, the rule oxilite names and the result. --inferred FILE replays a recorded closure: one line per inference, the rule, a tab, and the triple in N-Triples.
See oxilite for the whole workflow.
leanrdf-classify
leanrdf-classify ONTOLOGY
The certified class hierarchy of an OWL 2 EL ontology (Turtle or N-Triples). It saturates the ontology in Elpi under owlELRules (RDFS, OWL 2 RL and the EL rules), then certifies every derived A rdfs:subClassOf B between named classes as its own query. It prints only certified subsumptions, with names shortened to the part after # or the last /:
certified subsumptions: 36, unsatisfiable classes: 2
:Endocarditis ⊑ :Carditis
...
:PhantomPain ⊑ owl:Nothing (unsatisfiable)
A named class is an IRI outside the RDF, RDFS, OWL and XSD namespaces. Subsumption by owl:Nothing is printed as unsatisfiability. Exit codes: 0 every derived subsumption certified, 1 some not, 2 a certificate rejected, 3 an input or search error, 4 the ontology is inconsistent (a clash certificate accepted under checkClash_sound_el; no hierarchy is printed then).
leanrdf-sparql
leanrdf-sparql query --location FILE --query QUERY [--results-format FORMAT]
Runs a SPARQL 1.1 query with the evaluator that is proven to compute the SPARQL semantics. FORMAT is json (the default), xml, csv or tsv. The flags follow oxilite's and Oxigraph's. FILE may be N-Triples, N-Quads, Turtle or TriG. QUERY is the query text, not a file name, so use --query "$(cat q.rq)".
| Query form | Output |
|---|---|
SELECT | solutions in the chosen format, JSON by default |
ASK | true or false in the chosen format |
CONSTRUCT, DESCRIBE | N-Triples, whatever the format option |
A query with FROM or FROM NAMED is an error: the command line loads no graphs other than FILE. Exit codes: 0 the query ran, 3 an input, parse or evaluation error.
The evaluator is a reference for test-sized data. It is not meant for production.
leanrdf-shacl
leanrdf-shacl validate --data DATA --shapes SHAPES
Validates the data graph against the SHACL Core shapes and prints a validation report in Turtle (sh:ValidationReport with sh:conforms and one sh:result per result). The blank nodes of the shapes graph are renamed apart from the data's. A file may serve as both, with --data g.ttl --shapes g.ttl. Shapes that refer to themselves, directly or through other shapes, are rejected with an error, because SHACL leaves their meaning undefined.
Exit codes: 0 the data conforms, 1 it does not, 3 an input error or ill-formed shapes.
leanrdf-sg
leanrdf-sg check FILE.jsonl
leanrdf-sg export FILE.jsonl [--now | --as-of T | --history] [--valid-at MS]
leanrdf-sg decode FILE.nt [--now | --as-of T | --history] [--valid-at MS]
leanrdf-sg kernel FILE.jsonl
leanrdf-sg quote FILE.jsonl
Works on statement records, one JSON object per line (see Statement graphs). check lists well-formedness violations as eid N: NAME, where NAME is subject-position, object-position, self-reference, tx-interval, valid-interval, reserved-iri or reserved-predicate, and adds dangling references and reference cycles as warnings. export writes the RDF 1.2 export in the view as canonical N-Triples; the default view is --now with no valid-time filter. decode reads such an export back and writes the records as JSON lines, or names the first triple that does not fit. kernel writes the export kernel and the reason each other record was removed. quote writes each kernel record as a nested triple term.
Exit codes: 0 success, and for check well formed, possibly with warnings; 1 check or export found violations; 2 decode rejected its input; 3 an unreadable file or a usage error.
leanrdf-check
leanrdf-check --data DATA [--query QUERY] (--cert CERT.json | --countermodel MODEL.json) [--rules simple|rdf|rdfs|owl|el] [--json] [--emit-envelope OUT.json]
Package check/. Checks a certificate that someone else wrote, with the verified checker and nothing else: the package does not depend on lean-elpi, and the tool never searches. --rules picks the regime (rdfs by default), and with it the rule list and the theorem an acceptance stands for:
| Regime | Rules | Theorem | Entailment |
|---|---|---|---|
simple | none (facts only; the query must be well-formed) | checkQuery_sound_simple | SimpleEntails |
rdf | rdfRules | checkQuery_sound_rdf | RDFEntails |
rdfs | rdfsRules | checkQuery_sound | RDFSEntails |
owl | owlRules | Derives.owl_sound_graph | OWLEntails |
el | owlELRules | Derives.el_sound_graph | OWLEntails |
All five are combined in one theorem, LeanRDF.Check.checkRegime_sound. Exit codes: 0 proven, 2 rejected (with the checker's reason), 3 input error, 4 inconsistent, 5 refuted. There is no 1: a certificate or a countermodel is either accepted or not.
A countermodel (--countermodel FILE) is checked with the data and the query under simple, rdf or rdfs; owl and el are input errors. When checkCountermodel accepts it, the verdict is refuted with exit 5, naming checkCountermodel_sound_simple, _rdf or _rdfs and the datatypes. A rejected countermodel is exit 2, with the failed condition or the assignment under which the query holds.
A clash certificate is checked without --query; giving one is an input error. Under rdfs, owl or el, checkRegimeClash_sound turns its acceptance into the theorem that the data has no model of the regime: checkClash_sound_rdfs, checkClash_sound_owl or checkClash_sound_el. The verdict is inconsistent with exit 4, and the JSON names the clash rule:
{"verdict":"inconsistent","exit":4,"regime":"owl","theorem":"checkClash_sound_owl","clash":"cax-dw","nodes":5,"goals":[],"dataTriples":5,"graph":"sha256:c3aa3570…","bound":true}
Before the proof is checked, the envelope of a version-2 certificate is verified. The tool recomputes the digests of the data and the query it read and of the regime's rule list, and requires the envelope's regime to be the one in use. A mismatch is a rejection that names the field: envelope: graph digest mismatch, envelope: query digest mismatch, envelope: rules digest mismatch or envelope: regime mismatch. A version-1 certificate is checked as before, and the verdict says it is unbound. --emit-envelope OUT.json writes the accepted certificate as version 2, with the envelope filled from the check.
--json writes one object with these fields:
verdict:proven,rejectedorinput-error. The vocabulary also reservesunknown,inconsistentandrefutedfor tools that search.exit,regime,theorem,nodes,goals,mappingandreason.graphandquery: the digests.bound:truewhen the envelope was verified,falsefor version 1.
{"verdict":"proven","exit":0,"regime":"rdfs","theorem":"checkQuery_sound","nodes":7,"goals":[6],"dataTriples":12,"queryTriples":1,"graph":"sha256:b69d5884…","query":"sha256:402b7bd8…","bound":true}
See examples/certificate-check/.
Scripts
| Script | Purpose |
|---|---|
scripts/examples.sh [--update] [GROUP] | run the examples and compare their outputs with expected/; GROUP is all (the default), sparql, shacl, elpi or statements; --update records them |
scripts/examples-record.sh OXILITE | record oxilite's outputs for the oxilite examples |
scripts/statements-tm-record.sh TIRAMEMSU | record tiramemsu's tm export --format sg-nt12 outputs for the statement-graph tests |
scripts/oxilite-fixtures.sh OXILITE | record oxilite's outputs for the bridge tests |
scripts/shacl-oxilite-fixtures.sh OXILITE | record oxilite's SHACL reports for the SHACL tests |
scripts/sparql-diff.sh OXILITE | run the W3C SPARQL suite on oxilite too and write sparql/diff-report.md |
scripts/check_release.py [--online] | check the release contract: licences, metadata, CI workflow |
python3 site/build.py | build this website into _site/ |