Skip to content

Commit

Permalink
renamed vairables to reflect semantics and moved maxNodeChecks to opt…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
s-tittel committed Jul 23, 2024
1 parent d0f440c commit 20cb981
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/validation-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import ValidationReport from './validation-report.js'
import { extractStructure, extractSourceShapeStructure } from './dataset-utils.js'

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

class ValidationEngine {
constructor(context, options) {
this.context = context
this.factory = context.factory
this.maxErrors = options.maxErrors
this.maxNodeChecks = options.maxNodeChecks === undefined ? defaultMaxNodeChecks : options.maxNodeChecks
this.initReport()
this.recordErrorsLevel = 0
this.violationsCount = 0
Expand All @@ -19,12 +20,12 @@ class ValidationEngine {
}

clone() {
return new ValidationEngine(this.context, { maxErrors: this.maxErrors })
return new ValidationEngine(this.context, { maxErrors: this.maxErrors, maxNodeChecks: this.maxNodeChecks })
}

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

this.reportPointer = clownface({
dataset: this.factory.dataset(),
Expand Down Expand Up @@ -69,15 +70,17 @@ 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]
if (recursionDepth > maxRecursionDepth) {
// max recursion depth reached, so bail out
return false
if (this.maxNodeChecks > 0) {
// check how many times we have already tested this focusNode against this shape
const id = JSON.stringify([focusNode, shape.shapeNode])
const nodeCheckCounter = this.nodeCheckCounters[id] === undefined ? 0 : this.nodeCheckCounters[id]
if (nodeCheckCounter > this.maxNodeChecks) {
// max node checks reached, so bail out
return false
}
// increment check counter for given focusNode/shape pair
this.nodeCheckCounters[id] = nodeCheckCounter + 1
}
// increment check counter for given focusNode/shape pair
this.checkedNodes[id] = recursionDepth + 1

const valueNodes = shape.getValueNodes(focusNode, dataGraph)
let errorFound = false
Expand Down

0 comments on commit 20cb981

Please sign in to comment.