1
我做了這個貓頭鷹模型。有兩個類傳感器和位置,而位置是枚舉類。SPARQL查詢使用JENA JAVA打印枚舉類
:Sensor rdf:type owl:Class;
:Location rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Class ;
owl:oneOf (:Bathroom
:Bedroom
)
] .
:hasLocation rdf:type owl:ObjectProperty ;
rdfs:domain [ rdf:type owl:Class ;
:Sensor
] ;
rdfs:range :Location .
:Bathing rdf:type owl:NamedIndividual ,
ADLOntology:Bathing .
:Bathroom rdf:type owl:NamedIndividual ,
ADLOntology:Location .
:Window rdf:type owl:NamedIndividual ,
:Sensor ;
:hasLocation :Bedroom;
:hasId "55"^^xsd:int ; .
我想獲得每個傳感器的位置與他們的身份證號碼。我在Protege中寫了我的查詢,它工作正常。但是,在JENA上,該位置打印爲空。我使用資源來打印傳感器,但是對於它打印空位置。我無法弄清楚打印位置的方式。
String file = "C:/users/src/data.ttl";
Model model = FileManager.get().loadModel(file);
String queryString = "PREFIX : <http://semanticweb.org/sensor#>" +
"SELECT ?sensor ?location" +
"WHERE {?sensor :hasId \"55"\^^xsd:int." +
"?sensor :hasLocation ?location}";
Query query = QueryFactory.create(queryString);
try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) {
ResultSet result = qexec.execSelect();
for (; result.hasNext();) {
QuerySolution soln = result.nextSolution();
Resource sensor= soln.getResource("sensor");
Resource location = soln.getResource("location");
System.out.println("Sensor" + sensor);
System.out.println("Location" + location);
}
}
感謝這麼多,有沒有什麼好的教程,你可以推薦 – Ali