Open sapkotaruz11 opened 21 hours ago
Yes indeed. For example, the following example is provided in the README.
from owlapy.owl_ontology_manager import OntologyManager
from owlapy.owl_reasoner import SyncReasoner
from owlapy.static_funcs import stopJVM
ontology_path = "KGs/Family/family-benchmark_rich_background.owl"
# Available OWL Reasoners: 'HermiT', 'Pellet', 'JFact', 'Openllet'
sync_reasoner = SyncReasoner(ontology = ontology_path, reasoner="Pellet")
onto = OntologyManager().load_ontology(ontology_path)
# Iterate over defined owl Classes in the signature
for i in onto.classes_in_signature():
# Performing type inference with Pellet
instances=sync_reasoner.instances(i,direct=False)
print(f"Class:{i}\t Num instances:{len(instances)}")
stopJVM()
You just need to check whether individual
is an element of sync_reasoner.instances(parent)
.
We have also few more examples ,e.g.
In addition to Demir's suggestion you can also check if the class assertion axiom for that individual + ce is entailed by the ontology axioms.
ontology_location = "../KGs/Family/family-benchmark_rich_background.owl"
reasoner = SyncReasoner(ontology_location)
individual = OWLNamedIndividual(IRI('http://www.benchmark.org/family#','F2F36'))
assertion_axiom = OWLClassAssertionAxiom(individual, OWLClass(IRI('http://www.benchmark.org/family#','Parent')))
is_entailed = reasoner.is_entailed(assertion_axiom)
print(is_entailed)
Keep in mind that SyncReasoner uses open world assumption and it may not entail an axiom that would otherwise be entailed in CWA. I suggest testing it with some complex class expressions before you continue with your experiments.
Is there a function which we can directly use to determine if an individual is an instance of a OWLClass or OWL-Class Expression? Something similar to isinstance function in python?
Example use case: