I'm trying to get Individuals in my Ontology which have a certain property. I want all Individuals which are linked to a foot by the hasFoot property. In the past I used Jena's iterators, but now i want to use SPARQL. The Java code that creates my query:
String queryString =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+
"PREFIX owl: <http://www.w3.org/2002/07/owl#>" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" +
"PREFIX test: <file:/test#>"+
"select ?uri"+
"where { "+
"?uri test:hasFoot ?foot"+
"} \n ";
But I don't get any results with this query. When I query for the properties of all triples I get these results:
"select ?prop "+
"where { "+
"?uri ?prop ?subj"+
"} \n ";
<file:/test#hasFoot>
<file:/test#hasFoot>
<file:/test#hasFoot>
<file:/test#hasFoot>
<file:/test#hasAge>
<file:/test#hasName>
So SPARQL queries are clearly working. I can even search for the rdf:types, so the rdf namespace works, only my namespace (test) doesnt seem to work. I have also tried to write out the whole property name ("file:/test#hasFoot") with no results. Does anyone have an idea what I am missing?
Here is my ontology:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:test="file:/test#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
<rdf:Description rdf:about="file:/test#Foot2">
<rdf:type rdf:resource="file:/test#Foot"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#Peter">
<test:hasHand rdf:resource="file:/test#Hand2"/>
<test:hasHand rdf:resource="file:/test#Hand1"/>
<test:hasFoot rdf:resource="file:/test#Foot6"/>
<test:hasFoot rdf:resource="file:/test#Foot5"/>
<test:hasName>Peter</test:hasName>
<test:hasAge>98</test:hasAge>
<rdf:type rdf:resource="file:/test#Individuum"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#hasName">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#Foot1">
<rdf:type rdf:resource="file:/test#Foot"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#Foot3">
<rdf:type rdf:resource="file:/test#Foot"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#Hand">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#hasAge">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#Human">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#hasFoot">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#Doggy">
<test:hasFoot rdf:resource="file:/test#Foot4"/>
<test:hasFoot rdf:resource="file:/test#Foot3"/>
<test:hasFoot rdf:resource="file:/test#Foot2"/>
<test:hasFoot rdf:resource="file:/test#Foot1"/>
<test:hasAge>7</test:hasAge>
<test:hasName>Doggy</test:hasName>
<rdf:type rdf:resource="file:/test#Individuum"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#Hand2">
<rdf:type rdf:resource="file:/test#Hand"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#Foot6">
<rdf:type rdf:resource="file:/test#Foot"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#hasHand">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#Individuum">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#Foot">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#Foot5">
<rdf:type rdf:resource="file:/test#Foot"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#Hand1">
<rdf:type rdf:resource="file:/test#Hand"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
</rdf:Description>
<rdf:Description rdf:about="file:/test#Foot4">
<rdf:type rdf:resource="file:/test#Foot"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
</rdf:Description>
</rdf:RDF>