简体   繁体   English

Virtuoso Jena API中的SPARQL查询“ COUNT”-QueryParseException

[英]SPARQL Query “COUNT” in Virtuoso Jena API - QueryParseException

Same query works in DBpedia Endpoint( http://ko.dbpedia.org/sparql ), but not in my Java code. 相同的查询在DBpedia Endpoint( http://ko.dbpedia.org/sparql )中有效,但在我的Java代码中却无效。 I am just trying to extract the frequency using "COUNT" function. 我只是想使用“ COUNT”功能提取频率。

VirtGraph set = new VirtGraph("http://ko.dbpedia.org", HOST, USERNAME, PASSWORD);
Query freqsparql = QueryFactory.create("SELECT ?class count(distinct ?s) as ?count where{?s <http://ko.dbpedia.org/property/이름> ?o. ?s a ?class.} order by DESC(?count)");
VirtuosoQueryExecution freqvqe = VirtuosoQueryExecutionFactory.create(freqsparql, set);
ResultSet freqresults = freqvqe.execSelect();

And the error is as follows. 错误如下。

Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Encountered " "count" "count "" at line 1, column 15.
Was expecting one of:
<VAR1> ...
<VAR2> ...
"from" ...
"where" ...
"(" ...
"{" ...

at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:102)
at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.parse$(ParserSPARQL11.java:53)
at com.hp.hpl.jena.sparql.lang.SPARQLParser.parse(SPARQLParser.java:37)
at com.hp.hpl.jena.query.QueryFactory.parse(QueryFactory.java:148)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:80)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:53)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:41)

I am using virt_jena2.jar and virtjdbc4.jar. 我正在使用virt_jena2.jar和virtjdbc4.jar。 I have been looked through similar questions and answers(Jena ARQ extension and SPARQL 1.1 supports this aggregated query - But I couldn't find how to change it - I think I'm using SPARQL1.1 from the fact that error message includes PARSERSPARQL11.java ), but can't figure out how to solve this at this point. 我一直在寻找类似的问题和答案(Jena ARQ扩展和SPARQL 1.1支持此聚合查询-但我找不到如何更改它-我认为由于错误消息包含PARSERSPARQL11,我正在使用SPARQL1.1。 java),但目前还无法解决。

Thanks in advance. 提前致谢。


String sparqlQueryString = "SELECT ?class count(distinct ?s) as ?count    where{?s <http://ko.dbpedia.org/property/이름> ?o. ?s a ?class.} order by DESC(?count)";
Query query = QueryFactory.create(sparqlQueryString);
QueryExecution qexec = QueryExecutionFactory.sparqlService(
                "http://ko.dbpedia.org/sparql", query);
try {
    ResultSet results = qexec.execSelect();
    while(results.hasNext()){
        QuerySolution freqresult = results.nextSolution();
        RDFNode domain = freqresult.get("class");
        RDFNode freqcount = freqresult.get("count");
        System.out.println(freqresult);
        System.out.println(domain + "---" + freqcount);
    }
} catch (Exception e) {
    e.printStackTrace();
} finally {
    qexec.close();
}

This Jena code (without Virtuoso) gives me same error message. 这个耶拿代码(没有Virtuoso)给了我同样的错误信息。

This is illegal SPARQL syntax: 这是非法的SPARQL语法:

SELECT ... count(distinct ?s) as ?count where

It should be 它应该是

SELECT ... (count(distinct ?s) as ?count) where

The you will have a problem with ?class in: 您会在?class中遇到问题:

SELECT ?class (count(distinct ?s) as ?count) where

because it is not a grouped variable (using count you have a group of everything). 因为它不是一个分组变量(使用count您拥有一组所有内容)。 Did you mean to have a GROUP BY ?class ? 您是说要有GROUP BY ?class

关键字为“ Encountered " "count" "COUNT ""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM