2017-02-15 7 views
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); 
      } 
} 

答えて

1

これは、OWLの列挙とは関係ありません。

クエリは、単にRDFグラフ内のマッピングを探します。あなたの例では、を慎重にチェックすると、 SPARQLクエリが生成されます。 JavaでStringを連結すると、改行やスペースを使用する必要があります。 SELECT部分​​の変数?locationの後にクエリが両方とも表示されないため、結果は?locationWHEREになります。

ソリューション:

何か良いチュートリアルがある、本当にありがとうございました、すなわち

String queryString = "PREFIX : <http://semanticweb.org/sensor#>" + 
        "SELECT ?sensor ?location " + 
        "WHERE {?sensor :hasId \"55"\^^xsd:int." + 
          "?sensor :hasLocation ?location}"; 

や改行

String queryString = "PREFIX : <http://semanticweb.org/sensor#>" + 
        "SELECT ?sensor ?location\n" + 
        "WHERE {?sensor :hasId \"55"\^^xsd:int." + 
          "?sensor :hasLocation ?location}"; 
+0

を逃しスペースを追加し、あなたがお勧めすることができます – Ali