Ich machte dieses Eulenmodell. Es gibt zwei Klassen: Sensor und Ort, und Ort ist eine aufgezählte Klasse.SPARQL Abfrage Drucken Aufzählung Klasse mit 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 ; .
Ich versuche, die Position der einzelnen Sensoren mit ihrer ID-Nummer zu bekommen. Ich habe meine Abfrage in Protege geschrieben und es funktioniert gut. Aber auf JENA wird Null für den Standort gedruckt. Ich benutzte die Resource, um den Sensor zu drucken, aber für den Standort druckt er Null. Ich konnte es nicht herausfinden, wie der Standort gedruckt werden könnte.
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);
}
}
so vielen Dank, gibt es gute Tutorials, können Sie empfehlen – Ali