DerwenAI / kglab

Graph Data Science: an abstraction layer in Python for building knowledge graphs, integrated with popular graph libraries – atop Pandas, NetworkX, RAPIDS, RDFlib, pySHACL, PyVis, morph-kgc, pslpython, pyarrow, etc.
https://derwen.ai/docs/kgl/
MIT License
575 stars 65 forks source link

odd behavior with SHACL inverse path #214

Open fils opened 2 years ago

fils commented 2 years ago

I'm submitting a

Current Behaviour:

Expected Behaviour:

running pyshacl from the command results in this

(kglab) ➜  validation git:(master) ✗ pyshacl -s shapes/oih_checkDownload.ttl  -f human ./datagraphs/lipd.json
Validation Report
Conforms: False
Results (1):
Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):
        Severity: shacl:Violation
        Source Shape: [ shacl:minCount Literal("1", datatype=xsd:integer) ; shacl:path [ shacl:inversePath rdf:type ] ]
        Focus Node: :Course
        Result Path: [ shacl:inversePath rdf:type ]
        Message: Less than 1 values on :Course->[ shacl:inversePath rdf:type ]

but the script simpleshacl.py in https://github.com/gleanerio/notebooks/tree/master/notebooks/validation when run generates

(kglab) ➜  validation git:(master) ✗ python simpleshacl.py                                                   
Usage of abort_on_error is deprecated. Use abort_on_first instead.
Traceback (most recent call last):
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1174, in uri_ref2
    ns = self._bindings[pfx]
KeyError: 'rdf'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "simpleshacl.py", line 25, in <module>
    conforms, report_graph, report_text = kg.validate(
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/kglab/kglab.py", line 1181, in validate
    g.parse(
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/graph.py", line 1261, in parse
    raise se
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/graph.py", line 1252, in parse
    parser.parse(source, self, **args)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1921, in parse
    p.loadStream(stream)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 438, in loadStream
    return self.loadBuf(stream.read())  # Not ideal
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 444, in loadBuf
    self.feed(buf)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 470, in feed
    i = self.directiveOrStatement(s, j)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 490, in directiveOrStatement
    j = self.statement(argstr, i)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 740, in statement
    j = self.property_list(argstr, i, r[0])
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1088, in property_list
    i = self.objectList(argstr, j, objs)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1132, in objectList
    i = self.object(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1418, in object
    j = self.subject(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 747, in subject
    return self.item(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 839, in item
    return self.path(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 846, in path
    j = self.nodeOrLiteral(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1446, in nodeOrLiteral
    j = self.node(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 919, in node
    i = self.property_list(argstr, j, subj)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1088, in property_list
    i = self.objectList(argstr, j, objs)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1132, in objectList
    i = self.object(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1418, in object
    j = self.subject(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 747, in subject
    return self.item(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 839, in item
    return self.path(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 846, in path
    j = self.nodeOrLiteral(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1446, in nodeOrLiteral
    j = self.node(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 919, in node
    i = self.property_list(argstr, j, subj)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1088, in property_list
    i = self.objectList(argstr, j, objs)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1132, in objectList
    i = self.object(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1418, in object
    j = self.subject(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 747, in subject
    return self.item(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 839, in item
    return self.path(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 846, in path
    j = self.nodeOrLiteral(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1446, in nodeOrLiteral
    j = self.node(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1050, in node
    j = self.uri_ref2(argstr, i, res)
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1182, in uri_ref2
    self.BadSyntax(argstr, i, 'Prefix "%s:" not bound' % (pfx))
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1653, in BadSyntax
    raise BadSyntax(self._thisDoc, self.lines, argstr, i, msg)
rdflib.plugins.parsers.notation3.BadSyntax: at line 10 of <>:
Bad syntax (Prefix "rdf:" not bound) at ^ in:
"...b':type ]" ;\n            shacl:resultPath [ shacl:inversePath '^b'rdf:type ] ;\n            shacl:resultSeverity shacl:Violatio'..."

You can also reference https://github.com/RDFLib/pySHACL/issues/36 which may be related.

Steps to reproduce:

use the command above and the script simpleshacl.py in https://github.com/gleanerio/notebooks/tree/master/notebooks/validation environment file https://github.com/gleanerio/notebooks/blob/master/environment.yml

Environment:

(kglab) ➜ validation git:(master) ✗ conda list | grep -i shacl
pyshacl 0.16.1 pyhd8ed1ab_0 conda-forge

ceteri commented 2 years ago

Good catch, thank you @fils !

I had an exchange with the lead for pySHACL yesterday. They'd had an error in their requirements.txt file that caused an installation conflict, even though they were trying to upgrade to support RDFlib v6.x

I work with the upgrades since that issue is resolved, and see if the version bumps resolve this

fils commented 2 years ago

@ceteri I'm still seeing this error after the update.

Traceback (most recent call last):
  File "/home/fils/.conda/envs/kglab/lib/python3.8/site-packages/rdflib/plugins/parsers/notation3.py", line 1174, in uri_ref2
    ns = self._bindings[pfx]
KeyError: 'rdf'

I can try and dive into it tomorrow. I have to leave today for family. I really want this one working since this pattern check is turning out to be really useful for my use cases. So I am motivated.