I bumped into a problem of owlready2 Pellet reasoning. It doesn't honor the inferred type of my City class. My City class is a subclass of Locality class. I enabled Pellet reasoning by the following code:
sync_reasoner_pellet(self.world, infer_property_values=True, infer_data_property_values=True)
My SPARQL is shown below:
query = """
PREFIX owl: <
http://www.w3.org/2002/07/owl#>
PREFIX rdf: <
http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <
http://www.w3.org/2000/01/rdf-schema#>
PREFIX geo: <
http://www.vehorg.com/2024/03/geo_location#>
SELECT ?adm ?city
WHERE {
?city rdf:type geo:Locality .
OPTIONAL { ?city geo:inState ?adm . }
}
ORDER BY ?adm ?city
"""
Protege returned the correct answer - all city instances. However, owlready2 Pellet reasoner doesn't. Of course when I change geo:Locality to geo:City, it will work but it defeats the purpose of using the inference of Ontology.
Let me know if you need to access my ontology file or Python code snippet.
Thanks a million in advance for your time and feedback.