-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
45 lines (36 loc) · 1.21 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as fs from 'fs';
import factory from 'rdf-ext';
import rdfParserImport from 'rdf-parse';
import rdfSerializerImport from 'rdf-serialize';
import stringifyStream from 'stream-to-string';
import SHACLValidator from 'rdf-validate-shacl';
async function loadDataset (filePath) {
const stream = fs.createReadStream(filePath);
const rdfParser = rdfParserImport.default;
return factory.dataset().import(
rdfParser.parse(stream, { path: filePath })
);
}
async function main(shapeFile,dataFile) {
const shapes = await loadDataset(shapeFile)
const data = await loadDataset(dataFile)
const validator = new SHACLValidator(shapes, { factory })
const report = await validator.validate(data)
const rdfSerializer = rdfSerializerImport.default;
const quadStream = report.dataset.toStream();
const textStream = rdfSerializer.serialize(quadStream, { path: shapeFile });
console.log(await stringifyStream(textStream));
if (report.conforms) {
process.exit(0);
}
else {
process.exit(2);
}
}
if (process.argv.length != 4) {
console.error("usage: index.js shapeFile dataFile");
process.exit(1);
}
const shapeFile = process.argv[2];
const dataFile = process.argv[3];
main(shapeFile,dataFile);