加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

来自DBpedia和Jena的SPARQL XML结果

发布时间:2020-12-16 23:30:47 所属栏目:百科 来源:网络整理
导读:我从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" urihttp://www.w3.org/2002/07/owl#Thing/uri /binding /result r
我从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的?我怀疑这个bug可能与Java代码中的XML字符串的检索和格式有关,而不是与Jena的代码有关.

也是为什么这样做,为什么不使用ARQ的QueryExecutionFactory.sparqlService(字符串服务,字符串查询)方法呢?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读