eyereasoner 1.14.0 → 2.0.0
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/README.md +12 -8
- package/dist/bin/index.d.ts +2 -0
- package/dist/bin/index.js +21 -0
- package/dist/eye.d.ts +2 -0
- package/dist/eye.js +3 -0
- package/dist/index.d.ts +5 -7
- package/dist/index.js +6 -8
- package/dist/swipl-bundled.temp.js +227 -264
- package/dist/transformers.d.ts +5 -38
- package/dist/transformers.js +17 -87
- package/package.json +8 -10
- package/dist/eye.pl.d.ts +0 -2
- package/dist/eye.pl.js +0 -5
- package/dist/eye.pvm.d.ts +0 -2
- package/dist/eye.pvm.js +0 -5
package/dist/transformers.d.ts
CHANGED
|
@@ -1,34 +1,12 @@
|
|
|
1
1
|
/// <reference types="emscripten" />
|
|
2
2
|
import type { SWIPLModule } from 'swipl-wasm/dist/swipl/swipl';
|
|
3
3
|
import { Quad } from '@rdfjs/types';
|
|
4
|
-
import
|
|
5
|
-
export declare function loadEyeImage(swipl: typeof
|
|
4
|
+
import type SWIPL_TYPE from 'swipl-wasm/dist/common';
|
|
5
|
+
export declare function loadEyeImage(swipl: typeof SWIPL_TYPE): (options?: Partial<EmscriptenModule> | undefined) => Promise<SWIPLModule>;
|
|
6
6
|
/**
|
|
7
7
|
* Creates default SWIPL image loaded with EYE
|
|
8
8
|
*/
|
|
9
|
-
export declare function SwiplEye(options?: Partial<EmscriptenModule> | undefined):
|
|
10
|
-
/**
|
|
11
|
-
* Writes eye.pl to the Module
|
|
12
|
-
* @param Module A SWIPL Module
|
|
13
|
-
* @returns A SWIPL Module
|
|
14
|
-
* @deprecated
|
|
15
|
-
*/
|
|
16
|
-
export declare function writeEye(Module: SWIPLModule): SWIPLModule;
|
|
17
|
-
/**
|
|
18
|
-
* Consults the eye.pl Module
|
|
19
|
-
* @param Module A SWIPL Module
|
|
20
|
-
* @returns A SWIPL Module
|
|
21
|
-
* @deprecated
|
|
22
|
-
*/
|
|
23
|
-
export declare function consultEye(Module: SWIPLModule): SWIPLModule;
|
|
24
|
-
/**
|
|
25
|
-
* A SWIPL transformer that loads and consults eye.pl in the
|
|
26
|
-
* given SWIPL module
|
|
27
|
-
* @param Module A SWIPL Module
|
|
28
|
-
* @returns The same SWIPL module with EYE loaded and consulted
|
|
29
|
-
* @deprecated
|
|
30
|
-
*/
|
|
31
|
-
export declare function loadEye(Module: SWIPLModule): SWIPLModule;
|
|
9
|
+
export declare function SwiplEye(options?: Partial<EmscriptenModule> | undefined): Promise<SWIPLModule>;
|
|
32
10
|
/**
|
|
33
11
|
* Execute a query over a given data file
|
|
34
12
|
* @param Module A SWIPL Module
|
|
@@ -37,28 +15,17 @@ export declare function loadEye(Module: SWIPLModule): SWIPLModule;
|
|
|
37
15
|
* @returns The same SWIPL module
|
|
38
16
|
*/
|
|
39
17
|
export declare function runQuery(Module: SWIPLModule, data: string, queryString: string): SWIPLModule;
|
|
40
|
-
/**
|
|
41
|
-
* @param Module A SWIPL Module
|
|
42
|
-
* @param data The data as N3
|
|
43
|
-
* @param queryString The query as N3
|
|
44
|
-
* @returns
|
|
45
|
-
* @deprecated
|
|
46
|
-
*/
|
|
47
|
-
export declare function loadAndRunQuery(Module: SWIPLModule, data: string, queryString: string): SWIPLModule;
|
|
48
18
|
/**
|
|
49
19
|
* @param swipl The base SWIPL module to use
|
|
50
20
|
* @param data The data for the query (in N3 format)
|
|
51
21
|
* @param queryString The query (in N3 format)
|
|
52
22
|
* @returns The result of the query
|
|
53
23
|
*/
|
|
54
|
-
export declare function executeBasicEyeQuery(swipl: typeof
|
|
24
|
+
export declare function executeBasicEyeQuery(swipl: typeof SWIPL_TYPE, data: string, queryString: string): Promise<string>;
|
|
55
25
|
/**
|
|
56
26
|
* @param swipl The base SWIPL module to use
|
|
57
27
|
* @param data The data for the query (in N3 format)
|
|
58
28
|
* @param queryString The query (in N3 format)
|
|
59
29
|
* @returns The result of the query
|
|
60
30
|
*/
|
|
61
|
-
export declare function executeBasicEyeQueryQuads(swipl: typeof
|
|
62
|
-
result: Quad[];
|
|
63
|
-
proof: Quad[];
|
|
64
|
-
}>;
|
|
31
|
+
export declare function executeBasicEyeQueryQuads(swipl: typeof SWIPL_TYPE, data: Quad[], queryString: Quad[]): Promise<Quad[]>;
|
package/dist/transformers.js
CHANGED
|
@@ -1,30 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.executeBasicEyeQueryQuads = exports.executeBasicEyeQuery = exports.
|
|
6
|
+
exports.executeBasicEyeQueryQuads = exports.executeBasicEyeQuery = exports.runQuery = exports.SwiplEye = exports.loadEyeImage = void 0;
|
|
16
7
|
const n3_1 = require("n3");
|
|
17
8
|
// @ts-ignore
|
|
18
9
|
const swipl_bundled_temp_1 = __importDefault(require("./swipl-bundled.temp"));
|
|
19
10
|
const n3Writer_temp_1 = require("./n3Writer.temp");
|
|
20
|
-
const
|
|
21
|
-
const eye_pvm_1 = __importDefault(require("./eye.pvm"));
|
|
11
|
+
const eye_1 = __importDefault(require("./eye"));
|
|
22
12
|
const query_1 = require("./query");
|
|
23
13
|
const strToBuffer_1 = require("./strToBuffer");
|
|
24
14
|
function loadEyeImage(swipl) {
|
|
25
|
-
return (options) => swipl(
|
|
15
|
+
return (options) => swipl({
|
|
16
|
+
...options,
|
|
17
|
+
arguments: ['-q', '-x', 'eye.pvm'],
|
|
26
18
|
// @ts-ignore
|
|
27
|
-
preRun: (module) => module.FS.writeFile('eye.pvm', (0, strToBuffer_1.strToBuffer)(
|
|
19
|
+
preRun: (module) => module.FS.writeFile('eye.pvm', (0, strToBuffer_1.strToBuffer)(eye_1.default)),
|
|
20
|
+
});
|
|
28
21
|
}
|
|
29
22
|
exports.loadEyeImage = loadEyeImage;
|
|
30
23
|
/**
|
|
@@ -34,39 +27,6 @@ function SwiplEye(options) {
|
|
|
34
27
|
return loadEyeImage(swipl_bundled_temp_1.default)(options);
|
|
35
28
|
}
|
|
36
29
|
exports.SwiplEye = SwiplEye;
|
|
37
|
-
/**
|
|
38
|
-
* Writes eye.pl to the Module
|
|
39
|
-
* @param Module A SWIPL Module
|
|
40
|
-
* @returns A SWIPL Module
|
|
41
|
-
* @deprecated
|
|
42
|
-
*/
|
|
43
|
-
function writeEye(Module) {
|
|
44
|
-
Module.FS.writeFile('eye.pl', eye_pl_1.default);
|
|
45
|
-
return Module;
|
|
46
|
-
}
|
|
47
|
-
exports.writeEye = writeEye;
|
|
48
|
-
/**
|
|
49
|
-
* Consults the eye.pl Module
|
|
50
|
-
* @param Module A SWIPL Module
|
|
51
|
-
* @returns A SWIPL Module
|
|
52
|
-
* @deprecated
|
|
53
|
-
*/
|
|
54
|
-
function consultEye(Module) {
|
|
55
|
-
(0, query_1.queryOnce)(Module, 'consult', 'eye.pl');
|
|
56
|
-
return Module;
|
|
57
|
-
}
|
|
58
|
-
exports.consultEye = consultEye;
|
|
59
|
-
/**
|
|
60
|
-
* A SWIPL transformer that loads and consults eye.pl in the
|
|
61
|
-
* given SWIPL module
|
|
62
|
-
* @param Module A SWIPL Module
|
|
63
|
-
* @returns The same SWIPL module with EYE loaded and consulted
|
|
64
|
-
* @deprecated
|
|
65
|
-
*/
|
|
66
|
-
function loadEye(Module) {
|
|
67
|
-
return consultEye(writeEye(Module));
|
|
68
|
-
}
|
|
69
|
-
exports.loadEye = loadEye;
|
|
70
30
|
/**
|
|
71
31
|
* Execute a query over a given data file
|
|
72
32
|
* @param Module A SWIPL Module
|
|
@@ -77,34 +37,21 @@ exports.loadEye = loadEye;
|
|
|
77
37
|
function runQuery(Module, data, queryString) {
|
|
78
38
|
Module.FS.writeFile('data.nq', data);
|
|
79
39
|
Module.FS.writeFile('query.nq', queryString);
|
|
80
|
-
(0, query_1.queryOnce)(Module, 'main', ['--quiet', './data.nq', '--query', './query.nq']);
|
|
40
|
+
(0, query_1.queryOnce)(Module, 'main', ['--nope', '--quiet', './data.nq', '--query', './query.nq']);
|
|
81
41
|
return Module;
|
|
82
42
|
}
|
|
83
43
|
exports.runQuery = runQuery;
|
|
84
|
-
/**
|
|
85
|
-
* @param Module A SWIPL Module
|
|
86
|
-
* @param data The data as N3
|
|
87
|
-
* @param queryString The query as N3
|
|
88
|
-
* @returns
|
|
89
|
-
* @deprecated
|
|
90
|
-
*/
|
|
91
|
-
function loadAndRunQuery(Module, data, queryString) {
|
|
92
|
-
return runQuery(loadEye(Module), data, queryString);
|
|
93
|
-
}
|
|
94
|
-
exports.loadAndRunQuery = loadAndRunQuery;
|
|
95
44
|
/**
|
|
96
45
|
* @param swipl The base SWIPL module to use
|
|
97
46
|
* @param data The data for the query (in N3 format)
|
|
98
47
|
* @param queryString The query (in N3 format)
|
|
99
48
|
* @returns The result of the query
|
|
100
49
|
*/
|
|
101
|
-
function executeBasicEyeQuery(swipl, data, queryString) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return res;
|
|
107
|
-
});
|
|
50
|
+
async function executeBasicEyeQuery(swipl, data, queryString) {
|
|
51
|
+
let res = '';
|
|
52
|
+
const Module = await loadEyeImage(swipl)({ print: (str) => { res += `${str}\n`; }, arguments: ['-q'] });
|
|
53
|
+
runQuery(Module, data, queryString);
|
|
54
|
+
return res;
|
|
108
55
|
}
|
|
109
56
|
exports.executeBasicEyeQuery = executeBasicEyeQuery;
|
|
110
57
|
/**
|
|
@@ -113,26 +60,9 @@ exports.executeBasicEyeQuery = executeBasicEyeQuery;
|
|
|
113
60
|
* @param queryString The query (in N3 format)
|
|
114
61
|
* @returns The result of the query
|
|
115
62
|
*/
|
|
116
|
-
function executeBasicEyeQueryQuads(swipl, data, queryString) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const proof = parser.parse(queryResult);
|
|
121
|
-
const store = new n3_1.Store(proof);
|
|
122
|
-
const proofNode = store.getSubjects('http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://www.w3.org/2000/10/swap/reason#Proof', n3_1.DataFactory.defaultGraph());
|
|
123
|
-
if (proofNode.length !== 1) {
|
|
124
|
-
throw new Error(`Expected exactly one proof: received ${proofNode.length}`);
|
|
125
|
-
}
|
|
126
|
-
const results = store.getObjects(proofNode[0], 'http://www.w3.org/2000/10/swap/reason#gives', n3_1.DataFactory.defaultGraph());
|
|
127
|
-
if (results.length !== 1) {
|
|
128
|
-
throw new Error(`Expected exactly one triple giving inference results from proof: received ${results.length}`);
|
|
129
|
-
}
|
|
130
|
-
const result = store.getQuads(null, null, null, results[0])
|
|
131
|
-
.map((res) => n3_1.DataFactory.quad(res.subject, res.predicate, res.object));
|
|
132
|
-
return {
|
|
133
|
-
proof,
|
|
134
|
-
result,
|
|
135
|
-
};
|
|
136
|
-
});
|
|
63
|
+
async function executeBasicEyeQueryQuads(swipl, data, queryString) {
|
|
64
|
+
const parser = new n3_1.Parser({ format: 'text/n3' });
|
|
65
|
+
const queryResult = await executeBasicEyeQuery(swipl, (0, n3Writer_temp_1.write)(data), (0, n3Writer_temp_1.write)(queryString));
|
|
66
|
+
return parser.parse(queryResult);
|
|
137
67
|
}
|
|
138
68
|
exports.executeBasicEyeQueryQuads = executeBasicEyeQueryQuads;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyereasoner",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Distributing the [EYE](https://github.com/josd/eye) reasoner for browser and node using WebAssembly.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.js",
|
|
@@ -19,14 +19,11 @@
|
|
|
19
19
|
"build": "npm run eye:prepare && tsc",
|
|
20
20
|
"prepare": "npm run build",
|
|
21
21
|
"semantic-release": "semantic-release",
|
|
22
|
-
"eye:fetch": "ts-node scripts/fetch-eye",
|
|
23
22
|
"eye:pvm": "ts-node scripts/generate-pvm",
|
|
24
23
|
"eye:pvm:test": "ts-node scripts/run-pvm",
|
|
25
|
-
"eye:
|
|
26
|
-
"eye:build:pvm": "rollup --config rollup.config.pvm.mjs",
|
|
27
|
-
"eye:prepare": "npm run eye:fetch && npm run eye:build:pl && npm run eye:pvm && npm run eye:build:pvm",
|
|
24
|
+
"eye:prepare": "npm run eye:pvm",
|
|
28
25
|
"eye:update": "ts-node scripts/update",
|
|
29
|
-
"perf": "ts-node perf/socrates
|
|
26
|
+
"perf": "ts-node perf/socrates"
|
|
30
27
|
},
|
|
31
28
|
"repository": {
|
|
32
29
|
"type": "git",
|
|
@@ -67,9 +64,6 @@
|
|
|
67
64
|
"jest-environment-jsdom": "^29.3.1",
|
|
68
65
|
"jest-rdf": "^1.8.0",
|
|
69
66
|
"pre-commit": "^1.2.2",
|
|
70
|
-
"rollup": "^3.9.1",
|
|
71
|
-
"rollup-plugin-string": "^3.0.0",
|
|
72
|
-
"rollup-plugin-typescript2": "^0.34.1",
|
|
73
67
|
"semantic-release": "^20.0.1",
|
|
74
68
|
"ts-jest": "^29.0.3",
|
|
75
69
|
"ts-node": "^10.9.1",
|
|
@@ -109,6 +103,10 @@
|
|
|
109
103
|
"swipl-wasm": "^3.0.0"
|
|
110
104
|
},
|
|
111
105
|
"peerDependencies": {
|
|
112
|
-
"@rdfjs/types": "^1.1.0"
|
|
106
|
+
"@rdfjs/types": "^1.1.0",
|
|
107
|
+
"@types/emscripten": "^1.39.6"
|
|
108
|
+
},
|
|
109
|
+
"bin": {
|
|
110
|
+
"eyereasoner": "dist/bin/index.js"
|
|
113
111
|
}
|
|
114
112
|
}
|
package/dist/eye.pl.d.ts
DELETED