2013-10-28 43 views
2

我想創建一個與耶拿查詢DBpedia的SPARQL查詢。當我使用Virtuoso時,該查詢正在工作,但是當我將它插入到下面的Java代碼中時,它將返回一個空集。DBpedia查詢返回的結果與Virtuoso但不是與耶拿

String sr="Christopher_Nolan"; 
String sparqlQueryString1 = "PREFIX dbont: <http://dbpedia.org/ontology/> "+    
     "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"+ 
     "PREFIX foaf: <http://xmlns.com/foaf/0.1/> "+ 
     " SELECT distinct ?s"+   
     " WHERE { "+  
     "?s foaf:name ?label ." + 
     "filter(?label=\"Christpher_Nolan\"@en)." +    
     "  }"; 
      Query query = QueryFactory.create(sparqlQueryString1); 
      QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query); 

      ResultSet results = qexec.execSelect(); 
      ResultSetFormatter.out(System.out,results, query);  

     qexec.close() ;  
+0

有人可以幫我解決這個問題,請 – fadox

+0

確實喜歡[查詢DBpedia的一個問題SPARQL和Jena](http://stackoverflow.com/q/1644252/1281433)有幫助嗎? –

+0

「Christpher_Nolan」@ en'應該是「Christopher Nolan」@ en'嗎? (請注意'o'和空格而不是下劃線。) –

回答

2

我不認爲這是耶拿的問題,但與您的特定查詢。您的查詢,當在DBpedia中SPARQL端點上運行,不會產生任何結果

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX foaf: <http://xmlns.com/foaf/0.1/> 
SELECT distinct ?s  
WHERE { 
    ?s foaf:name ?label . 
    filter(?label="Christpher_Nolan"@en) 
} 

SPARQL results (no results)

no results

但是,如果添加o的名稱克里斯托弗,並改變下劃線的空間,你會得到三種結果:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX foaf: <http://xmlns.com/foaf/0.1/> 
SELECT distinct ?s  
WHERE { 
    ?s foaf:name ?label . 
    filter(?label="Christopher Nolan"@en) 
} 

SPARQL results (3 results)

小號
http://dbpedia.org/resource/Christopher_Nolan_(author)
http://dbpedia.org/resource/Christopher_Nolan
http://dbpedia.org/resource/Chris_Nolan_(musician)

three results

我也想指出,這是一個相當不尋常的使用filter。如果你想選擇使用某個值的三倍,只要把這個值到三重模式:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX foaf: <http://xmlns.com/foaf/0.1/> 
SELECT distinct ?s  
WHERE { 
    ?s foaf:name "Christopher Nolan"@en 
} 

SPARQL results (same 3 results)

+0

我試圖將您的查詢複製並粘貼到DBpedia中。我沒有得到任何結果,只顯示了桌子的頭部。 – lvarayut

+0

@LVarayut DBpedia的endpoing有時可能有點片面,但我仍然可以將這些查詢複製並粘貼到http://dbpedia.org/sparql並獲得預期結果。請注意,預期的結果是:第一個查詢沒有結果,第二個和第三個查詢沒有結果。我添加了截圖作爲證據。 :) –

+0

感謝您的迴應。我正在使用[fr.dbpedia.org/sparql](http://fr.dbpedia.org/sparql),它不起作用。我剛剛嘗試[dbpedia.org/sparql](http://dbpedia.org/sparql)。它像一個魅力。你能否解釋一下'什麼是默認數據集名稱(Graph IRI)',我應該在那裏放些什麼? – lvarayut