我正在使用 Jena 启动 SPARQL 查询。我有这段代码,它会产生错误。我不明白这个错误的原因,因为将查询放入DBpedia SPARQL 端点有效!我认为我正确地编写了查询字符串。有什么错误?
代码
String sparqlQueryString=
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+
"select ?sub ?super (count(?mid) as ?length) where {"+
"values ?sub { <http://dbpedia.org/ontology/Writer> }" +
"?sub rdfs:subClassOf* ?mid ."+
"?mid rdfs:subClassOf+ ?super .}"+
"group by (?sub ?super)"+
"order by (?length)";
query = QueryFactory.create(sparqlQueryString);
QueryExecution qexec =
QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql",query);
错误
Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Encountered "
<VAR1> "?super "" at line 1, column 231.
Was expecting one of:
"not" ...
"as" ...
"in" ...
<INTEGER_POSITIVE> ...
<DECIMAL_POSITIVE> ...
<DOUBLE_POSITIVE> ...
<INTEGER_NEGATIVE> ...
<DECIMAL_NEGATIVE> ...
<DOUBLE_NEGATIVE> ...
")" ...
"=" ...
"!=" ...
">" ...
"<" ...
"<=" ...
">=" ...
"||" ...
"&&" ...
"+" ...
"-" ...
"*" ...
"/" ...
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:156)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:79)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:52)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:40)
at Query.QueryRDF.retrieveSuperClasses(QueryRDF.java:87)
at Query.QueryRDF.main(QueryRDF.java:144)