eyereasoner 1.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.
@@ -0,0 +1,48 @@
1
+ import type { SWIPLModule } from 'swipl-wasm/dist/swipl/swipl';
2
+ import type SWIPL from 'swipl-wasm/dist/swipl/swipl';
3
+ import { Quad } from '@rdfjs/types';
4
+ /**
5
+ * Executes a query
6
+ * @param Module The module to execute the query on
7
+ * @param name The name of the query function
8
+ * @param args The arguments of the query function
9
+ * @returns The result of the query
10
+ */
11
+ export declare function query(Module: SWIPLModule, name: string, args: string[] | string): SWIPL.Query;
12
+ export declare function queryOnce(Module: SWIPLModule, name: string, args: string[] | string): unknown;
13
+ /**
14
+ * A SWIPL transformer that loads and consults eye.pl in the
15
+ * given SWIPL module
16
+ * @param Module A SWIPL Module
17
+ * @returns The same SWIPL module with EYE loaded and consulted
18
+ */
19
+ export declare function loadEye(Module: SWIPLModule): SWIPLModule;
20
+ /**
21
+ * Execute a query over a given data file
22
+ * @param Module A SWIPL Module
23
+ * @param data The data for the query (in Notation3)
24
+ * @param queryString The query (in Notation3)
25
+ * @returns The same SWIPL module
26
+ */
27
+ export declare function runQuery(Module: SWIPLModule, data: string, queryString: string): SWIPLModule;
28
+ /**
29
+ * @param Module A SWIPL Module
30
+ * @param data The data as N3
31
+ * @param queryString The query as N3
32
+ * @returns
33
+ */
34
+ export declare function loadAndRunQuery(Module: SWIPLModule, data: string, queryString: string): SWIPLModule;
35
+ /**
36
+ * @param swipl The base SWIPL module to use
37
+ * @param data The data for the query (in N3 format)
38
+ * @param queryString The query (in N3 format)
39
+ * @returns The result of the query
40
+ */
41
+ export declare function executeBasicEyeQuery(swipl: typeof SWIPL, data: string, queryString: string): Promise<string>;
42
+ /**
43
+ * @param swipl The base SWIPL module to use
44
+ * @param data The data for the query (in N3 format)
45
+ * @param queryString The query (in N3 format)
46
+ * @returns The result of the query
47
+ */
48
+ export declare function executeBasicEyeQueryQuads(swipl: typeof SWIPL, data: Quad[], queryString: Quad[]): Promise<Quad[]>;
@@ -0,0 +1,100 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.executeBasicEyeQueryQuads = exports.executeBasicEyeQuery = exports.loadAndRunQuery = exports.runQuery = exports.loadEye = exports.queryOnce = exports.query = void 0;
16
+ const n3_1 = require("n3");
17
+ const eye_pl_1 = __importDefault(require("./eye.pl"));
18
+ /**
19
+ * Executes a query
20
+ * @param Module The module to execute the query on
21
+ * @param name The name of the query function
22
+ * @param args The arguments of the query function
23
+ * @returns The result of the query
24
+ */
25
+ function query(Module, name, args) {
26
+ const queryString = `${name}(${typeof args === 'string'
27
+ ? `"${args}"`
28
+ : `[${args.map((arg) => `'${arg}'`).join(', ')}]`}).`;
29
+ return Module.prolog.query(queryString);
30
+ }
31
+ exports.query = query;
32
+ function queryOnce(Module, name, args) {
33
+ return query(Module, name, args).once();
34
+ }
35
+ exports.queryOnce = queryOnce;
36
+ /**
37
+ * A SWIPL transformer that loads and consults eye.pl in the
38
+ * given SWIPL module
39
+ * @param Module A SWIPL Module
40
+ * @returns The same SWIPL module with EYE loaded and consulted
41
+ */
42
+ function loadEye(Module) {
43
+ Module.FS.writeFile('eye.pl', eye_pl_1.default);
44
+ queryOnce(Module, 'consult', 'eye.pl');
45
+ return Module;
46
+ }
47
+ exports.loadEye = loadEye;
48
+ /**
49
+ * Execute a query over a given data file
50
+ * @param Module A SWIPL Module
51
+ * @param data The data for the query (in Notation3)
52
+ * @param queryString The query (in Notation3)
53
+ * @returns The same SWIPL module
54
+ */
55
+ function runQuery(Module, data, queryString) {
56
+ Module.FS.writeFile('data.n3', data);
57
+ Module.FS.writeFile('query.n3', queryString);
58
+ queryOnce(Module, 'main', ['--quiet', './data.n3', '--query', './query.n3']);
59
+ return Module;
60
+ }
61
+ exports.runQuery = runQuery;
62
+ /**
63
+ * @param Module A SWIPL Module
64
+ * @param data The data as N3
65
+ * @param queryString The query as N3
66
+ * @returns
67
+ */
68
+ function loadAndRunQuery(Module, data, queryString) {
69
+ return runQuery(loadEye(Module), data, queryString);
70
+ }
71
+ exports.loadAndRunQuery = loadAndRunQuery;
72
+ /**
73
+ * @param swipl The base SWIPL module to use
74
+ * @param data The data for the query (in N3 format)
75
+ * @param queryString The query (in N3 format)
76
+ * @returns The result of the query
77
+ */
78
+ function executeBasicEyeQuery(swipl, data, queryString) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ let res = '';
81
+ const Module = yield swipl({ print: (str) => { res += str; }, arguments: ['-q'] });
82
+ loadAndRunQuery(Module, data, queryString);
83
+ return res;
84
+ });
85
+ }
86
+ exports.executeBasicEyeQuery = executeBasicEyeQuery;
87
+ /**
88
+ * @param swipl The base SWIPL module to use
89
+ * @param data The data for the query (in N3 format)
90
+ * @param queryString The query (in N3 format)
91
+ * @returns The result of the query
92
+ */
93
+ function executeBasicEyeQueryQuads(swipl, data, queryString) {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ const parser = new n3_1.Parser();
96
+ const writer = new n3_1.Writer();
97
+ return parser.parse(yield executeBasicEyeQuery(swipl, writer.quadsToString(data), writer.quadsToString(queryString)));
98
+ });
99
+ }
100
+ exports.executeBasicEyeQueryQuads = executeBasicEyeQueryQuads;
package/package.json ADDED
@@ -0,0 +1,99 @@
1
+ {
2
+ "name": "eyereasoner",
3
+ "version": "1.0.0",
4
+ "description": "Distributing the [EYE](https://github.com/josd/eye) reasoner for browser and node using WebAssembly.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.js",
7
+ "directories": {
8
+ "lib": "lib"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "test:coverage": "npm test -- --coverage",
15
+ "test:badges": "npm run test:coverage && jest-coverage-badges",
16
+ "test": "jest",
17
+ "lint": "eslint lib/**/*.ts __tests__/* scripts/* --ext .ts",
18
+ "lint:fix": "eslint lib/**/*.ts __tests__/* scripts/* --ext .ts --fix",
19
+ "build": "tsc",
20
+ "prepare": "npm run eye:prepare && npm run build",
21
+ "semantic-release": "semantic-release",
22
+ "eye:fetch": "ts-node scripts/fetch-eye",
23
+ "eye:build": "rollup --config rollup.config.mjs",
24
+ "eye:prepare": "npm run eye:fetch && npm run eye:build",
25
+ "eye:update": "ts-node scripts/update",
26
+ "postinstall": "npm run eye:prepare"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/eyereasoner/eye-js.git"
31
+ },
32
+ "keywords": [],
33
+ "author": "Jesse Wright <https://github.com/jeswr/>",
34
+ "contributors": [
35
+ "Jesse Wright <https://github.com/jeswr/>",
36
+ "Jos De Roo <https://github.com/josd/>"
37
+ ],
38
+ "license": "MIT",
39
+ "bugs": {
40
+ "url": "https://github.com/eyereasoner/eye-js/issues"
41
+ },
42
+ "homepage": "",
43
+ "devDependencies": {
44
+ "@rollup/plugin-commonjs": "^24.0.0",
45
+ "@types/jest": "^29.2.4",
46
+ "@types/n3": "^1.10.4",
47
+ "@typescript-eslint/eslint-plugin": "^5.47.0",
48
+ "@typescript-eslint/parser": "^5.47.0",
49
+ "cross-fetch": "^3.1.5",
50
+ "eslint": "^8.30.0",
51
+ "eslint-config-airbnb-base": "^15.0.0",
52
+ "eslint-plugin-import": "^2.26.0",
53
+ "jest": "^29.3.1",
54
+ "pre-commit": "^1.2.2",
55
+ "rollup": "^3.8.1",
56
+ "rollup-plugin-string": "^3.0.0",
57
+ "rollup-plugin-typescript2": "^0.34.1",
58
+ "semantic-release": "^19.0.5",
59
+ "ts-jest": "^29.0.3",
60
+ "ts-node": "^10.9.1",
61
+ "typescript": "^4.9.4"
62
+ },
63
+ "pre-commit": [
64
+ "lint",
65
+ "build",
66
+ "test"
67
+ ],
68
+ "release": {
69
+ "branches": [
70
+ "main",
71
+ "+([0-9])?(.{+([0-9]),x}).x",
72
+ "next",
73
+ {
74
+ "name": "alpha",
75
+ "prerelease": true
76
+ },
77
+ {
78
+ "name": "beta",
79
+ "prerelease": true
80
+ }
81
+ ]
82
+ },
83
+ "publishConfig": {
84
+ "access": "public"
85
+ },
86
+ "config": {
87
+ "eye": {
88
+ "name": "v22.1224.0044",
89
+ "sha": "eb0b3f9723e54972be049a841771db1a56f0acce"
90
+ }
91
+ },
92
+ "dependencies": {
93
+ "n3": "^1.16.3",
94
+ "swipl-wasm": "^3.0.0"
95
+ },
96
+ "peerDependencies": {
97
+ "@rdfjs/types": "^1.1.0"
98
+ }
99
+ }