Skip to content

Commit

Permalink
fixes #136
Browse files Browse the repository at this point in the history
  • Loading branch information
s-tittel committed Jul 15, 2024
1 parent e865cac commit 7caa7a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SHACLValidator {
this.allowNamedNodeInList = options.allowNamedNodeInList === undefined ? false : options.allowNamedNodeInList
this.loadShapes(shapes)
this.validationEngine = new ValidationEngine(this, options)
this.checkedNodes = new Set()

this.depth = 0
}
Expand All @@ -34,6 +35,7 @@ class SHACLValidator {
* @return {ValidationReport} - Result of the validation
*/
validate(data) {
this.checkedNodes.clear()
this.$data = clownface({ dataset: data, factory: this.factory })
this.validationEngine.validateAll(this.$data)
return this.validationEngine.getReport()
Expand All @@ -48,6 +50,7 @@ class SHACLValidator {
* @returns {ValidationReport} - Result of the validation
*/
validateNode(data, focusNode, shapeNode) {
this.checkedNodes.clear()
this.$data = clownface({ dataset: data, factory: this.factory })
this.nodeConformsToShape(focusNode, shapeNode, this.validationEngine)
return this.validationEngine.getReport()
Expand Down
10 changes: 10 additions & 0 deletions src/validation-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ 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.
if (focusNode.id && shape.shapeNode.id) {
let id = focusNode.id + '::' + shape.shapeNode.id
if (this.context.checkedNodes.has(id)) {
return false
}
// mark given focusNode/shape pair as 'checked'.
this.context.checkedNodes.add(id)
}

const valueNodes = shape.getValueNodes(focusNode, dataGraph)
let errorFound = false
for (const constraint of shape.constraints) {
Expand Down

0 comments on commit 7caa7a1

Please sign in to comment.