4

我有一个由其他人在 Protege 中准备的 OWL 文件。我正在尝试使用以下 Python 代码对其进行解析,但不断收到解析错误。

import rdflib
g=rdflib.Graph()
result = g.parse(r'myfile.owl')

rdflib.exceptions.ParserError: file:///myfile.owl:461:27: 在属性元素中重复节点元素:http://www.w3.org/2002/07/owl#Class

行号和字符号指的<Class IRI="#Gas"/>是 OWL 文件中行的开头。这是否表明“SubClassOf”构造错误,或者我需要另一个插件才能正确使用 rdflib,或者其他什么?OWL 文件如下所示:

<Declaration>
    <Class IRI="#Acetylene"/>
</Declaration>
<Declaration>
    <Class IRI="#Gas"/>
</Declaration>
...
<SubClassOf>
    <Class IRI="#Acetylene"/>
    <Class IRI="#Gas"/>
</SubClassOf>
4

2 回答 2

4

您在不是 RDF/XML 中显示的 XML 代码;它是 OWL/XML。因此,RDFlib 无法解析它也就不足为奇了。RDFlib应该能够解析 OWL 本体的 RDF 映射的 RDF/XML 序列化,但这与本体的 OWL/XML 序列化不同。您应该使用 OWL 工具将 OWL/XML 文件转换为 RDF/XML 文件,或者要求本体提供者提供 RDF/XML 序列化。

也可以看看

于 2014-12-02T15:08:14.697 回答
0

我遇到了同样的错误...我解决了使用 Protege 打开本体并以正确格式保存(RDF/XML 语法)

前:

<Declaration>
    <Class IRI="#Painter"/>
</Declaration>

后:

<!-- http://www.semanticweb.org/marco.cerliani/ontologies/2019/8/untitled-ontology-2#paint -->

<owl:ObjectProperty rdf:about="http://www.semanticweb.org/marco.cerliani/ontologies/2019/8/untitled-ontology-2#paint">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AsymmetricProperty"/>
    <rdfs:domain rdf:resource="http://www.semanticweb.org/marco.cerliani/ontologies/2019/8/untitled-ontology-2#Painter"/>
    <rdfs:range rdf:resource="http://www.semanticweb.org/marco.cerliani/ontologies/2019/8/untitled-ontology-2#Picture"/>
</owl:ObjectProperty>

通过这种方式,您可以始终在 python 中解析和序列化图形

于 2019-09-14T09:07:03.617 回答