我尝试使用Jena创建SPARQL查询来查询DBpedia。当我使用Virtuoso时查询正在运行,但当我将其插入以下Java代码时,它返回一个空集。
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 :(得分:2)
我认为这不是Jena的问题,而是您的特定查询。您的查询在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)
}
但是,如果您向名称Christopher添加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)
}
<强>取值强>
http://dbpedia.org/resource/Christopher_Nolan_(author)
http://dbpedia.org/resource/Christopher_Nolan
http://dbpedia.org/resource/Chris_Nolan_(musician)
我还要指出,这是对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
}