-
Notifications
You must be signed in to change notification settings - Fork 2
/
validate.js
75 lines (67 loc) · 2.09 KB
/
validate.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const path = require('path');
const os = require("os");
const fs = require("fs");
const Validator = require('./lib/Validator');
const argv = require('minimist')(process.argv.slice(2));
let basePath = path.resolve(__dirname);
let profile = 'owl';
let distPath = path.resolve(basePath, 'dist', 'n3unit.pvm');
let queryPath = argv.count ? path.resolve(basePath, 'resources', 'rules', 'query_count.n3') : path.resolve(basePath, 'resources', 'rules', 'query.n3');
let profilePath = path.resolve(basePath, 'profiles', profile + '.n3');
let validationOpts = {
queryPath,
extraFiles: [distPath, profilePath]
};
if (!argv.i) {
console.log('-i is required!');
process.exit(-1);
}
if (!argv.o) {
console.log('-o is required!');
process.exit(-1);
}
if (argv.ram) {
validationOpts.ram = argv.ram;
}
let sourcePath = argv.i;
let outputPath = argv.o;
let schemas = argv.s ? argv.s.split(',') : null;
if (schemas) {
const prefices = JSON.parse(fs.readFileSync(path.resolve(basePath, 'resources', 'ontologies', 'prefix.json')));
schemas = schemas.map(function (schema) {
return prefices[schema] ? {uri: prefices[schema]} : {prefix: schema}
});
}
let validator = new Validator(validationOpts);
const startTime = new Date();
const extrafiles = [];
if (argv.r) {
let profiles = argv.r.split(',');
if (profiles.indexOf('rdfs') >= 0) {
extrafiles.push({
path: path.resolve(basePath, 'resources/rules/reasoning/rdfs_rules.n3'),
type: 'n3'
});
}
if (profiles.indexOf('owl') >= 0) {
extrafiles.push({
path: path.resolve(basePath, 'resources/rules/reasoning/owl_rules.n3'),
type: 'n3'
});
}
}
validator.validateStreamFileByOntologies(sourcePath, schemas, extrafiles, function (err, child) {
if (err) {
throw err;
}
let outStream = fs.createWriteStream(outputPath, 'utf8');
child.stderr.pipe(process.stderr);
child.stdout.pipe(outStream);
child.on('close', function (code) {
if (code !== 0) {
throw new Error("Couldn't reason: code " + code);
}
const endTime = new Date();
console.log(`done in ${endTime.getTime() - startTime.getTime()}!`);
});
});