djangordf.reasoning¶
Pluggable reasoner layer. Materialise inferred triples into the
configured backend. Pick a reasoner via settings.DJANGORDF_REASONER
(dotted import path) or pass one to
djangordf.reasoning.materialize().
Pluggable reasoner layer.
Materialise inferred triples into the configured backend. Pick a
reasoner via settings.DJANGORDF_REASONER (dotted import path) or
pass one directly to materialize(). Built-in reasoners cover
RDFS and SKOS; an optional OWLRLReasoner wraps the
third-party owlrl library when installed.
- class djangordf.reasoning.CompositeReasoner(*reasoners)[source]¶
Bases:
ReasonerRun several reasoners sequentially within one fixpoint envelope.
- Parameters:
reasoners (Reasoner)
- class djangordf.reasoning.OWLRLReasoner(profile=None)[source]¶
Bases:
ReasonerMaterialise via the
owlrllibrary’s OWL-RL closure.The reasoner loads the source graph into an in-memory
rdflib.Graph, runs the OWL-RL closure, and writes the new triples back into the target graph through the backend.- Parameters:
profile (object | None)
- class djangordf.reasoning.RDFSReasoner[source]¶
Bases:
ReasonerRun canonical RDFS entailment rules to a fixpoint.
- class djangordf.reasoning.Reasoner[source]¶
Bases:
objectBase class for reasoners.
Subclasses override
rules()(returning a sequence of SPARQLINSERT-WHEREstrings) to declare their inference rules. The basematerialize()runs them in a fixpoint loop. Overridematerialize()directly for non-SPARQL reasoners (seeOWLRLReasoner).
- class djangordf.reasoning.SKOSReasoner[source]¶
Bases:
ReasonerRun SKOS entailment rules to a fixpoint.
- djangordf.reasoning.materialize(reasoner=None, backend=None, *, source_graph=None, target_graph=None, max_iterations=50)[source]¶
Programmatic entry point. Resolves
reasonerfrom the argument (instance / class / dotted path) orsettings.DJANGORDF_REASONERand runsmaterializeon it.
Reasoner ABC plus the public materialize entry point.
- class djangordf.reasoning.base.Reasoner[source]¶
Bases:
objectBase class for reasoners.
Subclasses override
rules()(returning a sequence of SPARQLINSERT-WHEREstrings) to declare their inference rules. The basematerialize()runs them in a fixpoint loop. Overridematerialize()directly for non-SPARQL reasoners (seeOWLRLReasoner).
- class djangordf.reasoning.base.CompositeReasoner(*reasoners)[source]¶
Bases:
ReasonerRun several reasoners sequentially within one fixpoint envelope.
- Parameters:
reasoners (Reasoner)
- djangordf.reasoning.base.materialize(reasoner=None, backend=None, *, source_graph=None, target_graph=None, max_iterations=50)[source]¶
Programmatic entry point. Resolves
reasonerfrom the argument (instance / class / dotted path) orsettings.DJANGORDF_REASONERand runsmaterializeon it.
Canonical RDFS reasoner.
Five rules covering rdfs:subClassOf transitivity, type
propagation through subClassOf / subPropertyOf, and domain
/ range inference. Implemented as SPARQL INSERT-WHERE
templates so they execute against any SPARQL 1.1 backend.
- class djangordf.reasoning.rdfs.RDFSReasoner[source]¶
Bases:
ReasonerRun canonical RDFS entailment rules to a fixpoint.
SKOS-specific reasoner.
Propagates skos:broader / skos:narrower to their transitive
variants and closes the transitive predicates under composition.
Also enforces skos:exactMatch symmetry.
- class djangordf.reasoning.skos.SKOSReasoner[source]¶
Bases:
ReasonerRun SKOS entailment rules to a fixpoint.
Optional wrapper around the third-party owlrl library.
Importing this module without owlrl installed raises
ImportError; the materialize() method also raises
ImproperlyConfigured with an install hint if the import
fails late.
- class djangordf.reasoning.owlrl.OWLRLReasoner(profile=None)[source]¶
Bases:
ReasonerMaterialise via the
owlrllibrary’s OWL-RL closure.The reasoner loads the source graph into an in-memory
rdflib.Graph, runs the OWL-RL closure, and writes the new triples back into the target graph through the backend.- Parameters:
profile (object | None)