LeanRDF

Reference

Five Lake packages share one repository. leanrdf (the root) has no dependencies; leanrdf-sparql, leanrdf-owl and leanrdf-shacl require only leanrdf; leanrdf-elpi (elpi/) requires leanrdf, leanrdf-owl and lean-elpi v0.3.3. All use Lean 4.35.0. Packages and installation explains how to depend on each, and the documentation has a guide per package.

-- lakefile.lean of a project using the model and the checker
require leanrdf from git "https://github.com/Volland/rdf-lean" @ "main"
-- or a sub-package, by its directory
require «leanrdf-shacl» from git "https://github.com/Volland/rdf-lean" @ "main" / "shacl"

leanrdf

ModuleMain contents
LeanRDF.Core.TermIRI, BlankNode, Literal (typed, lang), Term
LeanRDF.Core.LiteralLiteral.datatype, mk?, lang', str, WellFormed
LeanRDF.Core.TripleTriple, WellFormed, mk?, renameBNodes
LeanRDF.Core.GraphGraph, empty, insert, union, singleton, ofList, toList, size, mem_*
LeanRDF.Core.IsoGraph.Iso, Iso.refl
LeanRDF.Core.Vocabrdf.*, rdfs.*, xsd.string, rdf.member n
LeanRDF.Parse.NTriples.*NTriples.parse, parseTriples, parseTerm, ParseError, Graph.toNTriples, Term.toNTriples
LeanRDF.Parse.Turtle.*Turtle.parse src base, parseTriples, parseTriG, resolve
LeanRDF.Core.DatasetQuad, Dataset, defaultGraph, namedGraph, graphNames, unionGraph, ofGraph, mem_*
LeanRDF.Parse.NQuads.*NQuads.parse, NTriples.parseQuads, Dataset.toNQuads
LeanRDF.Parse.TriG.ParserTriG.parse src base
LeanRDF.Xsd.*Literal.value?, XsdValue, XsdValue.compare?, canonicalInteger, canonicalDecimal?, canonicalDouble, DateTime
LeanRDF.Semantics.InterpretationSimpleInterp, denote, Holds, Satisfies, InClass, DInterp
LeanRDF.Semantics.RDFSRDFConditions, RDFSConditions, IsRDF, IsRDFS, RDFSCore, IsRDFS.toCore
LeanRDF.Semantics.EntailsGraph.SimpleEntails, DEntails, RDFEntails, RDFSEntails
LeanRDF.Entailment.RulePat, TPat, Guard, Rule, RangeRestricted, UniqueNames
LeanRDF.Entailment.Rulesrdfs2 … rdfs13, rdfD2, grdfD1String, grdfD1Lang, axiomRules, rdfsRules
LeanRDF.Entailment.DerivationDerives, Triple.instantiate
LeanRDF.Entailment.SoundnessRule.Sound, rdfsRules_sound, Derives.sound, Derives.sound_graph
LeanRDF.Cert.CheckNode, Certificate, check, checkQuery, check_sound, checkQuery_sound, checkB_sound, checkQueryB_sound
LeanRDF.Cert.JsonCertificate.render, Certificate.parse, Certificate.toJson, Certificate.ofJson
LeanRDF.Cert.DatalogtoDatalog (CertifyingDatalog GraphProblemInput)

leanrdf-elpi

ModuleMain contents
LeanRDFElpi.EncodeencodeTerm, decodeTerm, encodeTriple, decodeTriple
LeanRDFElpi.CodegenstepClauses (rules to Elpi clauses)
LeanRDFElpi.Saturateprogram, saturate, Entry, Closure
LeanRDFElpi.Certifycertify, entailmentCertificate (any rule list: saturate rules g then certify)
LeanRDFElpi.Demorun, verdict; executable leanrdf-demo
LeanRDFElpi.Classifyclassify, Edge, render; executable leanrdf-classify
LeanRDFElpi.Oxilite.*parseResults, patternQuery, instantiate, WhyNode, certificateOfWhy, certifyByElpi, certifyByWhy, Profile, run, runMaterialized; lake exe leanrdf-oxilite

leanrdf-sparql

leanrdf-sparql (sparql/) requires leanrdf.

ModuleMain definitions
LeanRDFSparql.MappingMapping, find?, insert, merge, restrict, compatible, ext
LeanRDFSparql.AlgebraTermPat, TriplePattern, Expr, Pattern, Query, subst, size
LeanRDFSparql.ExprExpr.eval, ebv, termEq, termCmp, callBuiltin, castTo
LeanRDFSparql.SemanticsSpec.bgp, Spec.join, Spec.leftJoin, Spec.minus, Spec.evalN, Spec.eval
LeanRDFSparql.EvalEval.matchTP, Eval.bgp, Eval.evalN, Eval.eval
LeanRDFSparql.BgpCorrect, Correct, Querybgp_perm, evalN_perm, eval_perm_spec, orderBy_sorted, Spec.Answer, Eval.runQuery, runQuery_answer
LeanRDFSparql.Syntax, ParserSQuery, GElem, parseQuery, validateQuery, translateQuery, SQuery.toAlgebra
LeanRDFSparql.Results, RunAnswer, toJson, toXml, toCsv, toTsv, ofJson, ofXml, ofTsv, execute, runCommand; lake exe leanrdf-sparql
LeanRDFSparql.Hashmd5, sha1, sha256, sha384, sha512
LeanRDF.Text.Regex (core)compile, isMatch, replace

leanrdf-owl

leanrdf-owl (owl/) requires leanrdf; leanrdf-elpi requires it for the OWL profile.

ModuleMain definitions
LeanRDFOwl.Vocabthe OWL IRIs (Owl.sameAs, Owl.inverseOf, …), owlAxioms
LeanRDFOwl.SemanticsOWLConds, OWLCore, DInterp.IsOWL, Graph.OWLEntails, sameAs_iff
LeanRDFOwl.Rulesthe 49 OWL 2 RL rules, owlRLDerivationRules, owlRLRules, owlRules
LeanRDFOwl.Soundnessone *_sound per rule, owlRules_sound, Derives.owl_sound, Derives.owl_sound_graph
LeanRDFOwl.Lists, EL, ELSoundnessListOf, intersection_two, intersection_three, the EL rules, elRules, owlELRules, elRules_sound, Derives.el_sound

leanrdf-shacl

leanrdf-shacl (shacl/) requires leanrdf.

ModuleMain definitions
LeanRDFShacl.PathPath, ValueNode, valueNodes, valueNodes_iff, closure
LeanRDFShacl.ShapesShape, Component, TermTest, Target, TermTest.ok, Component.iri
LeanRDFShacl.SemanticsVN, InstanceOf, Conforms, CompHolds, IsFocus, DataConforms
LeanRDFShacl.Validate, Correctresults, validate, Report, results_nil, validate_conforms, validate_sound
LeanRDFShacl.Read, Report, RunreadShapes, Report.toTurtle, runCommand; lake exe leanrdf-shacl validate

Key theorems

theorem Derives.sound {g : Graph} {t : Triple} (h : Derives rdfsRules g t) :
    g.RDFSEntails (Graph.singleton t)

theorem Derives.sound_graph {g q : Graph} (μ : BlankNode → Term)
    (h : ∀ t ∈ q, Derives rdfsRules g (t.instantiate μ)) : g.RDFSEntails q

theorem check_sound (h : check rules g c = .ok t) : Derives rules g t

theorem checkQuery_sound (h : checkQuery RDFS.rdfsRules g q c = .ok ()) : g.RDFSEntails q

-- XSD values: canonical forms read back, comparison is the order of Int and Rat
theorem Xsd.parseInteger_canonical (n : Int) : parseInteger (canonicalInteger n) = some n
theorem Xsd.parseDecimal_canonical (q : Rat) (s : String) (h : canonicalDecimal? q = some s) :
    parseDecimal s = some q
-- SPARQL: the evaluator computes the semantics
theorem evalN_perm (n : Nat) (D : Dataset) (G : Graph) (P : Pattern) :
    Eval.evalN n D G P ~ Spec.evalN n D G P
theorem runQuery_answer (D : Dataset) (q : Query) : Spec.Answer D q (Eval.runQuery D q)
-- SHACL: the report conforms exactly when the data conforms, and every result is real
theorem validate_conforms (G : Graph) (S : List Shape) :
    (validate G S).conforms = true ↔ DataConforms G S
theorem validate_sound (G : Graph) (S : List Shape) {r : Result} (h : r ∈ (validate G S).results) :
    Violation G r
-- OWL 2 RL: every rule is sound for the OWL conditions
theorem owlRules_sound : ∀ r ∈ owlRules, r.SoundIn OWLCore
theorem Derives.owl_sound {g : Graph} {t : Triple} (h : Derives owlRules g t) :
    g.OWLEntails (Graph.singleton t)
theorem Derives.el_sound {g : Graph} {t : Triple} (h : Derives owlELRules g t) :
    g.OWLEntails (Graph.singleton t)

theorem Xsd.compare_integer_iff (a b : Int) :
    ((XsdValue.integer a).compare? (.integer b) = some .lt ↔ a < b) ∧
    ((XsdValue.integer a).compare? (.integer b) = some .eq ↔ a = b)

Design and requirements

The design is a typed graph in tg.md/ (decisions, constraints, simplifications), and the requirements and scenarios are OpenSpec capabilities in openspec/specs/. In a checkout:

tg search "certificate checker"
tg trace --gaps