rdf-validate-shacl
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -22,2 +22,3 @@ const clownface = require('clownface') | ||
this.ns = prepareNamespaces(this.factory) | ||
this.allowNamedNodeInList = options.allowNamedNodeInList === undefined ? false : options.allowNamedNodeInList | ||
this.loadShapes(shapes) | ||
@@ -24,0 +25,0 @@ this.validationEngine = new ValidationEngine(this, options) |
{ | ||
"name": "rdf-validate-shacl", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "RDF SHACL validator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# rdf-validate-shacl | ||
Validate RDF data purely in JavaScript. An implementation of the [W3C SHACL](https://www.w3.org/TR/shacl/) specification on top of the [RDFJS](https://www.w3.org/TR/shacl/) stack. | ||
Validate RDF data purely in JavaScript. An implementation of the [W3C SHACL](https://www.w3.org/TR/shacl/) | ||
specification on top of the [RDFJS](https://www.w3.org/TR/shacl/) stack. | ||
@@ -68,2 +69,4 @@ [](https://badge.fury.io/js/rdf-validate-shacl) | ||
stop. By default, it only stops after all the errors are found. | ||
- `allowNamedNodeInList`: SHACL only allows blank nodes in property lists. To | ||
allow named nodes to occur in property lists, set this value to `true`. | ||
@@ -70,0 +73,0 @@ ## Running the tests |
@@ -8,14 +8,16 @@ const NodeSet = require('./node-set') | ||
* @param {Clownface} pathNode - Pointer to the start node of the path | ||
* @param {object} ns - Namespaces | ||
* @param {boolean} allowNamedNodeInList - Allow named node in lists. By default, only blank nodes are allowed | ||
* @return Property path object | ||
*/ | ||
function extractPropertyPath (pathNode, ns) { | ||
if (pathNode.term.termType === 'NamedNode') { | ||
function extractPropertyPath (pathNode, ns, allowNamedNodeInList) { | ||
if (pathNode.term.termType === 'NamedNode' && !allowNamedNodeInList) { | ||
return pathNode.term | ||
} | ||
if (pathNode.term.termType === 'BlankNode') { | ||
if (pathNode.term.termType === 'BlankNode' || pathNode.term.termType === 'NamedNode') { | ||
const first = pathNode.out(ns.rdf.first).term | ||
if (first) { | ||
const paths = [...pathNode.list()] | ||
return paths.map(path => extractPropertyPath(path, ns)) | ||
return paths.map(path => extractPropertyPath(path, ns, allowNamedNodeInList)) | ||
} | ||
@@ -26,3 +28,3 @@ | ||
const paths = [...alternativePath.list()] | ||
return { or: paths.map(path => extractPropertyPath(path, ns)) } | ||
return { or: paths.map(path => extractPropertyPath(path, ns, allowNamedNodeInList)) } | ||
} | ||
@@ -32,3 +34,3 @@ | ||
if (zeroOrMorePath.term) { | ||
return { zeroOrMore: extractPropertyPath(zeroOrMorePath, ns) } | ||
return { zeroOrMore: extractPropertyPath(zeroOrMorePath, ns, allowNamedNodeInList) } | ||
} | ||
@@ -38,3 +40,3 @@ | ||
if (oneOrMorePath.term) { | ||
return { oneOrMore: extractPropertyPath(oneOrMorePath, ns) } | ||
return { oneOrMore: extractPropertyPath(oneOrMorePath, ns, allowNamedNodeInList) } | ||
} | ||
@@ -44,3 +46,3 @@ | ||
if (zeroOrOnePath.term) { | ||
return { zeroOrOne: extractPropertyPath(zeroOrOnePath, ns) } | ||
return { zeroOrOne: extractPropertyPath(zeroOrOnePath, ns, allowNamedNodeInList) } | ||
} | ||
@@ -50,6 +52,7 @@ | ||
if (inversePath.term) { | ||
return { inverse: extractPropertyPath(inversePath, ns) } | ||
return { inverse: extractPropertyPath(inversePath, ns, allowNamedNodeInList) } | ||
} | ||
return pathNode.term | ||
} | ||
throw new Error(`Unsupported SHACL path: ${pathNode.term.value}`) | ||
@@ -56,0 +59,0 @@ } |
@@ -250,6 +250,6 @@ // Design: | ||
get pathObject () { | ||
const { $shapes, ns } = this.context | ||
const { $shapes, ns, allowNamedNodeInList } = this.context | ||
if (this._pathObject === undefined) { | ||
this._pathObject = this.path ? extractPropertyPath($shapes.node(this.path), ns) : null | ||
this._pathObject = this.path ? extractPropertyPath($shapes.node(this.path), ns, allowNamedNodeInList) : null | ||
} | ||
@@ -256,0 +256,0 @@ |
8305
99
398323
15