2013-05-16 124 views
0

嘿家伙我有我的sparql查询有问题任何人都可以帮助我。从dbpedia检索数据时出错

String queryString = 
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"+ 
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+ 
"PREFIX type: <http://dbpedia.org/class/yago/>"+ 
"PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>"+ 
"PREFIX prop: <http://dbpedia.org/property/>"+ 
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>"+ 
"SELECT "+ 
"?description "+ 
"FROM <http://dbpedia.org/page/Arctic_Monkeys> "+ 
"WHERE " + 
"{"+ 
"?x foaf:depiction ?description."+ 
"}"; 

Query query = QueryFactory.create(queryString); 
    //initializing queryExecution factory with remote service. 
    QueryExecution qexec=QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query); 
    //query execution and result processing 
    try { 
     //simple select 
     ResultSet results = qexec.execSelect(); 
     ResultSetFormatter.out(System.out, results, query); 
    } 
    finally{ 
     qexec.close(); 
    } 
} 

它不检索从dbpedia中需要的数据。 我想要从一个特定的dbpedia页面检索数据

+0

它返回什么不工作? – greedybuddha

+0

它只返回标题描述,但不是他实际的数据表格dbpedia –

+0

通过“标题描述”,你究竟是什么意思?您可以在[在线端点](http://dbpedia.org/sparql)(我建议您用它来测试查询)对DBPedia运行SPARQL查询。 –

回答

1

您的IRI识别页面时出错了。这不是page,而是resource。此外,它是图中的一个资源,而不是(据我所知)一个命名的图,因此您的查询中不需要FROM。这里是一个可行的查询:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX type: <http://dbpedia.org/class/yago/> 
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/> 
PREFIX prop: <http://dbpedia.org/property/> 
PREFIX foaf: <http://xmlns.com/foaf/0.1/> 
SELECT ?depiction 
WHERE { 
    <http://dbpedia.org/resource/Arctic_Monkeys> foaf:depiction ?depiction 
} 

results有一个行,北极猴子在玩味精的照片。

+0

谢谢你解决了我的问题 –

+1

很高兴听到它!我没有使用DBPedia,但我喜欢它在做什么。最近有很多关于它的问题,我很高兴看到人们正在利用它。 –

相关问题