gpt4 book ai didi

java - 为什么我得到这个 sparql 查询的单个结果?

转载 作者:行者123 更新时间:2023-12-01 16:50:53 25 4
gpt4 key购买 nike

我在 sparql 端点执行查询并得到多个结果。然而,在 Netbeans 中执行它时,我只得到一个结果。公共(public)类 FetchCountryData {

public void fetchData() {
ParameterizedSparqlString qs = new ParameterizedSparqlString("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+ "PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>\n"
+ "PREFIX dbo: <http://dbpedia.org/ontology/>\n"
+ "\n"
+ "SELECT distinct ?country ?capital ?caplat ?caplong\n"
+ "WHERE {\n"
+ " ?country rdf:type dbo:Country .\n"
+ " ?country dbo:capital ?capital .\n"
+ " OPTIONAL {\n"
+ " ?capital geo:lat ?caplat ;\n"
+ " geo:long ?caplong .\n"
+ " }\n"
+ "}\n"
+ "ORDER BY ?country");

QueryExecution exec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", qs.asQuery());
exec.setTimeout(10000000);
ResultSet results = exec.execSelect();
if (results.hasNext()) {
System.out.println(results.next());
}
}

}

输出

( ?capital = http://dbpedia.org/resource/Nicosia ) ( ?caplong = "33.3667"^^xsd:float ) ( ?caplat = "35.1667"^^xsd:float ) ( ?country <= http://dbpedia.org/resource/1974_Cypriot_coup_d 'état> )

最佳答案

您没有迭代结果。将“如果”更改为:

while (results.hasNext()){
System.out.println(results.next());
}

关于java - 为什么我得到这个 sparql 查询的单个结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40386432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com