eyeling 1.11.23 → 1.11.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/run-inprocess.js +103 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyeling",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.24",
|
|
4
4
|
"description": "A minimal Notation3 (N3) reasoner in JavaScript.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"eyeling.js",
|
|
29
29
|
"index.d.ts",
|
|
30
30
|
"index.js",
|
|
31
|
+
"run-inprocess.js",
|
|
31
32
|
"lib",
|
|
32
33
|
"test",
|
|
33
34
|
"tools"
|
package/run-inprocess.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// run-inprocess.js
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
|
|
7
|
+
// Local repo engine (in-process)
|
|
8
|
+
const engine = require("./lib/engine.js");
|
|
9
|
+
|
|
10
|
+
const argv = process.argv.slice(2);
|
|
11
|
+
|
|
12
|
+
let overall = 0; // 0 ok, 1 error, 2 contradiction/fuse seen
|
|
13
|
+
|
|
14
|
+
function prefixLabel(pfx) {
|
|
15
|
+
// N3/Turtle syntax requires the trailing ':'
|
|
16
|
+
return pfx === "" ? ":" : `${pfx}:`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function printPrefixes(prefixes, derivedTriples) {
|
|
20
|
+
const used = prefixes.prefixesUsedForOutput(derivedTriples);
|
|
21
|
+
for (const [pfx, base] of used) {
|
|
22
|
+
console.log(`@prefix ${prefixLabel(pfx)} <${base}> .`);
|
|
23
|
+
}
|
|
24
|
+
if (used.length && derivedTriples.length) console.log();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function statSafe(p) {
|
|
28
|
+
try {
|
|
29
|
+
return fs.statSync(p);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return { __err: e };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function runOne(file) {
|
|
36
|
+
const st = statSafe(file);
|
|
37
|
+
if (st.__err) {
|
|
38
|
+
console.error(`# skip ${file} (stat failed: ${st.__err.code || st.__err.message})`);
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
if (st.isDirectory()) {
|
|
42
|
+
console.error(`# skip ${file} (is a directory)`);
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
if (!st.isFile()) {
|
|
46
|
+
console.error(`# skip ${file} (not a regular file)`);
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let n3;
|
|
51
|
+
try {
|
|
52
|
+
n3 = fs.readFileSync(file, "utf8");
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.error(`# ${file} failed (read error: ${e.code || e.message}). Continuing…`);
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Trap process.exit so a fuse/contradiction (exit 2) doesn't stop the batch.
|
|
59
|
+
const origExit = process.exit;
|
|
60
|
+
process.exit = (code = 0) => {
|
|
61
|
+
const err = new Error(`eyeling requested process.exit(${code})`);
|
|
62
|
+
err.code = code;
|
|
63
|
+
throw err;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const res = engine.reasonStream(n3, {
|
|
68
|
+
baseIri: "file://" + path.resolve(file),
|
|
69
|
+
proof: false,
|
|
70
|
+
includeInputFactsInClosure: true,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// CLI-like output: derived triples only (not the full closure)
|
|
74
|
+
const derivedTriples = res.derived.map((df) => df.fact);
|
|
75
|
+
if (!derivedTriples.length) return 0;
|
|
76
|
+
|
|
77
|
+
printPrefixes(res.prefixes, derivedTriples);
|
|
78
|
+
|
|
79
|
+
for (const df of res.derived) {
|
|
80
|
+
console.log(engine.tripleToN3(df.fact, res.prefixes));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return 0;
|
|
84
|
+
} catch (e) {
|
|
85
|
+
if (e && e.code === 2) {
|
|
86
|
+
console.error(`# ${path.basename(file)} failed (exit 2: contradiction/fuse). Continuing…`);
|
|
87
|
+
return 2;
|
|
88
|
+
}
|
|
89
|
+
console.error(`# ${file} failed (${e && (e.stack || e.message) ? (e.stack || e.message) : String(e)}). Continuing…`);
|
|
90
|
+
return 1;
|
|
91
|
+
} finally {
|
|
92
|
+
process.exit = origExit;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
for (const f of argv) {
|
|
97
|
+
const code = runOne(f);
|
|
98
|
+
overall = Math.max(overall, code);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Preserve a useful overall exit status for CI
|
|
102
|
+
process.exitCode = overall;
|
|
103
|
+
|