相同的查询在DBpedia Endpoint(http://ko.dbpedia.org/sparql)中有效,但在我的Java代码中却无效。 我只是想用" 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();
错误如下。
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.jar。 我已经查看了类似的问题和答案(Jena ARQ扩展和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)给了我同样的错误信息。
答案 0 :(得分:4)
这是非法的SPARQL语法:
1 23 4
应该是
SELECT ... count(distinct ?s) as ?count where
您将遇到SELECT ... (count(distinct ?s) as ?count) where
的问题:
?class
因为它不是分组变量(使用SELECT ?class (count(distinct ?s) as ?count) where
你有一组所有东西)。你的意思是count
吗?
答案 1 :(得分:0)
关键字为g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize));
g.setColor(Color.red);
g.drawString("some string", 40, 40);