rdf-ext/shacl-engine

SHACL engine goes out of memory when classes are subclasses of themselves.

mightymax opened this issue · 2 comments

In RDF each class is a rdfs:subClassOf of itself. When this is defined in the model explicitly, the SHACL validation engine runs out of memory, probably due to some eternal loop. Here is a minimal working example demonstrating this behaviour:

import N3 from 'n3'
import {Validator} from 'shacl-engine'

const dataset = new N3.Store()
const parser = new N3.Parser();
parser.parse(
  `
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sh: <http://www.w3.org/ns/shacl#>
prefix ex: <http://example.org/>

ex:ObjectShape sh:targetClass ex:Object.
ex:Object rdfs:subClassOf ex:Object .
`,
  (error, quad) => {
    if(error) throw error
    if (quad)
      dataset.addQuad(quad);
    else {
      // create a validator instance for the shapes in the given dataset
      const validator = new Validator(dataset, { factory: N3.DataFactory })

      // run the validation process
      validator.validate({ dataset })
        .then(report => {
          // check if the data conforms to the given shape
          console.log(`conforms: ${report.conforms}`)
        })
    }
  });

A workaround is, of course to not use explicit subclasses, but since this is a valid construction it might be good to support this in the SHACL engine.

Looks like this needs to be fixed in grapoi. I will have a closer look in the next few days.