eyemind 0.9.14 → 0.9.16
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/LE-SPEC.md +17 -7
- package/LS-SPEC.md +1 -1
- package/package.json +1 -1
- package/src/arith.js +1 -5
- package/src/builtins.js +1 -1
- package/src/chains.js +1 -1
- package/src/cli.js +1 -3
- package/src/closure.js +1 -1
- package/src/common.js +1 -1
- package/src/engine.js +10 -6
- package/src/n3-documents.js +1 -1
- package/src/n3-parser.js +2 -2
- package/src/n3-writer.js +1 -1
- package/src/n3.js +4 -8
- package/src/odrl.js +1 -1
- package/src/owl2rl.js +0 -1
- package/src/program.js +1 -1
- package/src/proof.js +1 -1
- package/src/qudt.js +0 -1
- package/src/rdf-lexer.js +1 -1
- package/src/rdf-logic.js +2 -2
- package/src/rdf-prelude.js +1 -64
- package/src/reader.js +1 -1
- package/src/shacl-expr.js +2 -2
- package/src/shacl.js +1 -1
- package/src/srl-analyze.js +2 -67
- package/src/srl-assignments.js +1 -1
- package/src/srl-builtin-names.js +1 -5
- package/src/srl-parser.js +1 -15
- package/src/srl-term.js +1 -133
- package/src/srl.js +2 -6
- package/src/terms.js +0 -13
- package/src/version.js +1 -1
- package/src/writer.js +6 -6
package/LE-SPEC.md
CHANGED
|
@@ -183,17 +183,27 @@ indentation of that line, and a line break without a connective joins the lines
|
|
|
183
183
|
with `and` where both lines are conditions. eyemind reads the connectives as
|
|
184
184
|
LE's indentation does: the conditions are split at the least indented
|
|
185
185
|
connectives, joined from the top down, and each part is read in the same way.
|
|
186
|
-
So a deeper indentation binds tighter
|
|
186
|
+
So a deeper indentation binds tighter. These two rules differ only in the
|
|
187
|
+
indentation of `and`. With every connective at one indentation, this rule
|
|
188
|
+
means *(resident or citizen) and adult*:
|
|
187
189
|
|
|
188
190
|
```text
|
|
189
|
-
a person is eligible
|
|
190
|
-
if the person is a resident
|
|
191
|
-
or the person is a citizen
|
|
192
|
-
and the person is an adult.
|
|
191
|
+
a person is eligible
|
|
192
|
+
if the person is a resident
|
|
193
|
+
or the person is a citizen
|
|
194
|
+
and the person is an adult.
|
|
193
195
|
```
|
|
194
196
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
+
With `and` indented deeper, this one means *resident or (citizen and adult)*:
|
|
198
|
+
|
|
199
|
+
```text
|
|
200
|
+
a person is eligible
|
|
201
|
+
if the person is a resident
|
|
202
|
+
or the person is a citizen
|
|
203
|
+
and the person is an adult.
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
LE1 rejects different connectives at one indentation;
|
|
197
207
|
eyemind reads them from the top down, as LE2 does. A body may start with `and`
|
|
198
208
|
after `if`, as some LE1 programs write it.
|
|
199
209
|
|
package/LS-SPEC.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyemind",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.16",
|
|
4
4
|
"description": "A dependency-free Logic Script (LS) reasoner with forward and backward reasoning, checkable proofs, and RDF 1.2, Notation3 (N3), SPARQL 1.2 RL (SRL) and Logical English (LE) interoperability.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/arith.js
CHANGED
|
@@ -10,7 +10,7 @@ import { EyemindError, Var, compareNumbers, deref } from './terms.js';
|
|
|
10
10
|
|
|
11
11
|
// A power or shift whose result would need more bits than this is refused
|
|
12
12
|
// rather than allowed to exhaust memory.
|
|
13
|
-
|
|
13
|
+
const MAX_POWER_BITS = 1n << 26n;
|
|
14
14
|
|
|
15
15
|
class Problem extends Error {}
|
|
16
16
|
|
|
@@ -419,7 +419,3 @@ export function apply(name, values) {
|
|
|
419
419
|
export function compare(left, right, env) {
|
|
420
420
|
return compareNumbers(evaluate(left, env), evaluate(right, env));
|
|
421
421
|
}
|
|
422
|
-
|
|
423
|
-
export const ARITHMETIC_NAMES = new Set([
|
|
424
|
-
...Object.keys(BINARY), ...Object.keys(UNARY), ...Object.keys(FUNCTIONS),
|
|
425
|
-
]);
|
package/src/builtins.js
CHANGED
|
@@ -312,7 +312,7 @@ function* regexFind(args, resolved, env, mark) {
|
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
-
|
|
315
|
+
const RELATIONS = new Map([['atom_concat/3', atomConcat], ['regex_find/3', regexFind]]);
|
|
316
316
|
|
|
317
317
|
// Tests that a later binding can make false: is_var(X) holds while X is
|
|
318
318
|
// unbound, not_identical(X, a) until X is a, and compare orders a variable
|
package/src/chains.js
CHANGED
|
@@ -17,7 +17,7 @@ import { Env, Struct, Var, copyResolved, flattenConjunction, freshTerm, identity
|
|
|
17
17
|
|
|
18
18
|
// The analysis stops, rejecting the program, beyond these many chain states,
|
|
19
19
|
// or closure facts for one state.
|
|
20
|
-
|
|
20
|
+
const CHAIN_LIMITS = { states: 4096, facts: 2048 };
|
|
21
21
|
|
|
22
22
|
// Ranks for the forward clauses of a program classic stratification
|
|
23
23
|
// rejects, or null when the program is not chain-stratified, as far as this
|
package/src/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The eyemind command line.
|
|
2
|
-
import { run, unusedClauses } from './engine.js';
|
|
2
|
+
import { COMPILED_LIMITS, run, unusedClauses } from './engine.js';
|
|
3
3
|
import { OUTPUT_FORMATS, RDF_PROFILES, defaultFormat, inputKind, loadInputs, loadMessageReasoner, rdfMessageFormat, scopeOf, writeConclusions } from './formats.js';
|
|
4
4
|
import { explainLe } from './le-explain.js';
|
|
5
5
|
import { isRdfMessageLog, replayMessages, RdfMessageReader } from './messages.js';
|
|
@@ -52,8 +52,6 @@ Exit codes: 0 success, 1 error, 2 invalid proof, 65 contradiction.
|
|
|
52
52
|
|
|
53
53
|
const LIMITS = { '--max-depth': 'maxDepth', '--max-iterations': 'maxIterations', '--max-inferences': 'maxInferences' };
|
|
54
54
|
const ALIASES = new Map([['-p', '--proof'], ['-c', '--prove-and-check'], ['-v', '--version'], ['-h', '--help']]);
|
|
55
|
-
// N3 and SPARQL 1.2 RL programs run longer than eyemind's defaults allow.
|
|
56
|
-
const COMPILED_LIMITS = { maxDepth: 1000000, maxIterations: 100000, maxInferences: 1000000000 };
|
|
57
55
|
|
|
58
56
|
const RDF_FORMATS = ['turtle', 'trig', 'n-triples', 'n-quads'];
|
|
59
57
|
|
package/src/closure.js
CHANGED
|
@@ -63,7 +63,7 @@ export function plainGenerators(program, clause) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// The name and arity of every relation a forward rule concludes.
|
|
66
|
-
|
|
66
|
+
function forwardKeys(program) {
|
|
67
67
|
const keys = new Set();
|
|
68
68
|
for (const clause of program.forward) {
|
|
69
69
|
for (const head of clause.plainHeads) {
|
package/src/common.js
CHANGED
|
@@ -249,7 +249,7 @@ export function sameValue(a, b) {
|
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
// Whether term, read through env, is exactly target, variables included.
|
|
252
|
-
|
|
252
|
+
function resolvesTo(term, env, target) {
|
|
253
253
|
const pending = [term, target];
|
|
254
254
|
while (pending.length) {
|
|
255
255
|
const expected = pending.pop();
|
package/src/engine.js
CHANGED
|
@@ -14,10 +14,14 @@ import {
|
|
|
14
14
|
} from './terms.js';
|
|
15
15
|
import { Lettering, SourceNaming, write } from './writer.js';
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const BUILTIN = 'builtin';
|
|
18
|
+
const CONTROL = 'control';
|
|
19
|
+
const ABSENT = 'absent';
|
|
20
|
+
const COLLECTED = 'collected';
|
|
21
|
+
|
|
22
|
+
// Programs compiled from RDF, N3 and SPARQL 1.2 RL run longer than eyemind's
|
|
23
|
+
// defaults allow.
|
|
24
|
+
export const COMPILED_LIMITS = { maxDepth: 1000000, maxIterations: 100000, maxInferences: 1000000000 };
|
|
21
25
|
|
|
22
26
|
// One proof step: a goal, how it was justified, and the steps it used.
|
|
23
27
|
export class Node {
|
|
@@ -183,7 +187,7 @@ function unboundNegation(goal, env) {
|
|
|
183
187
|
// as the search that produced it. A derived fact's node is already final and
|
|
184
188
|
// is shared rather than copied, which keeps a long forward chain from being
|
|
185
189
|
// copied again at every step.
|
|
186
|
-
|
|
190
|
+
function resolveNode(node, env) {
|
|
187
191
|
if (node.final) return node;
|
|
188
192
|
const root = resolveOne(node, env);
|
|
189
193
|
const pending = [[node, root]];
|
|
@@ -1285,7 +1289,7 @@ export class Solver {
|
|
|
1285
1289
|
// variable and the values the solution gave the heads' other variables. The
|
|
1286
1290
|
// same firing thus always gives the same terms, and a different one
|
|
1287
1291
|
// different terms.
|
|
1288
|
-
|
|
1292
|
+
function skolemTerms(clause, head, unresolved, env, context = null) {
|
|
1289
1293
|
const values = context === null ? [] : [context];
|
|
1290
1294
|
for (const variable of variables(head).values()) {
|
|
1291
1295
|
const value = copyResolved(variable, env);
|
package/src/n3-documents.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// The host supplies file access and, optionally, HTTP document access.
|
|
8
8
|
import { LOG } from './n3-parser.js';
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const DOCUMENT_PREDICATES = new Set([`${LOG}semantics`, `${LOG}semanticsOrError`, `${LOG}content`]);
|
|
11
11
|
|
|
12
12
|
// The IRIs a document's triples name as documents to read: the subject of
|
|
13
13
|
// such a built-in, and, when a rule finds that subject with a pattern whose
|
package/src/n3-parser.js
CHANGED
|
@@ -204,7 +204,7 @@ function* tokens(src) {
|
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
// Resolve a relative IRI reference against a base (RFC 3986, Section 5.2).
|
|
207
|
-
|
|
207
|
+
function resolveIri(ref, base) {
|
|
208
208
|
if (!base || /^[A-Za-z][A-Za-z0-9+.-]*:/.test(ref)) return ref;
|
|
209
209
|
const m = /^([A-Za-z][A-Za-z0-9+.-]*:)(\/\/[^/?#]*)?([^?#]*)(\?[^#]*)?(#.*)?$/.exec(base);
|
|
210
210
|
if (!m) return ref;
|
|
@@ -234,7 +234,7 @@ function removeDots(path) {
|
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
// Prefixes a document may use without declaring them.
|
|
237
|
-
|
|
237
|
+
const DEFAULT_PREFIXES = {
|
|
238
238
|
rdf: RDF,
|
|
239
239
|
rdfs: 'http://www.w3.org/2000/01/rdf-schema#',
|
|
240
240
|
xsd: XSD,
|
package/src/n3-writer.js
CHANGED
|
@@ -9,7 +9,7 @@ import { Struct, Var, identity } from './terms.js';
|
|
|
9
9
|
import { write } from './writer.js';
|
|
10
10
|
import { LOG, RDF, XSD } from './n3-parser.js';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
class N3WriteError extends Error {}
|
|
13
13
|
|
|
14
14
|
// The triples of an eyemind conclusions document, in order and without
|
|
15
15
|
// duplicates. Also reports whether a contradiction halted the run.
|
package/src/n3.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// universals are qbnode(Label) and qvar(Name), and a rule's graph pattern
|
|
22
22
|
// matches it as a set, up to a one-to-one renaming of those. Built-in
|
|
23
23
|
// predicates of a body become goals defined in LS (n3-builtins.js).
|
|
24
|
-
import { run } from './engine.js';
|
|
24
|
+
import { COMPILED_LIMITS, run } from './engine.js';
|
|
25
25
|
import { loadText } from './lang.js';
|
|
26
26
|
import { Program, Source } from './program.js';
|
|
27
27
|
import { Struct, Var, conjunction, isGround } from './terms.js';
|
|
@@ -36,7 +36,7 @@ const LIST = 'http://www.w3.org/2000/10/swap/list#';
|
|
|
36
36
|
const GRAPH_CONTENT = 'https://eyereasoner.github.io/eyemind/graph#content';
|
|
37
37
|
import { BUILTINS, HELPERS, UNSUPPORTED } from './n3-builtins.js';
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
class N3CompileError extends Error {}
|
|
40
40
|
|
|
41
41
|
// A term or atom text as a JavaScript string literal.
|
|
42
42
|
const q = (text) => JSON.stringify(text);
|
|
@@ -52,7 +52,7 @@ export function compileN3(text, { base = '', source = 'input', documents } = {})
|
|
|
52
52
|
return compileN3Document(doc, { source, documents });
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
function compileN3Document(doc, { source = 'input', documents = new Map() } = {}) {
|
|
56
56
|
const facts = [];
|
|
57
57
|
const rules = [];
|
|
58
58
|
const needed = new Set();
|
|
@@ -301,7 +301,6 @@ function variablePredicate(triples) {
|
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
const isFormulaLike = (t) => t.t === 'graph' || (t.t === 'literal' && t.dt === `${XSD}boolean`);
|
|
304
|
-
const isTrue = (t) => t.t === 'literal' && t.dt === `${XSD}boolean` && t.v === 'true';
|
|
305
304
|
const isFalse = (t) => t.t === 'literal' && t.dt === `${XSD}boolean` && t.v === 'false';
|
|
306
305
|
const triplesOf = (t) => (t.t === 'graph' ? t.triples : []);
|
|
307
306
|
|
|
@@ -1136,15 +1135,12 @@ function conclusionsToN3(doc, { triples, contradiction }, { mode = 'new', string
|
|
|
1136
1135
|
return { n3: writeN3(triples, { prefixes: doc.prefixes, strings, blankNodePrefix }), triples, contradiction };
|
|
1137
1136
|
}
|
|
1138
1137
|
|
|
1139
|
-
// Generous bounds: N3 programs often run longer than eyemind's defaults.
|
|
1140
|
-
export const N3_LIMITS = { maxDepth: 1000000, maxIterations: 100000, maxInferences: 1000000000 };
|
|
1141
|
-
|
|
1142
1138
|
// Reason over N3 sources. Returns { n3, triples, contradiction, program,
|
|
1143
1139
|
// result }; with proof, result.proof is eyemind's checked proof of the
|
|
1144
1140
|
// compiled program.
|
|
1145
1141
|
export function reasonN3(sources, { base = '', mode = 'new', strings = 'auto', limits = {}, proof = false, goals = [], readFile = null, readDocument = null } = {}) {
|
|
1146
1142
|
const compiled = compileSources(sources, { base, readFile, readDocument, native: true });
|
|
1147
|
-
const result = run(compiled.nativeProgram ?? loadText(compiled.program, 'compiled.js'), { ...
|
|
1143
|
+
const result = run(compiled.nativeProgram ?? loadText(compiled.program, 'compiled.js'), { ...COMPILED_LIMITS, ...limits, proof, goals });
|
|
1148
1144
|
return { ...resultToN3(compiled.doc, result, { mode, strings }), get program() { return compiled.program; }, result };
|
|
1149
1145
|
}
|
|
1150
1146
|
|
package/src/odrl.js
CHANGED
|
@@ -11,7 +11,7 @@ import { DPV, DPV_PROPERTIES, dpvRules } from './dpv.js';
|
|
|
11
11
|
export const ODRL_EVAL = 'https://eyereasoner.github.io/eyemind/odrl#';
|
|
12
12
|
const RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
function isOdrlEvaluation(quads) {
|
|
15
15
|
return quads.some(([, predicate, object]) => predicate instanceof Struct && predicate.name === 'iri' &&
|
|
16
16
|
predicate.args[0] === `${RDF}type` && object instanceof Struct && object.name === 'iri' &&
|
|
17
17
|
object.args[0] === `${ODRL_EVAL}Evaluation`);
|
package/src/owl2rl.js
CHANGED
|
@@ -7,7 +7,6 @@ const COMMON = String.raw`
|
|
|
7
7
|
const r = (name) => iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#' + name);
|
|
8
8
|
const s = (name) => iri('http://www.w3.org/2000/01/rdf-schema#' + name);
|
|
9
9
|
const o = (name) => iri('http://www.w3.org/2002/07/owl#' + name);
|
|
10
|
-
const e = (name) => iri('https://eyereasoner.github.io/eyemind/entailment#' + name);
|
|
11
10
|
const t = (a, p, b) => rdf(a, p, b, G);
|
|
12
11
|
// RDFS class/property propagation.
|
|
13
12
|
implies([t(P, s('domain'), C), t(X, P, Y)], t(X, r('type'), C));
|
package/src/program.js
CHANGED
|
@@ -5,7 +5,7 @@ import { chainStrata } from './chains.js';
|
|
|
5
5
|
import { subgoals } from './goals.js';
|
|
6
6
|
import { hasInspection, inspectionTerm } from './inspection.js';
|
|
7
7
|
import {
|
|
8
|
-
EMPTY, Env, EyemindError, Struct, Var, conjunction,
|
|
8
|
+
EMPTY, Env, EyemindError, Struct, Var, conjunction, flattenConjunction, freshTerm, identity, indexKey, isCallable,
|
|
9
9
|
isCollection, isGround, isTerm, key, keyArity, listFromItems, unify, variables,
|
|
10
10
|
} from './terms.js';
|
|
11
11
|
import { write } from './writer.js';
|
package/src/proof.js
CHANGED
|
@@ -217,7 +217,7 @@ export function checkRendered(program, checkable, goals = null) {
|
|
|
217
217
|
// renaming of its variables (Section 6.3), since a listing may spell a
|
|
218
218
|
// pattern's variables differently from the step that derives it.
|
|
219
219
|
const patternSteps = new WeakMap();
|
|
220
|
-
|
|
220
|
+
function stepIdOf(steps, spellings, goal) {
|
|
221
221
|
const stepId = spellings.spell(goal);
|
|
222
222
|
if (steps.has(stepId) || isGround(goal)) return stepId;
|
|
223
223
|
let index = patternSteps.get(steps);
|
package/src/qudt.js
CHANGED
|
@@ -79,7 +79,6 @@ for (const [name, base, exponent, code] of [['B', 10, 1, 'B'], ['DeciB', 10, 0.1
|
|
|
79
79
|
const qudtCatalog = '\n' + definitions.join('\n') + String.raw`
|
|
80
80
|
const qu = (n) => iri('http://qudt.org/schema/qudt/' + n);
|
|
81
81
|
const qc = (n) => iri('https://eyereasoner.github.io/eyemind/qudt#' + n);
|
|
82
|
-
const quDouble = 'http://www.w3.org/2001/XMLSchema#double';
|
|
83
82
|
const quString = 'http://www.w3.org/2001/XMLSchema#string';
|
|
84
83
|
implied_by(qu_float(T, F), [rv_valid(T), srl_num(T, _, N), srl_float_value(N, F), is_float(F)]);
|
|
85
84
|
implied_by(qu_custom(U, G), ent_base(U, qu('conversionMultiplier'), _, G));
|
package/src/rdf-lexer.js
CHANGED
package/src/rdf-logic.js
CHANGED
|
@@ -16,7 +16,7 @@ import { Specializer, shape } from './specialize.js';
|
|
|
16
16
|
import { Env, EyemindError, Struct, Var, freshTerm, identity, key, unify } from './terms.js';
|
|
17
17
|
import { CONTROL_KEYS, Program } from './program.js';
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
const ENTAILMENT = 'https://eyereasoner.github.io/eyemind/entailment#';
|
|
20
20
|
export const RDF_PROFILES = ['owl2rl', 'qudt', 'skos', 'shacl'];
|
|
21
21
|
|
|
22
22
|
// wanted: rdf/4 patterns of the output contract, or null for every new triple.
|
|
@@ -191,7 +191,7 @@ const QUADS = new Set(['rdf/4', 'ent_base/4']);
|
|
|
191
191
|
// conclusion are kept; with output shapes, only rules concluding a property
|
|
192
192
|
// or class asked for, or one a kept rule reads. A relation other than a
|
|
193
193
|
// triple counts as a property of its own. Facts and backward rules stay.
|
|
194
|
-
|
|
194
|
+
function planRules(program, quads, { input = null, output = null }) {
|
|
195
195
|
const named = (t) => t instanceof Struct && t.name === 'iri' && typeof t.args[0] === 'string' ? t.args[0] : null;
|
|
196
196
|
const describe = (goals, into) => {
|
|
197
197
|
for (const goal of goals) {
|
package/src/rdf-prelude.js
CHANGED
|
@@ -14,7 +14,6 @@ const RDF_NS = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
|
|
|
14
14
|
const RDFS_NS = 'http://www.w3.org/2000/01/rdf-schema#';
|
|
15
15
|
const OWL_NS = 'http://www.w3.org/2002/07/owl#';
|
|
16
16
|
const XSD_NS = 'http://www.w3.org/2001/XMLSchema#';
|
|
17
|
-
const CRYPTO_NS = 'http://www.w3.org/2000/10/swap/crypto#';
|
|
18
17
|
const MATH_NS = 'http://www.w3.org/2000/10/swap/math#';
|
|
19
18
|
const TIME_NS = 'http://www.w3.org/2000/10/swap/time#';
|
|
20
19
|
const LIST_NS = 'http://www.w3.org/2000/10/swap/list#';
|
|
@@ -22,7 +21,6 @@ const LOG_NS = 'http://www.w3.org/2000/10/swap/log#';
|
|
|
22
21
|
const STRING_NS = 'http://www.w3.org/2000/10/swap/string#';
|
|
23
22
|
const DT_NS = 'https://eyereasoner.github.io/eyeling/datatype#';
|
|
24
23
|
const SKOLEM_NS = 'https://eyereasoner.github.io/.well-known/genid/';
|
|
25
|
-
const RDF_JSON_DT = RDF_NS + 'JSON';
|
|
26
24
|
|
|
27
25
|
// Private rule-lifting variable prefix used for blank nodes that appear in
|
|
28
26
|
// rule-body patterns. The prefix is intentionally not spellable in N3 input,
|
|
@@ -30,15 +28,6 @@ const RDF_JSON_DT = RDF_NS + 'JSON';
|
|
|
30
28
|
// ordinary names and translate them back internally.
|
|
31
29
|
const INTERNAL_BLANK_VAR_PREFIX = '\uE000eyeling_b';
|
|
32
30
|
|
|
33
|
-
function isInternalBlankVarName(name) {
|
|
34
|
-
return typeof name === 'string' && name.startsWith(INTERNAL_BLANK_VAR_PREFIX);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function internalBlankVarSuffix(name) {
|
|
38
|
-
if (!isInternalBlankVarName(name)) return '';
|
|
39
|
-
return name.slice(INTERNAL_BLANK_VAR_PREFIX.length);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
31
|
function parseUriReferenceForResolution(uri) {
|
|
43
32
|
// RFC 3986 Appendix B-style component parser, with the scheme tightened to
|
|
44
33
|
// the RFC scheme grammar. Capturing delimiter presence matters: `?` with an
|
|
@@ -265,7 +254,6 @@ function literalParts(lit) {
|
|
|
265
254
|
// equality fast-paths than repeated string key construction.
|
|
266
255
|
|
|
267
256
|
let __nextTid = 1;
|
|
268
|
-
const __tidIntern = new Map(); // legacy generic key -> number
|
|
269
257
|
const __iriTidIntern = new Map(); // IRI value -> number
|
|
270
258
|
const __blankTidIntern = new Map(); // blank label -> number
|
|
271
259
|
const __literalTidIntern = new Map(); // normalized literal lexical form -> number
|
|
@@ -283,10 +271,6 @@ function __getTidFromMap(map, key) {
|
|
|
283
271
|
return id;
|
|
284
272
|
}
|
|
285
273
|
|
|
286
|
-
function __getTid(key) {
|
|
287
|
-
return __getTidFromMap(__tidIntern, key);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
274
|
function __getIriTid(value) {
|
|
291
275
|
return __getTidFromMap(__iriTidIntern, value);
|
|
292
276
|
}
|
|
@@ -451,15 +435,6 @@ class Rule {
|
|
|
451
435
|
}
|
|
452
436
|
}
|
|
453
437
|
|
|
454
|
-
class DerivedFact {
|
|
455
|
-
constructor(fact, rule, premises, subst) {
|
|
456
|
-
this.fact = fact; // Triple
|
|
457
|
-
this.rule = rule; // Rule
|
|
458
|
-
this.premises = premises; // Triple[]
|
|
459
|
-
this.subst = subst; // { varName: Term }
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
438
|
// ===========================================================================
|
|
464
439
|
// Term interning
|
|
465
440
|
// ===========================================================================
|
|
@@ -474,7 +449,7 @@ const __literalIntern = new Map();
|
|
|
474
449
|
// eyemind: conversion produces independent eyemind terms. Keeping parser
|
|
475
450
|
// intern tables after that would retain every term in an unbounded log.
|
|
476
451
|
function clearParserCaches() {
|
|
477
|
-
for (const cache of [__literalPartsCache,
|
|
452
|
+
for (const cache of [__literalPartsCache, __iriTidIntern, __blankTidIntern,
|
|
478
453
|
__literalTidIntern, __iriIntern, __literalIntern]) cache.clear();
|
|
479
454
|
}
|
|
480
455
|
|
|
@@ -514,10 +489,6 @@ function isRdfTypePred(p) {
|
|
|
514
489
|
return p instanceof Iri && p.value === RDF_NS + 'type';
|
|
515
490
|
}
|
|
516
491
|
|
|
517
|
-
function isOwlSameAsPred(p) {
|
|
518
|
-
return p instanceof Iri && p.value === OWL_NS + 'sameAs';
|
|
519
|
-
}
|
|
520
|
-
|
|
521
492
|
function isLogImplies(p) {
|
|
522
493
|
return p instanceof Iri && p.value === LOG_NS + 'implies';
|
|
523
494
|
}
|
|
@@ -700,21 +671,6 @@ function collectVarsInTerm(t, acc) {
|
|
|
700
671
|
}
|
|
701
672
|
}
|
|
702
673
|
|
|
703
|
-
function varsInRule(rule) {
|
|
704
|
-
const acc = new Set();
|
|
705
|
-
for (const tr of rule.premise) {
|
|
706
|
-
collectVarsInTerm(tr.s, acc);
|
|
707
|
-
collectVarsInTerm(tr.p, acc);
|
|
708
|
-
collectVarsInTerm(tr.o, acc);
|
|
709
|
-
}
|
|
710
|
-
for (const tr of rule.conclusion) {
|
|
711
|
-
collectVarsInTerm(tr.s, acc);
|
|
712
|
-
collectVarsInTerm(tr.p, acc);
|
|
713
|
-
collectVarsInTerm(tr.o, acc);
|
|
714
|
-
}
|
|
715
|
-
return acc;
|
|
716
|
-
}
|
|
717
|
-
|
|
718
674
|
function collectBlankLabelsInTerm(t, acc) {
|
|
719
675
|
if (t instanceof Blank) {
|
|
720
676
|
acc.add(t.label);
|
|
@@ -769,25 +725,11 @@ function copyQuotedGraphMetadata(src, dst) {
|
|
|
769
725
|
|
|
770
726
|
export {
|
|
771
727
|
RDF_NS,
|
|
772
|
-
RDFS_NS,
|
|
773
728
|
OWL_NS,
|
|
774
|
-
XSD_NS,
|
|
775
|
-
CRYPTO_NS,
|
|
776
|
-
MATH_NS,
|
|
777
|
-
TIME_NS,
|
|
778
|
-
LIST_NS,
|
|
779
729
|
LOG_NS,
|
|
780
|
-
STRING_NS,
|
|
781
|
-
DT_NS,
|
|
782
|
-
SKOLEM_NS,
|
|
783
|
-
RDF_JSON_DT,
|
|
784
730
|
INTERNAL_BLANK_VAR_PREFIX,
|
|
785
|
-
isInternalBlankVarName,
|
|
786
|
-
internalBlankVarSuffix,
|
|
787
731
|
resolveIriRef,
|
|
788
732
|
literalParts,
|
|
789
|
-
normalizeLiteralForTid,
|
|
790
|
-
MAX_LITERAL_TID_LEN,
|
|
791
733
|
Term,
|
|
792
734
|
Iri,
|
|
793
735
|
Literal,
|
|
@@ -798,18 +740,13 @@ export {
|
|
|
798
740
|
GraphTerm,
|
|
799
741
|
Triple,
|
|
800
742
|
Rule,
|
|
801
|
-
DerivedFact,
|
|
802
743
|
internIri,
|
|
803
744
|
internLiteral,
|
|
804
745
|
clearParserCaches,
|
|
805
|
-
isRdfTypePred,
|
|
806
|
-
isOwlSameAsPred,
|
|
807
746
|
isLogImplies,
|
|
808
747
|
isLogImpliedBy,
|
|
809
748
|
isLogQuery,
|
|
810
749
|
PrefixEnv,
|
|
811
|
-
collectIrisInTerm,
|
|
812
|
-
varsInRule,
|
|
813
750
|
collectBlankLabelsInTriples,
|
|
814
751
|
annotateQuotedGraphTerm,
|
|
815
752
|
copyQuotedGraphMetadata,
|
package/src/reader.js
CHANGED
package/src/shacl-expr.js
CHANGED
|
@@ -12,7 +12,7 @@ import { DEFINITIONS } from './srl-functions.js';
|
|
|
12
12
|
const SH = 'http://www.w3.org/ns/shacl#';
|
|
13
13
|
const RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
|
|
14
14
|
const XSD = 'http://www.w3.org/2001/XMLSchema#';
|
|
15
|
-
|
|
15
|
+
const SHNEX = 'http://www.w3.org/ns/shacl-node-expr#';
|
|
16
16
|
export const SPARQL = 'http://www.w3.org/ns/sparql#';
|
|
17
17
|
const TRUE = `literal('true', datatype('${XSD}boolean'))`;
|
|
18
18
|
const FALSE = `literal('false', datatype('${XSD}boolean'))`;
|
|
@@ -48,7 +48,7 @@ const FUNCTIONS = {
|
|
|
48
48
|
// Functions that receive unbound arguments and errors themselves.
|
|
49
49
|
const UNBOUND = new Set(['bound', 'coalesce', 'if', 'logical-and', 'logical-or']);
|
|
50
50
|
// Execution functions read the captured clock and seed.
|
|
51
|
-
|
|
51
|
+
const EXECUTION = new Set(['now', 'rand', 'uuid', 'struuid', 'bnode']);
|
|
52
52
|
// Built-in named parameter functions by their key parameter.
|
|
53
53
|
const NAMED = ['var', 'pathValues', 'exists', 'if', 'distinct', 'intersection', 'concat', 'remove', 'filterShape', 'limit',
|
|
54
54
|
'offset', 'orderBy', 'flatMap', 'findFirst', 'matchAll', 'count', 'min', 'max', 'sum', 'instancesOf', 'nodesMatching', 'arg'];
|
package/src/shacl.js
CHANGED
|
@@ -29,7 +29,7 @@ const ALLOWED = new Set([...TARGETS, ...CONSTRAINTS, ...ANNOTATIONS, 'path', 'va
|
|
|
29
29
|
const SHAPE_PARAMETERS = ['node', 'not', 'qualifiedValueShape', 'property', 'memberShape', 'reifierShape', 'someValue', 'targetWhere', 'condition'];
|
|
30
30
|
const PATH_OPERATORS = ['inversePath', 'alternativePath', 'zeroOrMorePath', 'oneOrMorePath', 'zeroOrOnePath'];
|
|
31
31
|
// The default conformance-disallow set of SHACL 1.2.
|
|
32
|
-
|
|
32
|
+
const SHACL_DISALLOWS = ['Violation', 'Warning', 'Info'].map((n) => SH + n);
|
|
33
33
|
const literal = (t, datatype) => t instanceof Struct && t.name === 'literal' && t.args[1]?.name === 'datatype' && t.args[1].args[0] === datatype;
|
|
34
34
|
const BOOL = (t) => literal(t, XSD + 'boolean') && ['true', 'false', '1', '0'].includes(t.args[0]);
|
|
35
35
|
// Only the boolean true activates a constraint; the suite reads "1" as not true.
|
package/src/srl-analyze.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { compactIRI, iri, variable, termEquals } from './srl-term.js';
|
|
2
|
+
import { compactIRI, iri, variable, termEquals, termKey } from './srl-term.js';
|
|
3
3
|
import { tripleHasBlankNode, tripleHasVariableTripleTerm } from './srl-assignments.js';
|
|
4
4
|
|
|
5
5
|
function analyze(program, options = {}) {
|
|
@@ -212,7 +212,7 @@ function fixedTermIndexKey(term) {
|
|
|
212
212
|
if (term.type === 'var') return null;
|
|
213
213
|
if (term.type === 'path') return null;
|
|
214
214
|
if (term.type === 'triple' && containsVariableTerm(term)) return null;
|
|
215
|
-
return
|
|
215
|
+
return termKey(term);
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
function containsVariableTerm(term) {
|
|
@@ -226,33 +226,6 @@ function containsVariableTerm(term) {
|
|
|
226
226
|
return false;
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
function literalIndexValue(value) {
|
|
230
|
-
if (typeof value === 'bigint') return `${value.toString()}n`;
|
|
231
|
-
return JSON.stringify(value);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function termIndexKey(term) {
|
|
235
|
-
if (!term) return 'null';
|
|
236
|
-
if (term.type === 'iri') return `I:${term.value}`;
|
|
237
|
-
if (term.type === 'blank') return `B:${term.value}`;
|
|
238
|
-
if (term.type === 'literal') return `L:${literalIndexValue(term.value)}^^${term.datatype || ''}@${term.lang || ''}--${term.langDir || ''}`;
|
|
239
|
-
if (term.type === 'triple') return `T:${termIndexKey(term.s)} ${termIndexKey(term.p)} ${termIndexKey(term.o)}`;
|
|
240
|
-
return JSON.stringify(term);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function unionSets(a, b) {
|
|
244
|
-
const out = new Set();
|
|
245
|
-
if (a) for (const value of a) out.add(value);
|
|
246
|
-
if (b) for (const value of b) out.add(value);
|
|
247
|
-
return out;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function allTemplateIds(length) {
|
|
251
|
-
const out = new Set();
|
|
252
|
-
for (let i = 0; i < length; i += 1) out.add(i);
|
|
253
|
-
return out;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
229
|
function stratificationLayers(ruleCount, components, componentOf, edges) {
|
|
257
230
|
if (ruleCount === 0) return [];
|
|
258
231
|
const levels = Array(ruleCount).fill(0);
|
|
@@ -502,20 +475,6 @@ function possiblySameTerm(a, b) {
|
|
|
502
475
|
return termEquals(a, b);
|
|
503
476
|
}
|
|
504
477
|
|
|
505
|
-
function bodyPredicates(clauses, wantNegative, inNegativeContext = false) {
|
|
506
|
-
const out = [];
|
|
507
|
-
for (const clause of clauses) {
|
|
508
|
-
if ((clause.type === 'triple' || clause.type === 'path') && wantNegative === inNegativeContext) {
|
|
509
|
-
out.push(...predicateIRIs(clause.triple));
|
|
510
|
-
} else if (clause.type === 'not') {
|
|
511
|
-
out.push(...bodyPredicates(clause.body, wantNegative, true));
|
|
512
|
-
} else if (clause.type === 'group') {
|
|
513
|
-
out.push(...bodyPredicates(clause.pattern, wantNegative, inNegativeContext));
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
return out;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
478
|
function predicateIRI(triple) {
|
|
520
479
|
return triple && triple.p && triple.p.type === 'iri' ? triple.p.value : null;
|
|
521
480
|
}
|
|
@@ -636,20 +595,6 @@ function boundVariables(clauses, initialBound = new Set()) {
|
|
|
636
595
|
return vars;
|
|
637
596
|
}
|
|
638
597
|
|
|
639
|
-
function positiveVariables(clauses) {
|
|
640
|
-
const vars = new Set();
|
|
641
|
-
for (const clause of clauses) {
|
|
642
|
-
if (clause.type === 'triple' || clause.type === 'path') collectTripleVars(clause.triple, vars);
|
|
643
|
-
if ((clause.type === 'set' || clause.type === 'bind')) vars.add(clause.variable);
|
|
644
|
-
if (clause.type === 'group') {
|
|
645
|
-
for (const key of clause.keys) vars.add(key);
|
|
646
|
-
for (const aggregation of clause.aggregations) vars.add(aggregation.variable);
|
|
647
|
-
}
|
|
648
|
-
if (clause.type === 'filter') for (const v of expressionVariables(clause.expr)) vars.add(v);
|
|
649
|
-
}
|
|
650
|
-
return vars;
|
|
651
|
-
}
|
|
652
|
-
|
|
653
598
|
function bodyVariables(clauses) {
|
|
654
599
|
const vars = new Set();
|
|
655
600
|
for (const clause of clauses) {
|
|
@@ -709,14 +654,4 @@ function expressionVariables(expr, vars = new Set()) {
|
|
|
709
654
|
|
|
710
655
|
export {
|
|
711
656
|
analyze,
|
|
712
|
-
dependencyGraph,
|
|
713
|
-
stratificationLayers,
|
|
714
|
-
boundVariables,
|
|
715
|
-
positiveVariables,
|
|
716
|
-
bodyVariables,
|
|
717
|
-
collectTripleVars,
|
|
718
|
-
expressionVariables,
|
|
719
|
-
pathPredicateIRIs,
|
|
720
|
-
bodyTriplePatterns,
|
|
721
|
-
canPossiblyGenerate,
|
|
722
657
|
};
|
package/src/srl-assignments.js
CHANGED
package/src/srl-builtin-names.js
CHANGED
|
@@ -70,9 +70,5 @@ function isBuiltinName(name) {
|
|
|
70
70
|
return canonicalBuiltinName(name) !== null;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
function builtinNames() {
|
|
74
|
-
return Object.keys(BUILTIN_SIGNATURES);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
73
|
|
|
78
|
-
export { BUILTIN_SIGNATURES, canonicalBuiltinName, isBuiltinName
|
|
74
|
+
export { BUILTIN_SIGNATURES, canonicalBuiltinName, isBuiltinName };
|
package/src/srl-parser.js
CHANGED
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
RDF_REST,
|
|
14
14
|
RDF_NIL,
|
|
15
15
|
RDF_REIFIES,
|
|
16
|
-
XSD_STRING,
|
|
17
16
|
XSD_BOOLEAN,
|
|
18
17
|
XSD_INTEGER,
|
|
19
18
|
XSD_DECIMAL,
|
|
@@ -812,17 +811,4 @@ function parse(source, options = {}) {
|
|
|
812
811
|
return new Parser(source, options).parseProgram();
|
|
813
812
|
}
|
|
814
813
|
|
|
815
|
-
|
|
816
|
-
if (/^\s*(QUERY|SELECT)\b/i.test(source)) {
|
|
817
|
-
throw new Error('QUERY/SELECT concrete syntax is not part of the SPARQL-RL rule-set grammar; pass a raw body pattern instead');
|
|
818
|
-
}
|
|
819
|
-
const trimmed = String(source).trim();
|
|
820
|
-
const text = trimmed.startsWith('{') ? `RULE { } WHERE ${trimmed}` : `RULE { } WHERE { ${source} }`;
|
|
821
|
-
const program = new Parser(text, options).parseProgram();
|
|
822
|
-
if (program.rules.length !== 1 || program.data.length !== 0) {
|
|
823
|
-
throw new Error('Expected exactly one raw body pattern');
|
|
824
|
-
}
|
|
825
|
-
return { select: null, body: program.rules[0].body, prefixes: program.prefixes, baseIRI: program.baseIRI };
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
export { Parser, parse, parseQuery };
|
|
814
|
+
export { Parser, parse };
|
package/src/srl-term.js
CHANGED
|
@@ -33,10 +33,6 @@ function tripleTerm(s, p, o) {
|
|
|
33
33
|
return { type: 'triple', s, p, o };
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
function isVariable(term) {
|
|
37
|
-
return term && term.type === 'var';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
36
|
function isIRI(term) {
|
|
41
37
|
return term && term.type === 'iri';
|
|
42
38
|
}
|
|
@@ -49,10 +45,6 @@ function isLiteral(term) {
|
|
|
49
45
|
return term && term.type === 'literal';
|
|
50
46
|
}
|
|
51
47
|
|
|
52
|
-
function isTripleTerm(term) {
|
|
53
|
-
return term && term.type === 'triple';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
48
|
function termEquals(a, b) {
|
|
57
49
|
return termKey(a) === termKey(b);
|
|
58
50
|
}
|
|
@@ -62,34 +54,6 @@ function literalKeyValue(value) {
|
|
|
62
54
|
return JSON.stringify(value);
|
|
63
55
|
}
|
|
64
56
|
|
|
65
|
-
function isNumericPrimitive(value) {
|
|
66
|
-
return typeof value === 'number' || typeof value === 'bigint';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function compareNumericPrimitives(a, b) {
|
|
70
|
-
if (typeof a === 'bigint' && typeof b === 'bigint') {
|
|
71
|
-
if (a < b) return -1;
|
|
72
|
-
if (a > b) return 1;
|
|
73
|
-
return 0;
|
|
74
|
-
}
|
|
75
|
-
if (typeof a === 'bigint' && typeof b === 'number' && Number.isInteger(b) && Number.isSafeInteger(b)) {
|
|
76
|
-
const bi = BigInt(b);
|
|
77
|
-
if (a < bi) return -1;
|
|
78
|
-
if (a > bi) return 1;
|
|
79
|
-
return 0;
|
|
80
|
-
}
|
|
81
|
-
if (typeof a === 'number' && typeof b === 'bigint' && Number.isInteger(a) && Number.isSafeInteger(a)) {
|
|
82
|
-
const ai = BigInt(a);
|
|
83
|
-
if (ai < b) return -1;
|
|
84
|
-
if (ai > b) return 1;
|
|
85
|
-
return 0;
|
|
86
|
-
}
|
|
87
|
-
const diff = Number(a) - Number(b);
|
|
88
|
-
if (diff < 0) return -1;
|
|
89
|
-
if (diff > 0) return 1;
|
|
90
|
-
return 0;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
57
|
function termKey(term) {
|
|
94
58
|
if (!term) return 'null';
|
|
95
59
|
if (term.type === 'iri') return `I:${term.value}`;
|
|
@@ -100,68 +64,12 @@ function termKey(term) {
|
|
|
100
64
|
return JSON.stringify(term);
|
|
101
65
|
}
|
|
102
66
|
|
|
103
|
-
function tripleKey(triple) {
|
|
104
|
-
return `${termKey(triple.s)} ${termKey(triple.p)} ${termKey(triple.o)}`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
67
|
function cloneTerm(term) {
|
|
108
68
|
if (!term) return term;
|
|
109
69
|
if (term.type === 'triple') return tripleTerm(cloneTerm(term.s), cloneTerm(term.p), cloneTerm(term.o));
|
|
110
70
|
return { ...term };
|
|
111
71
|
}
|
|
112
72
|
|
|
113
|
-
function valueToTerm(value) {
|
|
114
|
-
if (value && typeof value === 'object' && value.type) return value;
|
|
115
|
-
return literal(value, inferDatatype(value));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function inferDatatype(value) {
|
|
119
|
-
if (typeof value === 'boolean') return XSD_BOOLEAN;
|
|
120
|
-
if (typeof value === 'bigint') return XSD_INTEGER;
|
|
121
|
-
if (typeof value === 'number' && Number.isInteger(value)) return XSD_INTEGER;
|
|
122
|
-
if (typeof value === 'number') return XSD_DECIMAL;
|
|
123
|
-
if (typeof value === 'string') return XSD_STRING;
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function termToPrimitive(term) {
|
|
128
|
-
if (!term) return undefined;
|
|
129
|
-
if (term.type === 'literal') return term.value;
|
|
130
|
-
if (term.type === 'iri') return term.value;
|
|
131
|
-
if (term.type === 'blank') return `_:${term.value}`;
|
|
132
|
-
if (term.type === 'var') return undefined;
|
|
133
|
-
if (term.type === 'triple') return term;
|
|
134
|
-
return term;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function termToString(term) {
|
|
138
|
-
const value = termToPrimitive(term);
|
|
139
|
-
if (value === undefined || value === null) return '';
|
|
140
|
-
if (value && value.type === 'triple') return formatTerm(value);
|
|
141
|
-
return String(value);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function booleanValue(value) {
|
|
145
|
-
const primitive = value && value.type ? termToPrimitive(value) : value;
|
|
146
|
-
if (primitive === undefined || primitive === null) return false;
|
|
147
|
-
if (typeof primitive === 'boolean') return primitive;
|
|
148
|
-
if (typeof primitive === 'bigint') return primitive !== 0n;
|
|
149
|
-
if (typeof primitive === 'number') return primitive !== 0 && !Number.isNaN(primitive);
|
|
150
|
-
if (typeof primitive === 'string') return primitive.length > 0 && primitive !== 'false';
|
|
151
|
-
return Boolean(primitive);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function comparePrimitives(a, b) {
|
|
155
|
-
const av = a && a.type ? termToPrimitive(a) : a;
|
|
156
|
-
const bv = b && b.type ? termToPrimitive(b) : b;
|
|
157
|
-
if (isNumericPrimitive(av) && isNumericPrimitive(bv)) return compareNumericPrimitives(av, bv);
|
|
158
|
-
const as = String(av);
|
|
159
|
-
const bs = String(bv);
|
|
160
|
-
if (as < bs) return -1;
|
|
161
|
-
if (as > bs) return 1;
|
|
162
|
-
return 0;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
73
|
function escapeString(value) {
|
|
166
74
|
return String(value)
|
|
167
75
|
.replace(/\\/g, '\\\\')
|
|
@@ -222,32 +130,8 @@ function formatTerm(term, prefixes = {}) {
|
|
|
222
130
|
return String(term.value ?? term);
|
|
223
131
|
}
|
|
224
132
|
|
|
225
|
-
function formatTriple(triple, prefixes = {}) {
|
|
226
|
-
return `${formatTerm(triple.s, prefixes)} ${formatTerm(triple.p, prefixes)} ${formatTerm(triple.o, prefixes)} .`;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// A solution mapping is keyed by variable name, and `?constructor`,
|
|
230
|
-
// `?toString` and friends are perfectly legal VARNAMEs ([123]/[126] of
|
|
231
|
-
// SPARQL 1.2 RL §7.6). A plain `{}` inherits those names from
|
|
232
|
-
// `Object.prototype`, so `binding[name]` would answer with an inherited
|
|
233
|
-
// function rather than `undefined` and a rule whose body binds such a
|
|
234
|
-
// variable would silently never fire. Every solution mapping is therefore
|
|
235
|
-
// created without a prototype, through these three helpers.
|
|
236
|
-
function emptyBinding() {
|
|
237
|
-
return Object.create(null);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function cloneBinding(binding) {
|
|
241
|
-
return Object.assign(Object.create(null), binding);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function extendBinding(binding, name, term) {
|
|
245
|
-
const out = cloneBinding(binding);
|
|
246
|
-
out[name] = term;
|
|
247
|
-
return out;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
133
|
export {
|
|
134
|
+
termKey,
|
|
251
135
|
RDF_NS,
|
|
252
136
|
RDF_TYPE,
|
|
253
137
|
RDF_FIRST,
|
|
@@ -264,25 +148,9 @@ export {
|
|
|
264
148
|
blankNode,
|
|
265
149
|
literal,
|
|
266
150
|
tripleTerm,
|
|
267
|
-
isVariable,
|
|
268
151
|
isIRI,
|
|
269
152
|
isBlank,
|
|
270
153
|
isLiteral,
|
|
271
|
-
isTripleTerm,
|
|
272
154
|
termEquals,
|
|
273
|
-
termKey,
|
|
274
|
-
tripleKey,
|
|
275
|
-
cloneTerm,
|
|
276
|
-
valueToTerm,
|
|
277
|
-
inferDatatype,
|
|
278
|
-
termToPrimitive,
|
|
279
|
-
termToString,
|
|
280
|
-
booleanValue,
|
|
281
|
-
comparePrimitives,
|
|
282
155
|
compactIRI,
|
|
283
|
-
formatTerm,
|
|
284
|
-
formatTriple,
|
|
285
|
-
emptyBinding,
|
|
286
|
-
cloneBinding,
|
|
287
|
-
extendBinding,
|
|
288
156
|
};
|
package/src/srl.js
CHANGED
|
@@ -35,7 +35,7 @@ import { analyze } from './srl-analyze.js';
|
|
|
35
35
|
import { BUILTIN_SIGNATURES, canonicalBuiltinName } from './srl-builtin-names.js';
|
|
36
36
|
import { libraryText } from './srl-functions.js';
|
|
37
37
|
import { Parser } from './srl-parser.js';
|
|
38
|
-
import { run } from './engine.js';
|
|
38
|
+
import { COMPILED_LIMITS, run } from './engine.js';
|
|
39
39
|
import { loadText, statementSources } from './lang.js';
|
|
40
40
|
import { Program, Source } from './program.js';
|
|
41
41
|
import { DEFAULT_GRAPH } from './rdf.js';
|
|
@@ -786,10 +786,6 @@ function collectClauseVars(clauses, out) {
|
|
|
786
786
|
}
|
|
787
787
|
}
|
|
788
788
|
|
|
789
|
-
|
|
790
|
-
// Generous bounds: rule sets over real data run longer than eyemind's defaults.
|
|
791
|
-
export const SRL_LIMITS = { maxDepth: 1000000, maxIterations: 100000, maxInferences: 1000000000 };
|
|
792
|
-
|
|
793
789
|
// Reason over a rule set. Options: base, filename, resolve (IMPORTS), data
|
|
794
790
|
// (the base graph as RDF quads), all (the base graph too), limits and proof.
|
|
795
791
|
// Returns { quads, program, prefixes, warnings, result }: the quads are the
|
|
@@ -797,7 +793,7 @@ export const SRL_LIMITS = { maxDepth: 1000000, maxIterations: 100000, maxInferen
|
|
|
797
793
|
// proof of the compiled program.
|
|
798
794
|
export function reasonSrl(text, { base = null, filename = '<input>', resolve = null, data = [], all = false, limits = {}, proof = false, context = null } = {}) {
|
|
799
795
|
const compiled = compileSrl(text, { base, filename, resolve, data, context });
|
|
800
|
-
const result = run(compiled.nativeProgram ?? loadText(compiled.program, 'compiled.js'), { ...
|
|
796
|
+
const result = run(compiled.nativeProgram ?? loadText(compiled.program, 'compiled.js'), { ...COMPILED_LIMITS, ...limits, proof });
|
|
801
797
|
const { prefixes, warnings, context: execution } = compiled;
|
|
802
798
|
return { quads: srlQuads(compiled, srlAnswers(result), { all }), get program() { return compiled.program; }, prefixes, warnings, result, context: execution };
|
|
803
799
|
}
|
package/src/terms.js
CHANGED
|
@@ -59,12 +59,7 @@ export class Tail {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
export const isVar = (term) => term instanceof Var;
|
|
63
|
-
export const isStruct = (term) => term instanceof Struct;
|
|
64
|
-
export const isAtom = (term) => typeof term === 'string';
|
|
65
62
|
export const isInt = (term) => typeof term === 'bigint';
|
|
66
|
-
export const isFloat = (term) => typeof term === 'number';
|
|
67
|
-
export const isNumber = (term) => typeof term === 'bigint' || typeof term === 'number';
|
|
68
63
|
export const isCallable = (term) => typeof term === 'string' || term instanceof Struct;
|
|
69
64
|
|
|
70
65
|
// 0, 1, 2 or 3: the rank of a term's kind in the standard order.
|
|
@@ -80,20 +75,12 @@ export function nonfinite(value, where = '') {
|
|
|
80
75
|
return new EyemindError(`${where}a float term must be finite, not ${value}`);
|
|
81
76
|
}
|
|
82
77
|
|
|
83
|
-
export function cons(head, tail) {
|
|
84
|
-
return new Struct('.', [head, tail]);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
78
|
export function listFromItems(items, tail = EMPTY) {
|
|
88
79
|
let result = tail;
|
|
89
80
|
for (let i = items.length - 1; i >= 0; i--) result = new Struct('.', [items[i], result]);
|
|
90
81
|
return result;
|
|
91
82
|
}
|
|
92
83
|
|
|
93
|
-
export function isCons(term) {
|
|
94
|
-
return term instanceof Struct && term.name === '.' && term.args.length === 2;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
84
|
export function properListItems(term, env) {
|
|
98
85
|
const items = [];
|
|
99
86
|
let cursor = deref(term, env);
|
package/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// The release this checkout is; ./release keeps it in step with package.json.
|
|
2
|
-
export const VERSION = '0.9.
|
|
2
|
+
export const VERSION = '0.9.16';
|
package/src/writer.js
CHANGED
|
@@ -26,18 +26,18 @@ export const CHAINED = new Set(['and', 'or']);
|
|
|
26
26
|
|
|
27
27
|
const PLAIN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
function plainName(name) {
|
|
30
30
|
return PLAIN.test(name) && !RESERVED_WORDS.has(name);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// Whether a compound with this name and arity is written name(...).
|
|
34
|
-
|
|
34
|
+
function callableName(name, arity) {
|
|
35
35
|
if (!plainName(name) || RESERVED_CALLS.has(name)) return false;
|
|
36
36
|
// and(A, B, C) reads as a chain, so a compound and/3 is struct('and', ...).
|
|
37
37
|
return !(CHAINED.has(name) && arity > 2);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
function validVariableName(name) {
|
|
41
41
|
return plainName(name) && name !== '_' && !name.startsWith('VAR_');
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -45,7 +45,7 @@ export function validVariableName(name) {
|
|
|
45
45
|
// the name a renamed-apart clause variable gets, becomes VAR_X_23_12. ASCII
|
|
46
46
|
// letters and digits stay, an underscore doubles and any other character
|
|
47
47
|
// becomes _hex_. Names already starting with the prefix are encoded too.
|
|
48
|
-
|
|
48
|
+
function encodeName(name) {
|
|
49
49
|
const out = ['VAR_'];
|
|
50
50
|
for (const ch of name) {
|
|
51
51
|
if (/^[A-Za-z0-9]$/.test(ch)) out.push(ch);
|
|
@@ -81,7 +81,7 @@ export function decodeName(text) {
|
|
|
81
81
|
return encodeName(name) === text ? name : null;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
function variableText(name) {
|
|
85
85
|
return validVariableName(name) ? name : encodeName(name);
|
|
86
86
|
}
|
|
87
87
|
|
|
@@ -132,7 +132,7 @@ export function floatText(value) {
|
|
|
132
132
|
return `${sign}${lead}e${exponent < 0 ? '-' : '+'}${magnitude}`;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
function letterName(n) {
|
|
136
136
|
return String.fromCharCode(65 + (n % 26)) + (n >= 26 ? String(Math.floor(n / 26)) : '');
|
|
137
137
|
}
|
|
138
138
|
|