owlapy.owl_reasoner_rdflib
RDFLib-based OWL Reasoner - Pure Python implementation.
Attributes
Classes
A pure Python OWL reasoner based on RDFLib. |
Module Contents
- owlapy.owl_reasoner_rdflib.logger
- class owlapy.owl_reasoner_rdflib.RDFLibReasoner(ontology: owlapy.abstracts.abstract_owl_ontology.AbstractOWLOntology | str, *, class_cache: bool = True, property_cache: bool = True, infer_property_values: bool = False, infer_data_property_values: bool = False, negation_default: bool = True, sub_properties: bool = False)[source]
Bases:
owlapy.abstracts.abstract_owl_reasoner.AbstractOWLReasonerA pure Python OWL reasoner based on RDFLib.
This reasoner uses SPARQL queries over an RDF graph to perform reasoning tasks. It’s designed as a drop-in replacement for StructuralReasoner with better predictability and no owlready2/Java dependencies for basic operations.
Features: - Pure Python implementation using RDFLib - SPARQL-based reasoning - Efficient graph traversal with caching - Support for basic OWL 2 class expressions - Direct and indirect hierarchy navigation for classes, object properties and data properties - Domain/range, equivalence, disjointness and same/different-individual queries, including the
RDF-list-based owl:AllDisjointProperties/owl:AllDifferent axiom forms
Limitations: - Does not perform OWL 2 DL inference/entailment (use HermiT/Pellet via SyncReasoner for that) —
results reflect asserted axioms plus simple transitive closure over sub-class/sub-property hierarchies, not full description logic reasoning
Best suited for ontology navigation and simple instance retrieval
Does not handle all complex class expressions (nominals, cardinalities may be limited)
- instances(ce: owlapy.class_expression.OWLClassExpression, direct: bool = False, timeout: int = 1000) Iterable[owlapy.owl_individual.OWLNamedIndividual][source]
Get individuals that are instances of the specified class expression.
- Parameters:
ce – The class expression whose instances are to be retrieved.
direct – If True, retrieve only direct instances (not implemented - returns all).
timeout – Timeout in milliseconds (for compatibility, not enforced).
- Returns:
Iterable of named individuals that are instances of ce.
- sub_classes(ce: owlapy.class_expression.OWLClassExpression, direct: bool = False, only_named: bool = True) Iterable[owlapy.class_expression.OWLClassExpression][source]
Get subclasses of the specified class expression.
- Parameters:
ce – The class expression whose subclasses are to be retrieved.
direct – If True, only direct subclasses; if False, all descendant subclasses.
only_named – If True, only return named classes (OWLClass instances).
- Returns:
Iterable of subclass expressions.
- super_classes(ce: owlapy.class_expression.OWLClassExpression, direct: bool = False, only_named: bool = True) Iterable[owlapy.class_expression.OWLClassExpression][source]
Get superclasses of the specified class expression.
- Parameters:
ce – The class expression whose superclasses are to be retrieved.
direct – If True, only direct superclasses; if False, all ancestor superclasses.
only_named – If True, only return named classes (OWLClass instances).
- Returns:
Iterable of superclass expressions.
- equivalent_classes(ce: owlapy.class_expression.OWLClassExpression, only_named: bool = True) Iterable[owlapy.class_expression.OWLClassExpression][source]
Get classes equivalent to the specified class expression.
- Parameters:
ce – The class expression.
only_named – If True, only return named classes.
- Returns:
Iterable of equivalent class expressions.
- disjoint_classes(ce: owlapy.class_expression.OWLClassExpression, only_named: bool = True) Iterable[owlapy.class_expression.OWLClassExpression][source]
Get classes disjoint with the specified class expression.
- Parameters:
ce – The class expression.
only_named – If True, only return named classes.
- Returns:
Iterable of disjoint class expressions.
- object_property_values(ind: owlapy.owl_individual.OWLNamedIndividual, pe: owlapy.owl_property.OWLObjectPropertyExpression, direct: bool = True) Iterable[owlapy.owl_individual.OWLNamedIndividual][source]
Get object property values for an individual.
- Parameters:
ind – The individual.
pe – The object property expression.
direct – Whether to consider only direct assertions.
- Returns:
Iterable of individuals that are values of the property for ind.
- get_root_ontology() owlapy.abstracts.abstract_owl_ontology.AbstractOWLOntology[source]
Gets the root ontology that is loaded into this reasoner.
- types(ind: owlapy.owl_individual.OWLNamedIndividual, direct: bool = False) Iterable[owlapy.class_expression.OWLClass][source]
Gets the named classes which are (potentially direct) types of the specified named individual.
- Parameters:
ind – The individual whose types are to be retrieved.
direct – If True, only direct types; if False, all types.
- Returns:
Iterable of OWLClass representing the types of the individual.
- data_property_domains(pe: owlapy.owl_property.OWLDataProperty, direct: bool = False) Iterable[owlapy.class_expression.OWLClassExpression][source]
Gets the class expressions that are the domains of this data property.
- object_property_domains(pe: owlapy.owl_property.OWLObjectProperty, direct: bool = False) Iterable[owlapy.class_expression.OWLClassExpression][source]
Gets the class expressions that are the domains of this object property.
- object_property_ranges(pe: owlapy.owl_property.OWLObjectProperty, direct: bool = False) Iterable[owlapy.class_expression.OWLClassExpression][source]
Gets the class expressions that are the ranges of this object property.
- data_property_values(e: owlapy.owl_individual.OWLNamedIndividual, pe: owlapy.owl_property.OWLDataProperty) Iterable[owlapy.owl_literal.OWLLiteral][source]
Gets the data property values for the specified entity and data property.
- different_individuals(ind: owlapy.owl_individual.OWLNamedIndividual) Iterable[owlapy.owl_individual.OWLNamedIndividual][source]
Gets the individuals that are different from the specified individual.
- same_individuals(ind: owlapy.owl_individual.OWLNamedIndividual)[source]
Gets the individuals that are the same as the specified individual.
- equivalent_object_properties(op: owlapy.owl_property.OWLObjectPropertyExpression) Iterable[owlapy.owl_property.OWLObjectPropertyExpression][source]
Gets the object properties that are equivalent to the specified object property.
- equivalent_data_properties(dp: owlapy.owl_property.OWLDataProperty) Iterable[owlapy.owl_property.OWLDataProperty][source]
Gets the data properties that are equivalent to the specified data property.
- disjoint_object_properties(op: owlapy.owl_property.OWLObjectPropertyExpression) Iterable[owlapy.owl_property.OWLObjectPropertyExpression][source]
Gets the object properties that are disjoint with the specified object property.
- disjoint_data_properties(dp: owlapy.owl_property.OWLDataProperty) Iterable[owlapy.owl_property.OWLDataProperty][source]
Gets the data properties that are disjoint with the specified data property.
- sub_object_properties(op: owlapy.owl_property.OWLObjectPropertyExpression, direct: bool = False) Iterable[owlapy.owl_property.OWLObjectPropertyExpression][source]
Gets the sub object properties of the specified object property.
- super_object_properties(op: owlapy.owl_property.OWLObjectPropertyExpression, direct: bool = False) Iterable[owlapy.owl_property.OWLObjectPropertyExpression][source]
Gets the super object properties of the specified object property.
- sub_data_properties(dp: owlapy.owl_property.OWLDataProperty, direct: bool = False) Iterable[owlapy.owl_property.OWLDataProperty][source]
Gets the sub data properties of the specified data property.
- super_data_properties(dp: owlapy.owl_property.OWLDataProperty, direct: bool = False) Iterable[owlapy.owl_property.OWLDataProperty][source]
Gets the super data properties of the specified data property.