gpt4 book ai didi

来自 DBpedia 和 Jena 的 SPARQL XML 结果

转载 作者:行者123 更新时间:2023-12-04 21:24:40 25 4
gpt4 key购买 nike

我从 DBpedia SPARQL 端点得到以下 XML:

<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="onto"/>
</head>
<results>
<result>
<binding name="onto">
<uri>http://www.w3.org/2002/07/owl#Thing</uri>
</binding>
</result>
<result>
<binding name="onto">
<uri>http://www.w3.org/2002/07/owl#Thing</uri>
</binding>
</result>
<result>
<binding name="onto">
<uri>http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing</uri>
</binding>
</result>
</results>
</sparql>

当我用 Jena 阅读它并尝试扫描它时:

  ResultSet r = ResultSetFactory.fromXML( xmlCode );
while ( r.hasNext() ) {
QuerySolution soln = r.next()
...
}

我总是收到以下异常:
com.hp.hpl.jena.sparql.resultset.ResultSetException: End of document while processing solution
at com.hp.hpl.jena.sparql.resultset.XMLInputStAX$ResultSetStAX.staxError(XMLInputStAX.java:503)
at com.hp.hpl.jena.sparql.resultset.XMLInputStAX$ResultSetStAX.getOneSolution(XMLInputStAX.java:413)
at com.hp.hpl.jena.sparql.resultset.XMLInputStAX$ResultSetStAX.hasNext(XMLInputStAX.java:218)

这是耶拿的错误还是其他什么?

编辑 :为了完整起见,我报告 a thread about this error :

When some help from the bio2rdf mailing list, we were able to track the error down a bit more.

Arq 2.8.3 works fine Arq 2.8.4 fails with the described error Arq 2.8.5 fails with the described error So I guess I will keep Art 2.8.3 for my tests. Let me know if I can help to debug this error a bit more.

Weird. The error is coming from the STaX parser - all the base level XML parsing is subcontracted to Woodstox. It's almost if it is reading faster than the input arrives and sees EOF rather than blocking for new input. I tried reading the whole stream then parsing the bytes read and it works OK. Why 2.8.3 should be different is unclear to me at the moment it might just be timing.

Workaround: switch the XML parsers with:

ARQ.getContext().setTrue(ARQ.useSAX) ;

before making the call to QueryExecutionFactory.sparqlService Andy

最佳答案

XML 结果看起来完全有效(并且使用其他工具解析没有问题)所以这可能是 Jena 的一些问题,尽管考虑到 Jena 框架的相对成熟度,如果它在如此简单且明显有效的输入上出错,我会感到惊讶。

您究竟是如何从 DBPedia 读取 XML 的?我怀疑该错误可能与 Java 代码中 XML 字符串的检索和格式有关,而不是与 Jena 的代码有关。

还有为什么这样做,为什么不使用 ARQ 的 QueryExecutionFactory.sparqlService(String service, String query)方法?

关于来自 DBpedia 和 Jena 的 SPARQL XML 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5581769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com