zazuko / rdf-validate-shacl

Validate RDF data purely in JavaScript. An implementation of the W3C SHACL specification on top of the RDFJS stack.
MIT License
95 stars 12 forks source link

lists in result messages #129

Closed giacomociti closed 2 months ago

giacomociti commented 2 months ago

should address #109 . Result messages include the first (three) elements of lists

changeset-bot[bot] commented 2 months ago

🦋 Changeset detected

Latest commit: f732f93478c88fe3f42afae31835a85fb22ea1ff

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------------------ | ----- | | rdf-validate-shacl | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

giacomociti commented 2 months ago

added a commit to also address #131 because the information in the rdfs:comment and in sh:resultMessage is complementary

Rdataflow commented 2 months ago

@giacomociti FYI this PR may have a regression which occurs for some cubes while not for others - can you reproduce?

repro:

npx barnard59 cube fetch-metadata --endpoint https://ld.admin.ch/query --cube https://environment.ld.admin.ch/foen/ubd0066/12 | npx barnard59 cube check-metadata --profile ./validation/profile-visualize.ttl

msg:

TypeError: Cannot read properties of undefined (reading 'size')
at inListSize (file:///tmp/test/node_modules/rdf-validate-shacl/src/dataset-utils.js:43:33)
at extractSourceShapeStructure (file:///tmp/test/node_modules/rdf-validate-shacl/src/dataset-utils.js:48:41)
at extractSourceShapeStructure.next (<anonymous>)
at ValidationEngine.copySourceShapeStructure (file:///tmp/test/node_modules/rdf-validate-shacl/src/validation-engine.js:271:16)
at ValidationEngine.createResult (file:///tmp/test/node_modules/rdf-validate-shacl/src/validation-engine.js:244:10)
at ValidationEngine.createResultFromObject (file:///tmp/test/node_modules/rdf-validate-shacl/src/validation-engine.js:181:25)
at file:///tmp/test/node_modules/rdf-validate-shacl/src/validation-engine.js:131:37
at Array.map (<anonymous>)
at ValidationEngine.validateValueNodeAgainstConstraint (file:///tmp/test/node_modules/rdf-validate-shacl/src/validation-engine.js:131:8)
at ValidationEngine.validateNodeAgainstConstraint (file:///tmp/test/node_modules/rdf-validate-shacl/src/validation-engine.js:119:19)

nb: some more repro cases

npx barnard59 cube fetch-metadata --endpoint https://ld.admin.ch/query --cube https://environment.ld.admin.ch/foen/EFV_cofog_international/2 | npx barnard59 cube check-metadata --profile ./validation/profile-visualize.ttl
npx barnard59 cube fetch-metadata --endpoint https://ld.admin.ch/query --cube https://environment.ld.admin.ch/foen/nfi/nfi_C-1029/cube/2023-3 | npx barnard59 cube check-metadata --profile ./validation/profile-visualize.ttl
npx barnard59 cube fetch-metadata --endpoint https://int.ld.admin.ch/query --cube https://agriculture.ld.admin.ch/foag/cube/Eggs/Consumption_Price_Month | npx barnard59 cube check-metadata --profile ./validation/profile-visualize.ttl
npx barnard59 cube fetch-metadata --endpoint https://int.ld.admin.ch/query --cube https://health.ld.admin.ch/fsvo/gefahrFRESIL/7 | npx barnard59 cube check-metadata --profile ./validation/profile-visualize.ttl
...
giacomociti commented 2 months ago

Nice catch @Rdataflow : the list of values allowed by sh:in is collected lazily; in your case, it was needed in the report shape but not initialized yet because not needed during validation.

I managed to fix the issue, also introducing a non-regression test. But I'm not super-happy with the design: the list initialization is now within the Constraint class, but it is a feature specific for the sh:in constraint. Maybe @tpluscode can suggest an improvement

Rdataflow commented 2 months ago

@giacomociti thanks for your fix - confirm it works here :+1:

tpluscode commented 2 months ago

Maybe @tpluscode can suggest an improvement

Not without diving deeper. I suggest we create a ticket to improve in the future and roll with what we have now