Python API
API reference
Public classes for consistency checking and direct class hierarchy. HermitPy reads an rdflib graph and does not need a JVM.
hermitpy
Reasoner
Classify one ontology. Construct it from an rdflib.graph.Graph already parsed from Turtle, RDF/XML, or another format rdflib accepts.
Reasoner(graph: Graph)
| Method | Returns | Purpose |
|---|---|---|
is_consistent() | bool | Whether the ontology has a model. |
unsatisfiable_classes() | list[str] | Named class IRIs that are empty in every model. If the ontology is inconsistent, every named class is returned. |
direct_subclasses() | list[tuple[str, str]] | Direct (subclass, superclass) IRI pairs. Equivalent classes appear in both directions. Satisfiable classes with no stricter named parent link to owl:Thing. Unsatisfiable classes link to owl:Nothing. |
from rdflib import Graph
from hermitpy import Reasoner
graph = Graph()
graph.parse("ontology.ttl")
reasoner = Reasoner(graph)
if reasoner.is_consistent():
for child, parent in reasoner.direct_subclasses():
print(child, "rdfs:subClassOf", parent)
rdflib.GraphNo JVM View source โ
hermitpy
Errors
| Exception | When |
|---|---|
UnsupportedConstruct | The graph uses OWL outside the fragment, including datatypes, cardinality, property chains, nominals, role hierarchies, keys, and SWRL. The construct is named on the exception and is not ignored. |
InconsistentOntology | direct_subclasses() was called on an ontology with no model. |
ReasonerLimitExceeded | The tableau exceeded its node or search-depth bound. |
from hermitpy import InconsistentOntology, UnsupportedConstruct
try:
pairs = reasoner.direct_subclasses()
except InconsistentOntology:
print(reasoner.unsatisfiable_classes())
except UnsupportedConstruct as error:
print(error.construct)
OWL fragment
What the reasoner accepts
| Accepted | Raises UnsupportedConstruct |
|---|---|
Named classes, owl:Thing, owl:Nothing, subclass, equivalence, disjointness, complement, intersection, union, existential and universal restrictions on object and datatype properties, numeric datatype bounds, inverses, transitive and symmetric object properties, domain, range, class assertions, object-property assertions, and literal assertions. |
Cardinality, property chains, owl:oneOf, role inclusion, keys, owl:sameAs, and SWRL. |
direct_subclasses() refuses an inconsistent ontology. It does not classify every class as a subclass of owl:Nothing.