2013-03-27 213 views
4

我只是試圖在DBpedia上運行一個小的查詢,查詢本身的作品,看到它here,但我不明白爲什麼它返回時與耶拿這樣做,我得到空。DBpedia Jena查詢返回null

String service = "http://dbpedia.org/sparql"; 
String queryString = ""; 
queryString = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?label" + 
     "WHERE {" + 
     "<http://dbpedia.org/resource/Quatre_Bornes> <http://dbpedia.org/ontology/country> ?y ."+ 
     "?y rdfs:label ?label ."+ 
     "FILTER (LANG(?label) = 'en')"+ 
     "}"; 

Query query = QueryFactory.create(queryString); 
QueryEngineHTTP qexec = QueryExecutionFactory.createServiceRequest(service, query); 
ResultSet results = qexec.execSelect(); 
for (; results.hasNext() ;) { 
    QuerySolution soln = results.nextSolution() ; 
    System.out.println(soln.getLiteral("label")); 
} 

有什麼建議嗎?

+1

你的回答是有意義的,它是有用的人。 (我的問題也出現在其他問題上。)您應該接受您的答案,以便其他人知道它的工作原理,並在沒有接受答案的情況下減少問題的數量。 – 2013-09-25 00:30:47

回答

5

就是這樣尷尬的,有查詢空間的問題:

String service = "http://dbpedia.org/sparql"; 
     String queryString = ""; 
     queryString = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?label " + 
      "WHERE {" + 
      "<http://dbpedia.org/resource/Quatre_Bornes> <http://dbpedia.org/ontology/country> ?y ."+ 
      "?y rdfs:label ?label ."+ 
      "FILTER (LANG(?label) = 'en')"+ 
      "}"; 
+2

WHERE在查詢中是可選的。查詢字符串的簡單解決方案不是使用它。 – AndyS 2013-03-27 23:24:16