Hello Jiba,
it seems I have detected a bug concerning SPARQL queries involving annotation properties. When I execute a SPARQL query with of the following code using Owlready2 0.18, I get a correct result:
CODE
ontology = or2.get_ontology(file_location).load()
graph = or2.default_world.as_rdflib_graph()
graph.bind("owl", "
http://www.w3.org/2002/07/owl#")
graph.bind("rdfs", "
http://www.w3.org/2000/01/rdf-schema#")
graph.bind("onto", ontology.base_iri)
query = "SELECT ?label WHERE { ?annotation owl:annotatedSource onto:individual1 ; owl:annotatedTarget onto:individual2 ; rdfs:comment ?label . }"
result = list(graph.query(query))
print(result)
ONTOLOGY
<?xml version="1.0"?>
<rdf:RDF xmlns="
http://www.example/or2_swrl#" xml:base="
http://www.example/or2_swrl" xmlns:owl="
http://www.w3.org/2002/07/owl#" xmlns:rdf="
http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xml="
http://www.w3.org/XML/1998/namespace" xmlns:xsd="
http://www.w3.org/2001/XMLSchema#" xmlns:rdfs="
http://www.w3.org/2000/01/rdf-schema#" xmlns:swrl="
http://www.w3.org/2003/11/swrl#"> <owl:Ontology rdf:about="
http://www.example/or2_swrl"/>
<owl:ObjectProperty rdf:about="
http://www.example/or2_swrl#op1"/>
<owl:ObjectProperty rdf:about="
http://www.example/or2_swrl#op2"/>
<owl:Class rdf:about="
http://www.example/or2_swrl#A"/>
<owl:NamedIndividual rdf:about="
http://www.example/or2_swrl#individual1"> <rdf:type rdf:resource="
http://www.example/or2_swrl#A"/> <op1 rdf:resource="
http://www.example/or2_swrl#individual2"/> </owl:NamedIndividual>
<owl:Axiom>
<owl:annotatedSource rdf:resource="
http://www.example/or2_swrl#individual1"/> <owl:annotatedProperty rdf:resource="
http://www.example/or2_swrl#op1"/> <owl:annotatedTarget rdf:resource="
http://www.example/or2_swrl#individual2"/> <rdfs:comment>test</rdfs:comment>
</owl:Axiom>
<owl:NamedIndividual rdf:about="
http://www.example/or2_swrl#individual2"> <rdf:type rdf:resource="
http://www.example/or2_swrl#A"/> </owl:NamedIndividual>
</rdf:RDF>
The same SPARQL query executed with Owlready2 0.19 delivers no result. The code is identical in both cases. This could be related to some changes that were made to Owlready2 from version 0.18 to 0.19.
Many thanks in advance!
Marie