eyemind 0.9.16 → 0.9.18
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/LS-SPEC.md +1 -1
- package/README.md +5 -0
- package/package.json +1 -1
- package/src/engine.js +12 -15
- package/src/le.js +33 -45
- package/src/messages.js +1 -1
- package/src/n3-writer.js +0 -4
- package/src/rdf-lexer.js +40 -645
- package/src/rdf-parser.js +47 -304
- package/src/rdf-prelude.js +0 -259
- package/src/rdf.js +4 -7
- package/src/shacl-expr.js +1 -1
- package/src/shacl.js +8 -19
- package/src/srl-analyze.js +0 -22
- package/src/srl-term.js +0 -53
- package/src/srl-tokenizer.js +16 -22
- package/src/version.js +1 -1
- package/src/rdf-rules.js +0 -106
package/src/rdf-rules.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* eyemind: RDF rule helpers
|
|
3
|
-
*
|
|
4
|
-
* Built-in rule helpers and utilities used by the engine. This is not the
|
|
5
|
-
* inference engine itself, but shared rule-related machinery.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
LOG_NS,
|
|
11
|
-
Iri,
|
|
12
|
-
Var,
|
|
13
|
-
Blank,
|
|
14
|
-
ListTerm,
|
|
15
|
-
OpenListTerm,
|
|
16
|
-
GraphTerm,
|
|
17
|
-
Triple,
|
|
18
|
-
copyQuotedGraphMetadata,
|
|
19
|
-
INTERNAL_BLANK_VAR_PREFIX,
|
|
20
|
-
} from './rdf-prelude.js';
|
|
21
|
-
|
|
22
|
-
function liftBlankRuleVars(premise, conclusion) {
|
|
23
|
-
function isLogIncludesLikePredicate(p) {
|
|
24
|
-
return p instanceof Iri && (p.value === LOG_NS + 'includes' || p.value === LOG_NS + 'notIncludes');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Map blank labels to stable rule-local variable names.
|
|
28
|
-
// This runs at rule construction time; keep it simple and allocation-light.
|
|
29
|
-
const mapping = Object.create(null);
|
|
30
|
-
let counter = 0;
|
|
31
|
-
|
|
32
|
-
// These variables are implementation details used to correlate one blank
|
|
33
|
-
// node across the lifted rule body. Their names must not be spellable by
|
|
34
|
-
// user input; otherwise a user variable such as ?_b1 can capture the
|
|
35
|
-
// lifted blank node and leak it into the rule head. The public custom
|
|
36
|
-
// builtin API maps these names back to ordinary-looking ?_bN variables.
|
|
37
|
-
function blankToVar(label) {
|
|
38
|
-
let name = mapping[label];
|
|
39
|
-
if (name === undefined) {
|
|
40
|
-
counter += 1;
|
|
41
|
-
name = `${INTERNAL_BLANK_VAR_PREFIX}${counter}`;
|
|
42
|
-
mapping[label] = name;
|
|
43
|
-
}
|
|
44
|
-
return new Var(name);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function copyQuotedTerm(t) {
|
|
48
|
-
// Quoted formulas are data terms with their own local blank scope.
|
|
49
|
-
// Copy them structurally so later in-place rewrites cannot mutate shared AST,
|
|
50
|
-
// but do not lift their blank nodes into rule-body variables.
|
|
51
|
-
if (t instanceof ListTerm) return new ListTerm(t.elems.map(copyQuotedTerm));
|
|
52
|
-
if (t instanceof OpenListTerm) return new OpenListTerm(t.prefix.map(copyQuotedTerm), t.tailVar);
|
|
53
|
-
if (t instanceof GraphTerm) {
|
|
54
|
-
const triples = t.triples.map(
|
|
55
|
-
(tr) => new Triple(copyQuotedTerm(tr.s), copyQuotedTerm(tr.p), copyQuotedTerm(tr.o)),
|
|
56
|
-
);
|
|
57
|
-
return copyQuotedGraphMetadata(t, new GraphTerm(triples));
|
|
58
|
-
}
|
|
59
|
-
return t;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function convertQuotedPatternTerm(t) {
|
|
63
|
-
if (t instanceof Blank) return blankToVar(t.label);
|
|
64
|
-
if (t instanceof ListTerm) return new ListTerm(t.elems.map(convertQuotedPatternTerm));
|
|
65
|
-
if (t instanceof OpenListTerm) return new OpenListTerm(t.prefix.map(convertQuotedPatternTerm), t.tailVar);
|
|
66
|
-
if (t instanceof GraphTerm) {
|
|
67
|
-
const triples = t.triples.map(
|
|
68
|
-
(tr) =>
|
|
69
|
-
new Triple(convertQuotedPatternTerm(tr.s), convertQuotedPatternTerm(tr.p), convertQuotedPatternTerm(tr.o)),
|
|
70
|
-
);
|
|
71
|
-
return copyQuotedGraphMetadata(t, new GraphTerm(triples));
|
|
72
|
-
}
|
|
73
|
-
return t;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function convertTerm(t, allowDirectQuotedPattern = false) {
|
|
77
|
-
if (t instanceof Blank) return blankToVar(t.label);
|
|
78
|
-
if (t instanceof ListTerm) return new ListTerm(t.elems.map((e) => convertTerm(e, false)));
|
|
79
|
-
if (t instanceof OpenListTerm)
|
|
80
|
-
return new OpenListTerm(
|
|
81
|
-
t.prefix.map((e) => convertTerm(e, false)),
|
|
82
|
-
t.tailVar,
|
|
83
|
-
);
|
|
84
|
-
if (t instanceof GraphTerm) return allowDirectQuotedPattern ? convertQuotedPatternTerm(t) : copyQuotedTerm(t);
|
|
85
|
-
return t;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const newPremise = premise.map((tr) => {
|
|
89
|
-
// In log:includes / log:notIncludes, quoted formula operands are formulas
|
|
90
|
-
// consumed by the builtin rather than ordinary triple patterns. Keep their
|
|
91
|
-
// local blank nodes as Blank terms so the builtin can treat them as local
|
|
92
|
-
// existentials, and bindings returned from an explicit scope are blank nodes
|
|
93
|
-
// instead of synthetic rule variables.
|
|
94
|
-
const keepFormulaBlanks = isLogIncludesLikePredicate(tr.p);
|
|
95
|
-
return new Triple(
|
|
96
|
-
keepFormulaBlanks && tr.s instanceof GraphTerm ? copyQuotedTerm(tr.s) : convertTerm(tr.s, true),
|
|
97
|
-
convertTerm(tr.p, true),
|
|
98
|
-
keepFormulaBlanks && tr.o instanceof GraphTerm ? copyQuotedTerm(tr.o) : convertTerm(tr.o, true),
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
return [newPremise, conclusion];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export {
|
|
105
|
-
liftBlankRuleVars,
|
|
106
|
-
};
|