Querying instances of one ontology through another.

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

Querying instances of one ontology through another.

emir
Hello again!

Consider the following setting. We have two ontologies: ontology1 and ontology2; they have classes: entity1 and entity2 respectively. In entity2, we state equivalent_to = [ontology1.entity1].
We create instances only for entity1 and run sync_reasoner(). Then, we save each of the ontologies into their own file and also do world.save()

Question: Would it be possible to query instances of ontology1.entity1 by referring to ontology2.entity2?

In fact, it does retrieve instances of entity one if we run sync_reasoner() before world.sparql(query). But why doesn't it retrieve the same instances without syncing the reasoner every time before running the query? Since, I sync the reasoner before saving the world and it already must have the instances reparented.

Thank you! Let me know if the question is not clear enough!
Reply | Threaded
Open this post in threaded view
|

Re: Querying instances of one ontology through another.

Jiba
Administrator
Hi,

SPARQL works at the RDF level, so it does not consider OWL constructs, including equivalentClasses.

When you run the reasoner, it infers additional RDF triples stating that instances of entity1 are also instances of entity2.

Here, the inference are rather trivial, so you may also use a more complex SPARQL query that takes into account equivalence, such as:

q = default_world.sparql_query("""
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX onto: <http://test.org/onto.owl#>
SELECT ?i {
?i a ?c .
?c (rdfs:subClassOf|owl:equivalentClass|^owl:equivalentClass)* onto:entity2 .
}""")

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Querying instances of one ontology through another.

emir
OK! I will try that, thank you!