Reputation: 1537
Hey I made the protege tutorial for pizzas. I got an owl file. I saved the file as RDF/XML format. Now I try to get some information about the data in the file. Things like:
"Select * where {
?s rdfs:subClassOf owl:Thing
}
work. Now I want to get all subjects and objects who are related with "hasTopping".
OntModel m = ModelFactory.createOntologyModel(OWL_MEM);
InputStream in = FileManager.get().open("pizza1.owl");
m.read(in, "RDF/XML");
String queryString =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"PREFIX : <http://www.pizza.com/ontologies/pizza.owl> " +
"PREFIX owl: <http://www.w3.org/2002/07/owl#>" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" +
"PREFIX xml: <http://www.w3.org/XML/1998/namespace>" +
"SELECT * WHERE" +
"{" +
"?s :hasTopping ?o" +
"}";
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query,m);
try {
ResultSet results = qexec.execSelect();
while( results.hasNext()) {
QuerySolution soln = results.nextSolution();
RDFNode name = soln.get("s");
RDFNode name1 = soln.get("o");
//RDFNode name2 = soln.get("s");
System.out.println("Subject:" + name);
System.out.println("Object:" + name1);
//System.out.println(name2);
}
} finally {
qexec.close();
}
But the result is always empty. Hope someone can help me.
Kindly Regards!
Upvotes: 0
Views: 41
Reputation: 8465
The prefix declaration of :
is missing a separator like #
or /
- depends on how it's defined in the ontology.
Without it, using :hasTopping
results in the URI http://www.pizza.com/ontologies/pizza.owlhasTopping
Upvotes: 1