Pellet reasoner problem: inferred type is not honored

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Pellet reasoner problem: inferred type is not honored

ernest.tam@ontologicalemf.com
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.
Reply | Threaded
Open this post in threaded view
|

Re: Pellet reasoner problem: inferred type is not honored

Jiba
Administrator
Is just City is subclass of Locality? In that case, the inference is considered as too trivial to worth saving in the quadstore (in case of deep hierarchy, the number of such relations that can be inferred is very high).

In practice, you don't need a reasoner like Pellet for such simple inference, you can just adapt your SPARQL query to take into account inheritance, as follows:

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/rdfs:subClassOf* geo:Locality .
    OPTIONAL { ?city geo:inState ?adm . }
    }
ORDER BY ?adm ?city
        """

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Pellet reasoner problem: inferred type is not honored

ernest.tam@ontologicalemf.com
Thanks. Really appreciated for your feedback. You unblock me to continue my project.

For inferred type, I will use subclass. By the way, I tried your query and it doesn't work. I have to use the following SPARQL 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 ?subclass ?city
WHERE {
  ?city rdf:type ?subclass .
  ?subclass rdfs:subClassOf* geo:Locality .
  OPTIONAL { ?city geo:inAdministrativeDistrict ?adm . }
}

Last but not the least. thank for owlready2. It is excellent.