Reputation: 969
I have this ontology
<owl:NamedIndividual rdf:about="&object_test;TablePick">
<rdf:type rdf:resource="&dul;PhysicalArtifact"/>
<SOMA:hasLocalization>
<owl:NamedIndividual>
<rdf:type rdf:resource="&SOMA;Localization"/>
<SOMA:hasSpaceRegion>
<xyz:pose rdf:resource="&object_test;Pose_TablePick"/>
</SOMA:hasSpaceRegion>
</owl:NamedIndividual>
</SOMA:hasLocalization>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="&object_test;Pose_TablePick">
<rdf:type rdf:resource="&xyz;Pose"/>
<xyz:quaternion rdf:datatype="&xsd;string">0.0 0.0 1.0 0.0</xyz:quaternion>
<xyz:translation rdf:datatype="&xsd;string">0.5 0.0 0.2</xyz:translation>
</owl:NamedIndividual>
I am trying to extract the translation and quaternion. This is my initial query is:
SELECT ?obj ?translation WHERE {
?obj rdf:type dul:PhysicalArtifact .
?pose rdf:type xyz:Pose .
?pose xyz:translation ?translation .
}
and I get translation
[object_test.TablePick, '0.5 0.0 0.2']
But I want to multiple queries on "obj", so I changed my query to
SELECT ?obj ?translation WHERE {
?obj rdf:type dul:PhysicalArtifact .
}
Since I am using owlready2
I tried to access obj this way
with onto:
print(obj.hasLocalization[0].hasSpaceRegion[0].translation)
but now the translation is an empty list. How can I access translation in python?
Edit 1: actually the initial query is "wrong" as well, since it gives all possible combinations of objects and locations, not just that particular object's location. So something like this
[[object_test.TablePick, '0.0 0.0 0.0'], [object_test.TablePick, '0.5 0.0 0.2'], [object_test.TablePick, '0.5 -0.1 0.5'], [object_test.TablePick, '0.5 0.1 0.5'], [object_test.obj_1234, '0.0 0.0 0.0'], [object_test.obj_1234, '0.5 0.0 0.2'], [object_test.obj_1234, '0.5 -0.1 0.5'], [object_test.obj_1234, '0.5 0.1 0.5'], [object_test.obj_5678, '0.0 0.0 0.0'], [object_test.obj_5678, '0.5 0.0 0.2'], [object_test.obj_5678, '0.5 -0.1 0.5'], [object_test.obj_5678, '0.5 0.1 0.5']]
Edit 2: "fixed" the sparql query by simplifying the ontology
<SOMA:hasLocalization>
<owl:NamedIndividual>
<rdf:type rdf:resource="&SOMA;Localization"/>
<xyz:pose rdf:resource="&object_test;Pose_obj_5678"/>
</owl:NamedIndividual>
</SOMA:hasLocalization>
Now I get the correct solution with
[[objects.TablePick, '0.5 0.0 0.2'], [objects.obj_1234, '0.5 -0.1 0.5'], [objects.obj_5678, '0.5 0.1 0.5']]
but trying to access translation with obj in python still gives an empty list.
Edit 3:
print(obj.hasLocalization[0].get_properties())
the result of this is empty. How is that possible when this sparql query works
SELECT ?obj ?translation WHERE {
?obj rdf:type dul:PhysicalArtifact .
?obj SOMA:hasLocalization ?loc .
?loc xyz:pose ?pose .
?pose rdf:type xyz:Pose .
?pose xyz:translation ?translation .
}
Upvotes: 0
Views: 78