目前,Wikidata有一个SPARQL端点"https://query.wikidata.org/",我想使用Jena(3.0.1)查询此网站,我使用以下代码,但我收到错误消息"Endpoint returned Content Type:text/html/当前SELECT查询不支持该类型"。有办法解决吗?同样的代码适用于dbpedia。谢谢
queryString = "PREFIX bd: <http://www.bigdata.com/rdf#>n" +
"PREFIX wikibase: <http://wikiba.se/ontology#>n" +
"PREFIX wdt: <http://www.wikidata.org/prop/direct/>n" +
"PREFIX wd: <http://www.wikidata.org/entity/>n" +
"SELECT DISTINCT ?country ?countryLabeln" +
"WHEREn" +
"{n" +
"t?country wdt:P31 wd:Q3624078 .n" +
" ?country wdt:P1622 wd:Q13196750.n" +
" ?country wdt:P30 wd:Q15n" +
"tFILTER NOT EXISTS {?country wdt:P31 wd:Q3024240}n" +
"tSERVICE wikibase:label { bd:serviceParam wikibase:language "en" }n" +
"}n" +
"ORDER BY ?countryLabel";
query = QueryFactory.create(queryString);
qexec = QueryExecutionFactory.sparqlService("https://query.wikidata.org/", queryString);
try {
ResultSet results = qexec.execSelect();
ResultSetFormatter.out(System.out, results, query);
} catch (Exception ex) {
System.out.println(ex.getMessage());
} finally {
qexec.close();
}
根据文档,端点的末尾有一个/sparql。上面写着
SPARQL查询可以通过对
https://query.wikidata.org/sparql?query={SPARQL}
的GET请求直接提交到SPARQL端点(POST和其他方法请求将被"403 Forbidden"拒绝)。默认情况下,结果返回为XML,如果提供了查询参数format=JSON或标头Accept:application/sparql-resules+JSON,则返回为JSON。