使用Python中的rdflib解析RDF XML文件时出错

时间:2015-08-24 21:30:34

标签: python rdflib

我正在尝试解析这个RDF:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://w3.org/1999/02/22-rdf-syntax-ns#">
    <rdf:Description rdf:about="http://sentic.net/api/en/concept/celebrate_special_occasion/polarity">
        <rdf:type rdf:resource="http://sentic.net/api/concept/polarity"/>
        <polarity xmlns="http://sentic.net" rdf:datatype="http://w3.org/2001/XMLSchema#float">0.551</polarity>
    </rdf:Description>
</rdf:RDF>

我是通过网址加载的:http://sentic.net/api/en/concept/celebrate_special_occasion/polarity

为此,我使用此代码:

import rdflib

g = rdflib.Graph()
g.parse("http://sentic.net/api/en/concept/celebrate_special_occasion/polarity", format='xml')

但是,代码返回此错误:

ParserError: http://sentic.net/api/en/concept/celebrate_special_occasion/polarity:4:67: Repeat node-elements inside property elements: http://w3.org/1999/02/22-rdf-syntax-ns#type

有谁知道发生了什么?哪个元素重复?我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

它似乎不是有效的RDF。 W3C validator fails

我用[说唱歌手]加载它并得到了更具描述性的错误信息。

rapper: Parsing URI http://sentic.net/api/en/concept/celebrate_special_occasion/polarity with parser rdfxml
rapper: Serializing with serializer turtle
rapper: Error - URI http://sentic.net/api/en/concept/celebrate_special_occasion/polarity:5 - property element 'Description' has multiple object node elements, skipping.