我试图使用以下代码片段对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)据我所知,维基数据中有一些uris没有被正确编码,即有一个空格。因此,rdf4j解析器会发出抱怨。有没有一种不那么严格的配置解析器的方法?
谢谢D063520
发布于 2020-01-21 23:34:09
正如您所发现的,这里的问题是您的查询在服务器端超时。您从RDF4J获得的错误消息令人困惑,但原因是服务器端点没有正确地传达存在问题:它只创建了200个HTTP响应(因此RDF4J认为一切正常,并开始处理响应体)。在运行过程中,服务器突然向响应体抛出一个错误,从而使RDF4J解析器抛出此错误。
https://stackoverflow.com/questions/59839409
复制相似问题