Skip to content
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

fixes https://github.com/zazuko/rdf-validate-shacl/issues/136 #137

Merged
merged 13 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/validation-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ValidationEngine {
this.violationsCount = 0
this.validationError = null
this.nestedResults = {}
this.checkedNodes = new Set()
}

clone() {
Expand Down Expand Up @@ -42,6 +43,7 @@ class ValidationEngine {
this.validationError = null
try {
this.initReport()
this.checkedNodes.clear()
tpluscode marked this conversation as resolved.
Show resolved Hide resolved
let foundError = false
const shapes = this.context.shapesGraph.shapesWithTarget
for (const shape of shapes) {
Expand All @@ -67,6 +69,14 @@ class ValidationEngine {

if (shape.deactivated) return false

// have we already checked this focusNode against the shape? If so, don't check again to prevent possible recursion.
let id = JSON.stringify([focusNode, shape.shapeNode])
if (this.checkedNodes.has(id)) {
return false
}
// mark given focusNode/shape pair as 'checked'.
this.checkedNodes.add(id)

const valueNodes = shape.getValueNodes(focusNode, dataGraph)
let errorFound = false
for (const constraint of shape.constraints) {
Expand Down
48 changes: 48 additions & 0 deletions test/data/data-shapes/custom/circularReferences.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@prefix dash: <http://datashapes.org/dash#> .
@prefix ex: <http://example.org#> .
@prefix mf: <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix sht: <http://www.w3.org/ns/shacl-test#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<>
rdf:type mf:Manifest ;
mf:entries (
<circularReferences>
) ;
.

<circularReferences>
rdf:type sht:Validate ;
rdfs:label "Test of circular references in data graph" ;
mf:action [
sht:dataGraph <> ;
sht:shapesGraph <> ;
] ;
mf:result [
rdf:type sh:ValidationReport ;
sh:conforms "true"^^xsd:boolean ;
] ;
.

ex:Thing
a sh:NodeShape,rdfs:Class ;
sh:property [
sh:path ex:references ;
sh:node ex:Thing
] ;
sh:targetClass <Thing>
.

<thing1>
a <Thing> ;
ex:references <thing2>
.

<thing2>
a <Thing> ;
ex:references <thing1> ;
.
1 change: 1 addition & 0 deletions test/data/data-shapes/custom/manifest.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
mf:include <multiLevelInheritanceWithImplicitTarget.ttl> ;
mf:include <targetNodeDoesNotExist.ttl> ;
mf:include <lessThan-moreTypes.ttl> ;
mf:include <circularReferences.ttl> ;
.
Loading