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 11 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
12 changes: 12 additions & 0 deletions src/validation-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ValidationReport from './validation-report.js'
import { extractStructure, extractSourceShapeStructure } from './dataset-utils.js'

const error = debug('validation-enging::error')
const maxRecursionDepth = 30

class ValidationEngine {
constructor(context, options) {
Expand All @@ -23,6 +24,7 @@ class ValidationEngine {

initReport() {
const { rdf, sh } = this.context.ns
this.checkedNodes = {}

this.reportPointer = clownface({
dataset: this.factory.dataset(),
Expand Down Expand Up @@ -67,6 +69,16 @@ class ValidationEngine {

if (shape.deactivated) return false

// check recursion depth: how many times have we already checked this focusNode against this shape?
let id = JSON.stringify([focusNode, shape.shapeNode])
let recursionDepth = this.checkedNodes[id] === undefined ? 0 : this.checkedNodes[id]
tpluscode marked this conversation as resolved.
Show resolved Hide resolved
if (recursionDepth > maxRecursionDepth) {
// max recursion depth reached, so bail out
return false
}
// increment check counter for given focusNode/shape pair
this.checkedNodes[id] = recursionDepth + 1

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> ;
.