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