有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

同样的查询可以在DBpedia端点(http://ko.dbpedia.org/sparql)中使用,但不能在我的Java代码中使用。 我只是想用“计数”函数提取频率

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();

误差如下

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)

我用的是virt_jena2。jar和virtjdbc4。罐子 我已经看过了类似的问题和答案(Jena ARQ extension和SPARQL 1.1支持这种聚合查询——但我找不到如何更改它——我认为我使用SPARQL1.1是因为错误消息包括PARSERSPARQL11.java),但目前还不知道如何解决这个问题

提前谢谢


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();
}

这个Jena代码(没有Virtuoso)给了我同样的错误信息


共 (1) 个答案

  1. # 1 楼答案

    关键字是Encountered " "count" "COUNT ""