[英]How can I get the result of a “Select count(*)” query with Apache Jena?
I tried many times to get the result of a select query count with apache jena in JAVA but it doesn't work. 我尝试了很多次,以使用JAVA中的apache jena来获得选择查询计数的结果,但是它不起作用。
select count(*) where {
?s dbo:award ?o.
?o rdf:type ?C.
FILTER
regex(?C,"http://dbpedia.org/ontology/Award")}
The result of this query in the endpoint is 33767 端点中此查询的结果为33767
So I made this code in java to get the result. 因此,我在Java中编写了此代码以获取结果。
public int CR() {
int CR=0;
String ch="http://dbpedia.org/ontology/";
String service="http://dbpedia.org/sparql";
String query="PREFIX dbo:<http://dbpedia.org/ontology/>"
+ "PREFIX : <http://dbpedia.org/resource/>"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
+ "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+"select * where { "
+"?s dbo:award ?o."
+"?o rdf:type ?C."
+"FILTER"
+"regex(?C,\"http://dbpedia.org/ontology/Award\")}";
QueryExecution qe=QueryExecutionFactory.sparqlService(service, query);
ResultSet rs=qe.execSelect();
while (rs.hasNext()){
QuerySolution s=rs.nextSolution();
CR++;
System.out.println(CR);
}
;
return CR;
}
The result that I've got in the console does not exceed 10000. 我在控制台中得到的结果不超过10000。
.
.
9992
9993
9994
9995
9996
9997
9998
9999
10000
Please I need an example of a select count query with apache jena, or find what's wrong with my code. 请使用apache jena进行选择计数查询的示例,或者查找我的代码有什么问题。
Thank you ! 谢谢 !
Dbpedia virtuoso, like many open sparql endpoints, has a limit in the number of results it will return. 像许多开放式sparql端点一样,Dbpedia演奏家对返回结果的数量有所限制。 Use
LIMIT
and OFFSET
to get the results in batches. 使用
LIMIT
和OFFSET
批量获取结果。 This will give you the second batch of 10000: 这将给您第二批10000:
SELECT * WHERE {
?s dbo:award ?o .
?o rdf:type ?C .
FILTER STRSTARTS(STR(?C), "http://dbpedia.org/ontology/Award")
}
LIMIT 10000
OFFSET 10000
Repeat with offset 0, 10000, 20000 etc. until the result is empty. 重复偏移量0、10000、20000等,直到结果为空。
PS. PS。 Since your filter actually matches a complete type URI, you can drop the filter altogether and simply match
?o rdf:type <http://dbpedia.org/ontology/Award>
(or equivalently: ?o rdf:type dbo:Award
) in the second condition. 由于您的过滤器实际上匹配完整的URI类型,因此您可以完全删除过滤器,而只需匹配
?o rdf:type <http://dbpedia.org/ontology/Award>
(或等效地: ?o rdf:type dbo:Award
)在第二种情况下。 It's far more efficient. 效率更高。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.