ModellingWebLab / cellmlmanip

CellML loading and model equation manipulation
Other
3 stars 1 forks source link

Parsing bug with rdflib version #344

Closed MauriceHendrix closed 2 years ago

MauriceHendrix commented 2 years ago

I got the following error trying cellmlmanip.load_model.

This error occurs with python 3.9.9 and rdflib 6.1.1 (withc installed whant I pip installed cllmlmanip) . Downgrading to rdflib 5.0.0 removes the error.

>>> load_model('/opt/django/media/aslanidi_atrial_model_2009.cellml')
rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:bqs="http://www.cellml.org/bqs/1.0#" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns="http://www.cellml.org/cellml/1.0#" xmlns:cellml="http://www.cellml.org/cellml/1.0#" xmlns:cmeta="http://www.cellml.org/metadata/1.0#" does not look like a valid URI, trying to serialize this will break.
rdf:Description rdf:about="#environment_time" does not look like a valid URI, trying to serialize this will break.
bqbiol:is rdf:resource="https://chaste.comlab.ox.ac.uk/cellml/ns/oxford-metadata#time"/ does not look like a valid URI, trying to serialize this will break.
Traceback (most recent call last):
  File "/opt/test_cmm/lib/python3.9/site-packages/rdflib/graph.py", line 1258, in parse
    parser.parse(source, self, **args)  # type: ignore[call-arg]
  File "/opt/test_cmm/lib/python3.9/site-packages/rdflib/plugins/parsers/notation3.py", line 1913, in parse
    p.loadStream(stream)
  File "/opt/test_cmm/lib/python3.9/site-packages/rdflib/plugins/parsers/notation3.py", line 434, in loadStream
    return self.loadBuf(stream.read())  # Not ideal
  File "/opt/test_cmm/lib/python3.9/site-packages/rdflib/plugins/parsers/notation3.py", line 440, in loadBuf
    self.feed(buf)
  File "/opt/test_cmm/lib/python3.9/site-packages/rdflib/plugins/parsers/notation3.py", line 466, in feed
    i = self.directiveOrStatement(s, j)
  File "/opt/test_cmm/lib/python3.9/site-packages/rdflib/plugins/parsers/notation3.py", line 488, in directiveOrStatement
    return self.checkDot(argstr, j)
  File "/opt/test_cmm/lib/python3.9/site-packages/rdflib/plugins/parsers/notation3.py", line 1149, in checkDot
    self.BadSyntax(argstr, j, "expected '.' or '}' or ']' at end of statement")
  File "/opt/test_cmm/lib/python3.9/site-packages/rdflib/plugins/parsers/notation3.py", line 1646, in BadSyntax
    raise BadSyntax(self._thisDoc, self.lines, argstr, i, msg)
rdflib.plugins.parsers.notation3.BadSyntax: at line 4 of <>:
Bad syntax (expected '.' or '}' or ']' at end of statement) at ^ in:
"...b'mlab.ox.ac.uk/cellml/ns/oxford-metadata#time"/>\n            '^b'</rdf:Description>\n         </rdf:RDF>\n      '"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/test_cmm/lib/python3.9/site-packages/cellmlmanip/main.py", line 11, in load_model
    return Parser(path).parse(unit_store=unit_store)
  File "/opt/test_cmm/lib/python3.9/site-packages/cellmlmanip/parser.py", line 131, in parse
    self._add_rdf(model_xml)
  File "/opt/test_cmm/lib/python3.9/site-packages/cellmlmanip/parser.py", line 155, in _add_rdf
    self.model.add_rdf(etree.tostring(rdf, encoding=str))
  File "/opt/test_cmm/lib/python3.9/site-packages/cellmlmanip/model.py", line 714, in add_rdf
    self.rdf.parse(StringIO(rdf))
  File "/opt/test_cmm/lib/python3.9/site-packages/rdflib/graph.py", line 1261, in parse
    raise ParserError(
rdflib.exceptions.ParserError: Could not guess RDF format for <rdflib.parser.InputSource object at 0x7f2c13928ca0> from file extension so tried Turtle but failed.You can explicitly specify format using the format argument.
>>>

output of pip freeze:

cellmlmanip==0.3.1
isodate==0.6.1
lxml==4.7.1
mpmath==1.2.1
networkx==2.6.3
packaging==21.3
Pint==0.18
pyparsing==3.0.6
rdflib==6.1.1
six==1.16.0
sympy==1.9
jonc125 commented 2 years ago

Simple fix: require rdflib < 6 for cellmlmanip.

Longer fix: figure out what has changed in the interface and make cellmlmanip support both versions...

MauriceHendrix commented 2 years ago

Simple fix: require rdflib < 6 for cellmlmanip.

Longer fix: figure out what has changed in the interface and make cellmlmanip support both versions...

it's a pretty simple change (just pass format='xml') so a PR coming up