rdflib "repeat node-elements" parse error with OWL/XML file

2.2k views Asked by At

I have an OWL file prepared in Protege by someone else. I'm trying to parse it with the following Python code, but keep getting a parse error.

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

rdflib.exceptions.ParserError: file:///myfile.owl:461:27: Repeat node-elements inside property elements: http://www.w3.org/2002/07/owl#Class

The line and character numbers refer to the start of the <Class IRI="#Gas"/> line in the OWL file. Does this indicate that the 'SubClassOf' construct is wrong, or that I need another plugin to use rdflib properly, or something else? The OWL file looks like this:

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

There are 2 answers

1
Joshua Taylor On BEST ANSWER

The XML code you're showing in not RDF/XML; it's OWL/XML. As such, it's not surprising that RDFlib can't parse it. RDFlib should be able to parse the RDF/XML serialization of the RDF mapping of the OWL ontology, but that's not the same thing as the OWL/XML serialization of the ontology. You should either use an OWL tool to convert the OWL/XML file to an RDF/XML file, or ask the provider of the ontology to provide the RDF/XML serialization.

See Also

0
Marco Cerliani On

I had the same error... I solved opening the ontology with Protege and saving in the correct format (RDF/XML Syntax)

Before:

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

After:

<!-- 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>

In this way you can parse and serialize graph always in python