我正在尝试使用以下代码段通过Wikidata执行构造查询:
construct = "CONSTRUCT { " +
" ?s <http://schema.org/about> ?wikipedia ." +
"} where { " +
" OPTIONAL{ " +
" ?wikipedia <http://schema.org/about> ?s ; <http://schema.org/inLanguage> ?language ; <http://schema.org/isPartOf> <https://en.wikipedia.org/> . " +
" } "+
" ?s ?p1 <http://www.wikidata.org/entity/Q12136> . " +
"}";
repo = new SPARQLRepository("https://query.wikidata.org/sparql");
repositoryConnection = repo.getConnection();
query = repositoryConnection.prepareGraphQuery(construct);
rs = query.evaluate();
while (rs.hasNext()) {
Statement statement = rs.next();
}
不幸的是,这导致解析错误:
WARN org.eclipse.rdf4j.rio.helpers.ParseErrorLogger - [Rio error] IRI included an unencoded space: '32' (7730, -1)
org.eclipse.rdf4j.query.QueryEvaluationException: org.eclipse.rdf4j.query.QueryEvaluationException: org.eclipse.rdf4j.rio.RDFParseException: IRI included an unencoded space: '32' [line 7730]
at org.eclipse.rdf4j.query.impl.QueueCursor.convert(QueueCursor.java:58)
at org.eclipse.rdf4j.query.impl.QueueCursor.convert(QueueCursor.java:22)
at org.eclipse.rdf4j.common.iteration.QueueIteration.checkException(QueueIteration.java:165)
at org.eclipse.rdf4j.common.iteration.QueueIteration.getNextElement(QueueIteration.java:134)
at org.eclipse.rdf4j.common.iteration.LookAheadIteration.lookAhead(LookAheadIteration.java:81)
at org.eclipse.rdf4j.common.iteration.LookAheadIteration.hasNext(LookAheadIteration.java:49)
at org.eclipse.rdf4j.common.iteration.IterationWrapper.hasNext(IterationWrapper.java:63)
at eu.qanswer.mapping.mappings.informa.Refactor.main(Refactor.java:227)
据我在Wikidata中了解,有些uri编码不正确,即存在空格。因此rdf4j解析器抱怨。有没有一种不那么严格的方法来配置解析器?
谢谢D063520
如您所发现,这里的问题是您的查询在服务器端超时。您从RDF4J收到的错误消息令人困惑,但原因是服务器端点无法正确传达存在问题:它只会创建200 HTTP响应(因此RDF4J认为一切正常,并开始处理响应正文)。服务器中途突然将一个错误抛出到响应主体中,这随后使RDF4J解析器抛出此错误。