All Projects → zazuko → rdf-validate-shacl

zazuko / rdf-validate-shacl

Licence: MIT License
Validate RDF data purely in JavaScript. An implementation of the W3C SHACL specification on top of the RDFJS stack.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to rdf-validate-shacl

Easierrdf
Making RDF easy enough for average developers
Stars: ✭ 152 (+149.18%)
Mutual labels:  rdf, w3c
OLGA
an Ontology SDK
Stars: ✭ 36 (-40.98%)
Mutual labels:  rdf, w3c
Unicorn
Unicorn - W3C's Unified Validator
Stars: ✭ 70 (+14.75%)
Mutual labels:  validation, w3c
corese
Software platform implementing and extending the standards of the Semantic Web.
Stars: ✭ 55 (-9.84%)
Mutual labels:  rdf, shacl
Rdfunit
An RDF Unit Testing Suite
Stars: ✭ 117 (+91.8%)
Mutual labels:  validation, rdf
rdfshape-api
API for validating and transforming RDF, ShEx, SHACL and more.
Stars: ✭ 31 (-49.18%)
Mutual labels:  rdf, shacl
react-native-validator-form
Simple validator for react-native forms.
Stars: ✭ 21 (-65.57%)
Mutual labels:  validation
pyvaru
Rule based data validation library for python 3.
Stars: ✭ 17 (-72.13%)
Mutual labels:  validation
Maat
Validation and transformation library powered by deductive ascending parser. Made to be extended for any kind of project.
Stars: ✭ 27 (-55.74%)
Mutual labels:  validation
openui5-validator
A library to validate OpenUI5 fields
Stars: ✭ 17 (-72.13%)
Mutual labels:  validation
brutal
A code-first approach to automate the writing of unit tests.
Stars: ✭ 54 (-11.48%)
Mutual labels:  shape
datalize
Parameter, query, form data validation and filtering for NodeJS.
Stars: ✭ 55 (-9.84%)
Mutual labels:  validation
rdf-canonize
An implementation of the RDF Dataset Normalization Algorithm in JavaScript.
Stars: ✭ 14 (-77.05%)
Mutual labels:  rdf
Events-based-organizational-website
The official codebase for college-based (event managing) organizations. FOUR-LEVEL Authorization system and scalable.
Stars: ✭ 14 (-77.05%)
Mutual labels:  validation
phone
Validate phone number format
Stars: ✭ 63 (+3.28%)
Mutual labels:  validation
jsonld-streaming-serializer.js
A fast and lightweight streaming JSON-LD serializer for JavaScript
Stars: ✭ 20 (-67.21%)
Mutual labels:  rdf
frames-android
Checkout API Client, Payment Form UI and Utilities
Stars: ✭ 26 (-57.38%)
Mutual labels:  validation
valify
Validates data in JavaScript in a very simple way
Stars: ✭ 13 (-78.69%)
Mutual labels:  validation
hapic
Input/Output/Error management for your python controllers with Swagger doc generation
Stars: ✭ 18 (-70.49%)
Mutual labels:  validation
filter
Go语言的数据过滤包,由 数据输入、格式化、校验、输出 几个部份组成。
Stars: ✭ 22 (-63.93%)
Mutual labels:  validation

rdf-validate-shacl

Validate RDF data purely in JavaScript. An implementation of the W3C SHACL specification on top of the RDFJS stack.

npm version

We provide a SHACL playground based on this library.

Usage

The library only handles SHACL validation and not data loading/parsing. The following example uses rdf-utils-fs for this purpose. For more information about handling RDF data in JavaScript, check out Get started with RDF in JavaScript.

The validation function returns a ValidationReport object that can be used to inspect conformance and results. The ValidationReport also has a .dataset property, which provides the report as RDF data.

const fs = require('fs')
const factory = require('rdf-ext')
const ParserN3 = require('@rdfjs/parser-n3')
const SHACLValidator = require('rdf-validate-shacl')

async function loadDataset (filePath) {
  const stream = fs.createReadStream(filePath)
  const parser = new ParserN3({ factory })
  return factory.dataset().import(parser.import(stream))
}

async function main() {
  const shapes = await loadDataset('my-shapes.ttl')
  const data = await loadDataset('my-data.ttl')

  const validator = new SHACLValidator(shapes, { factory })
  const report = await validator.validate(data)

  // Check conformance: `true` or `false`
  console.log(report.conforms)

  for (const result of report.results) {
    // See https://www.w3.org/TR/shacl/#results-validation-result for details
    // about each property
    console.log(result.message)
    console.log(result.path)
    console.log(result.focusNode)
    console.log(result.severity)
    console.log(result.sourceConstraintComponent)
    console.log(result.sourceShape)
  }

  // Validation report as RDF dataset
  console.log(report.dataset)
}

main();

Validator options

The SHACLValidator constructor accepts an optional options object as second parameter. The available options are:

  • factory: RDF/JS data factory (must have a .dataset() method)
  • maxErrors: max number of errors after which the validation process should 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.

Running the tests

$ npm test

Regenerating vocabularies

The SHACL vocabulary is imported from @zazuko/rdf-vocabularies and pre-parsed in src/vocabularies/shacl.js.

After updating the @zazuko/rdf-vocabularies dependency, run npm run generate-vocabularies to regenerate the pre-parsed vocabulary.

Limitations

rdf-validate-shacl does not support SHACL-SPARQL constraints

About

rdf-validate-shacl was originally a fork of shacl-js meant to make it compatible with RDF/JS libraries. Since then, we dropped support for the SHACL-JS extension and adapted the API to suit our needs.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].