-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from zazuko/list-in-message
lists in result messages
- Loading branch information
Showing
11 changed files
with
186 additions
and
24 deletions.
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 | ||
--- | ||
|
||
Improved result messages with lists |
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
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,11 @@ | ||
@prefix sh: <http://www.w3.org/ns/shacl#> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
|
||
<Alice> a <Person> ; <category> "f" . | ||
|
||
<ShapeWithList> a sh:NodeShape ; | ||
sh:targetClass <Person> ; | ||
sh:property [ | ||
sh:path <category> ; | ||
sh:in ("a" "b" "c" "d" "e") ; | ||
] . |
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,12 @@ | ||
@prefix sh: <http://www.w3.org/ns/shacl#> . | ||
@prefix ex: <http://example.com/> . | ||
|
||
ex:p1 a ex:Person ; ex:category 3 . | ||
ex:p2 a ex:Person ; ex:category 30, 40 . | ||
|
||
ex:shape sh:targetClass ex:Person ; | ||
sh:property [ | ||
sh:path ex:category ; | ||
sh:minCount 2 ; | ||
sh:in (1 2 3 4 5) ; | ||
] . |
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,11 @@ | ||
@prefix sh: <http://www.w3.org/ns/shacl#> . | ||
@prefix ex: <http://example.com/> . | ||
|
||
ex:p1 a ex:Person . | ||
|
||
ex:shape sh:targetClass ex:Person ; | ||
sh:property [ | ||
sh:path ex:category ; | ||
sh:minCount 1 ; | ||
sh:in (1 2 3) ; | ||
] . |
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,52 @@ | ||
/* eslint-env mocha */ | ||
import path from 'path' | ||
import assert from 'assert' | ||
import * as url from 'url' | ||
import clownface from 'clownface' | ||
import SHACLValidator from '../index.js' | ||
import ns from '../src/namespaces.js' | ||
import { rdfListToArray } from '../src/dataset-utils.js' | ||
import { loadDataset } from './utils.js' | ||
|
||
const { rdfs, sh } = ns | ||
|
||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) | ||
const rootPath = path.join(__dirname, '/data/validation-sourceShape') | ||
|
||
describe('validation source shapes', () => { | ||
it('Includes source shape without long list', async () => { | ||
const dataPath = path.join(rootPath, 'long-list.ttl') | ||
const data = await loadDataset(dataPath) | ||
const shapes = data | ||
|
||
const validator = new SHACLValidator(shapes) | ||
const report = validator.validate(data) | ||
|
||
// three results for the same source shape | ||
assert.strictEqual(report.results.length, 3) | ||
const sourceShapes = new Set(report.results.map(result => result.sourceShape)) | ||
assert.strictEqual(sourceShapes.size, 1) | ||
const [shape] = sourceShapes | ||
// the shape has a comment instead of sh:in | ||
assert.deepEqual([], [...report.dataset.match(shape, sh.in, null)]) | ||
const [comment] = report.dataset.match(shape, rdfs.comment, null) | ||
assert.strictEqual(comment.object.value, 'sh:in has 5 elements and has been removed from the report for brevity. Please refer the original shape') | ||
}) | ||
it('Includes source shape with list', async () => { | ||
const dataPath = path.join(rootPath, 'mandatory-list.ttl') | ||
const data = await loadDataset(dataPath) | ||
const shapes = data | ||
|
||
const validator = new SHACLValidator(shapes) | ||
const report = validator.validate(data) | ||
|
||
assert.strictEqual(report.results.length, 1) | ||
const sourceShapes = new Set(report.results.map(result => result.sourceShape)) | ||
assert.strictEqual(sourceShapes.size, 1) | ||
const [shape] = sourceShapes | ||
// the shape has the lst of allowed values even though the violated constraint is sh:minCount and not sh:in | ||
const list = clownface({ dataset: report.dataset, term: shape }).out(sh.in) | ||
const actual = rdfListToArray(list).map(term => term.value) | ||
assert.deepEqual(actual, ['1', '2', '3']) | ||
}) | ||
}) |