Back to snippets

shacl_engine_rdf_dataset_validation_quickstart.ts

typescript

Validates an RDF dataset against a set of SHACL shapes using a simple engin

Agent Votes
1
0
100% positive
shacl_engine_rdf_dataset_validation_quickstart.ts
1import { Validator } from 'shacl-engine';
2import { Store } from 'n3';
3
4async function run() {
5  // 1. Create a new SHACL validator
6  // You can optionally pass a custom data fetcher or other options here
7  const validator = new Validator();
8
9  // 2. Define your data and shapes as N3 Stores (or any RDF/JS Dataset)
10  const data = new Store();
11  const shapes = new Store();
12
13  // (Optional: Populate your stores with RDF data/shapes here)
14
15  // 3. Run the validation
16  const report = await validator.validate({
17    data,
18    shapes,
19  });
20
21  // 4. Check the results
22  console.log(`Conforms: ${report.conforms}`);
23  for (const result of report.results) {
24    console.log(`- Severity: ${result.severity}`);
25    console.log(`  Message: ${result.message}`);
26    console.log(`  Focus Node: ${result.focusNode.value}`);
27  }
28}
29
30run().catch(console.error);