1
私はこのフクロウのモデルを作った。 SensorとLocationの2つのクラスがあり、Locationは列挙されたクラスです。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 ; .
私は各センサーの位置をID番号で取得しようとしています。私はProtegeで私の質問を書いて、うまくいきます。しかし、JENAでは、その場所にnullが印刷されています。 リソースを使用してセンサーを印刷しましたが、その場所にはnullが印刷されていました。私は場所を印刷するプロペラの方法を理解できませんでした。
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