-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #125 #126
Merged
Merged
fix #125 #126
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"rdf-validate-shacl": patch | ||
--- | ||
|
||
fix #125 (phantom result details) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@prefix sh: <http://www.w3.org/ns/shacl#> . | ||
@prefix ex: <https://example.org/> . | ||
|
||
ex:person1 a ex:Person . | ||
[] a ex:Person . | ||
|
||
ex:personShape a sh:NodeShape ; | ||
sh:targetClass ex:Person ; | ||
sh:node [ sh:nodeKind sh:BlankNode ] . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@prefix ex: <https://example.org/> . | ||
|
||
ex:person1 a ex:Person ; ex:address ex:address1 . | ||
|
||
ex:address1 ex:city "London" . | ||
|
||
ex:tv ex:size ex:big . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@prefix sh: <http://www.w3.org/ns/shacl#> . | ||
@prefix ex: <https://example.org/> . | ||
|
||
ex:personShape a sh:NodeShape ; | ||
sh:targetClass ex:Person ; | ||
sh:property [ | ||
sh:path ex:address ; | ||
sh:message "ex:city should be sh:IRI" ; | ||
sh:node ex:cityShape | ||
] . | ||
|
||
ex:cityShape | ||
sh:property [ | ||
sh:path ex:city ; | ||
sh:nodeKind sh:IRI | ||
] . | ||
|
||
ex:sizeShape | ||
sh:targetObjectsOf ex:size ; | ||
sh:or ( | ||
[ sh:hasValue ex:small ] | ||
[ sh:hasValue ex:big ] | ||
) . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-env mocha */ | ||
import path from 'path' | ||
import assert from 'assert' | ||
import * as url from 'url' | ||
import RDF from '@zazuko/env-node' | ||
import SHACLValidator from '../index.js' | ||
import { loadDataset } from './utils.js' | ||
|
||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) | ||
const rootPath = path.join(__dirname, '/data/validation-details') | ||
|
||
describe('validation details', () => { | ||
it('creates detail for node constraint', async () => { | ||
const data = await loadDataset(path.join(rootPath, 'node-constraint-details.ttl')) | ||
const shapes = data | ||
|
||
const validator = new SHACLValidator(shapes) | ||
const report = validator.validate(data) | ||
|
||
assert.equal(1, report.results.length) | ||
const result = report.results[0] | ||
assert.deepStrictEqual(result.sourceConstraintComponent, RDF.ns.sh.NodeConstraintComponent) | ||
assert.deepStrictEqual(result.focusNode, RDF.namedNode('https://example.org/person1')) | ||
assert.deepStrictEqual(result.value, RDF.namedNode('https://example.org/person1')) | ||
|
||
assert.equal(1, result.detail.length) | ||
const detail = result.detail[0] | ||
assert.deepStrictEqual(detail.sourceConstraintComponent, RDF.ns.sh.NodeKindConstraintComponent) | ||
assert.deepStrictEqual(detail.focusNode, RDF.namedNode('https://example.org/person1')) | ||
assert.deepStrictEqual(detail.value, RDF.namedNode('https://example.org/person1')) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-env mocha */ | ||
import path from 'path' | ||
import assert from 'assert' | ||
import * as url from 'url' | ||
import RDF from '@zazuko/env-node' | ||
import SHACLValidator from '../index.js' | ||
import { loadDataset } from './utils.js' | ||
|
||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) | ||
const rootPath = path.join(__dirname, '/data/validation-repro') | ||
|
||
describe('validation repro', () => { | ||
it('repro #125', async () => { | ||
const data = await loadDataset(path.join(rootPath, 'repro125-data.ttl')) | ||
const shapes = await loadDataset(path.join(rootPath, 'repro125-shapes.ttl')) | ||
|
||
const validator = new SHACLValidator(shapes) | ||
const report = validator.validate(data) | ||
|
||
assert.equal(1, report.results.length) | ||
const result = report.results[0] | ||
assert.deepStrictEqual(result.sourceConstraintComponent, RDF.ns.sh.NodeConstraintComponent) | ||
assert.deepStrictEqual(result.focusNode, RDF.namedNode('https://example.org/person1')) | ||
assert.deepStrictEqual(result.path, RDF.namedNode('https://example.org/address')) | ||
assert.deepStrictEqual(result.value, RDF.namedNode('https://example.org/address1')) | ||
assert.deepStrictEqual(result.message, [RDF.literal('ex:city should be sh:IRI')]) | ||
|
||
assert.equal(1, result.detail.length) | ||
const detail = result.detail[0] | ||
assert.deepStrictEqual(detail.sourceConstraintComponent, RDF.ns.sh.NodeKindConstraintComponent) | ||
assert.deepStrictEqual(detail.focusNode, RDF.namedNode('https://example.org/address1')) | ||
assert.deepStrictEqual(detail.path, RDF.namedNode('https://example.org/city')) | ||
assert.deepStrictEqual(detail.value, RDF.literal('London')) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why clone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using a fresh instance of validation engine we avoid side effects (collection of result details) on the current instance.
Only when calling from a
sh:node
constraint we do want to affect the current instance, in the other cases (sh:and
,sh:or
,sh:not
...) we are only interested in the boolean result and we don't care about the details.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I wonder if that is entirely true. I was always thinking that to improve the error messages in complex scenarios would require a smarter analysis of the nested results. But maybe it's better to reorganise the shapes and write good, targeted messages...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
admittedly, this PR is a bit of hacking trying to fix the anomaly. Redesigning all the result details to provide more insights for violations of logical constraints is intriguing but beyond the scope of this PR.