eyeling 1.30.6 → 1.32.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 +0 -161
- package/dist/browser/eyeling.browser.js +54 -638
- package/eyeling.js +54 -638
- package/index.d.ts +9 -49
- package/index.js +1 -2
- package/lib/cli.js +4 -11
- package/lib/engine.js +6 -14
- package/lib/lexer.js +2 -6
- package/lib/multisource.js +3 -5
- package/lib/rdfjs.js +39 -1
- package/package.json +4 -2
- package/test/examples.test.js +5 -37
- package/test/run.js +0 -1
- package/examples/input/rdf-surfaces-all-values-from-reverse.trig +0 -18
- package/examples/input/rdf-surfaces-all-values-from.trig +0 -14
- package/examples/input/rdf-surfaces-ancestor.trig +0 -21
- package/examples/input/rdf-surfaces-city.trig +0 -12
- package/examples/input/rdf-surfaces-disjunction-elimination.trig +0 -17
- package/examples/input/rdf-surfaces-disjunction-route-filter.trig +0 -12
- package/examples/input/rdf-surfaces-domain.trig +0 -12
- package/examples/input/rdf-surfaces-explicit-disjunction.trig +0 -23
- package/examples/input/rdf-surfaces-multi-premise.trig +0 -14
- package/examples/input/rdf-surfaces-owl-all-values-from-codex.trig +0 -36
- package/examples/input/rdf-surfaces-property-chain.trig +0 -14
- package/examples/input/rdf-surfaces-range.trig +0 -12
- package/examples/input/rdf-surfaces-rdf12-graph-triple-term.trig +0 -15
- package/examples/input/rdf-surfaces-rdf12-named-graph.trig +0 -14
- package/examples/input/rdf-surfaces-rdf12-triple-term.trig +0 -13
- package/examples/input/rdf-surfaces-rdfs-range-codex.trig +0 -19
- package/examples/input/rdf-surfaces-rdfs-subclass-codex.trig +0 -19
- package/examples/input/rdf-surfaces-strong-negation-access.trig +0 -15
- package/examples/output/rdf-surfaces-all-values-from-reverse.n3 +0 -3
- package/examples/output/rdf-surfaces-all-values-from.n3 +0 -3
- package/examples/output/rdf-surfaces-ancestor.n3 +0 -5
- package/examples/output/rdf-surfaces-city.n3 +0 -3
- package/examples/output/rdf-surfaces-disjunction-elimination.n3 +0 -3
- package/examples/output/rdf-surfaces-disjunction-route-filter.n3 +0 -3
- package/examples/output/rdf-surfaces-domain.n3 +0 -3
- package/examples/output/rdf-surfaces-explicit-disjunction.n3 +0 -3
- package/examples/output/rdf-surfaces-multi-premise.n3 +0 -3
- package/examples/output/rdf-surfaces-owl-all-values-from-codex.n3 +0 -6
- package/examples/output/rdf-surfaces-property-chain.n3 +0 -3
- package/examples/output/rdf-surfaces-range.n3 +0 -3
- package/examples/output/rdf-surfaces-rdf12-graph-triple-term.n3 +0 -3
- package/examples/output/rdf-surfaces-rdf12-named-graph.n3 +0 -3
- package/examples/output/rdf-surfaces-rdf12-triple-term.n3 +0 -3
- package/examples/output/rdf-surfaces-rdfs-range-codex.n3 +0 -3
- package/examples/output/rdf-surfaces-rdfs-subclass-codex.n3 +0 -3
- package/examples/output/rdf-surfaces-strong-negation-access.n3 +0 -4
- package/examples/rdf-surfaces-all-values-from-reverse.n3 +0 -6
- package/examples/rdf-surfaces-all-values-from.n3 +0 -6
- package/examples/rdf-surfaces-ancestor.n3 +0 -6
- package/examples/rdf-surfaces-city.n3 +0 -6
- package/examples/rdf-surfaces-disjunction-elimination.n3 +0 -13
- package/examples/rdf-surfaces-disjunction-route-filter.n3 +0 -24
- package/examples/rdf-surfaces-domain.n3 +0 -6
- package/examples/rdf-surfaces-explicit-disjunction.n3 +0 -16
- package/examples/rdf-surfaces-multi-premise.n3 +0 -6
- package/examples/rdf-surfaces-owl-all-values-from-codex.n3 +0 -10
- package/examples/rdf-surfaces-property-chain.n3 +0 -6
- package/examples/rdf-surfaces-range.n3 +0 -6
- package/examples/rdf-surfaces-rdf12-graph-triple-term.n3 +0 -6
- package/examples/rdf-surfaces-rdf12-named-graph.n3 +0 -6
- package/examples/rdf-surfaces-rdf12-triple-term.n3 +0 -6
- package/examples/rdf-surfaces-rdfs-range-codex.n3 +0 -6
- package/examples/rdf-surfaces-rdfs-subclass-codex.n3 +0 -6
- package/examples/rdf-surfaces-strong-negation-access.n3 +0 -20
- package/lib/rdf_surfaces.js +0 -598
- package/test/rdf_surfaces.test.js +0 -227
package/index.d.ts
CHANGED
|
@@ -1,50 +1,14 @@
|
|
|
1
1
|
declare module 'eyeling' {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface RdfJsBlankNode extends RdfJsTerm {
|
|
13
|
-
termType: 'BlankNode';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface RdfJsVariable extends RdfJsTerm {
|
|
17
|
-
termType: 'Variable';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface RdfJsDefaultGraph extends RdfJsTerm {
|
|
21
|
-
termType: 'DefaultGraph';
|
|
22
|
-
value: '';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface RdfJsLiteral extends RdfJsTerm {
|
|
26
|
-
termType: 'Literal';
|
|
27
|
-
language: string;
|
|
28
|
-
datatype: RdfJsNamedNode;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface RdfJsQuad extends RdfJsTerm {
|
|
32
|
-
termType: 'Quad';
|
|
33
|
-
value: '';
|
|
34
|
-
subject: RdfJsTerm;
|
|
35
|
-
predicate: RdfJsTerm;
|
|
36
|
-
object: RdfJsTerm;
|
|
37
|
-
graph: RdfJsTerm;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface RdfJsDataFactory {
|
|
41
|
-
namedNode(value: string): RdfJsNamedNode;
|
|
42
|
-
blankNode(value?: string): RdfJsBlankNode;
|
|
43
|
-
literal(value: string, languageOrDatatype?: string | RdfJsNamedNode): RdfJsLiteral;
|
|
2
|
+
export type RdfJsTerm = import('@rdfjs/types').Term;
|
|
3
|
+
export type RdfJsNamedNode = import('@rdfjs/types').NamedNode;
|
|
4
|
+
export type RdfJsBlankNode = import('@rdfjs/types').BlankNode;
|
|
5
|
+
export type RdfJsVariable = import('@rdfjs/types').Variable;
|
|
6
|
+
export type RdfJsDefaultGraph = import('@rdfjs/types').DefaultGraph;
|
|
7
|
+
export type RdfJsLiteral = import('@rdfjs/types').Literal;
|
|
8
|
+
export type RdfJsQuad = import('@rdfjs/types').Quad;
|
|
9
|
+
export type RdfJsDataFactory = import('@rdfjs/types').DataFactory<RdfJsQuad> & {
|
|
44
10
|
variable(value: string): RdfJsVariable;
|
|
45
|
-
|
|
46
|
-
quad(subject: RdfJsTerm, predicate: RdfJsTerm, object: RdfJsTerm, graph?: RdfJsTerm): RdfJsQuad;
|
|
47
|
-
}
|
|
11
|
+
};
|
|
48
12
|
|
|
49
13
|
export interface EyelingPrefixEnv {
|
|
50
14
|
_type?: 'PrefixEnv';
|
|
@@ -169,8 +133,6 @@ declare module 'eyeling' {
|
|
|
169
133
|
store?: string | StoreOptions;
|
|
170
134
|
storePath?: string;
|
|
171
135
|
storeClear?: boolean;
|
|
172
|
-
rdf?: boolean;
|
|
173
|
-
rdfSurfaces?: boolean;
|
|
174
136
|
}
|
|
175
137
|
|
|
176
138
|
export interface BuiltinRegistrationContext {
|
|
@@ -193,8 +155,6 @@ declare module 'eyeling' {
|
|
|
193
155
|
includeInputFactsInClosure?: boolean;
|
|
194
156
|
enforceHttps?: boolean;
|
|
195
157
|
rdfjs?: boolean;
|
|
196
|
-
rdf?: boolean;
|
|
197
|
-
rdfSurfaces?: boolean;
|
|
198
158
|
dataFactory?: RdfJsDataFactory | null;
|
|
199
159
|
skipUnsupportedRdfJs?: boolean;
|
|
200
160
|
builtinModules?: string | string[];
|
package/index.js
CHANGED
|
@@ -40,8 +40,7 @@ function reason(opt = {}, input = '') {
|
|
|
40
40
|
else args.push('--no-proof-comments');
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
if (opt.rdf
|
|
44
|
-
if (opt.rdfSurfaces) args.push('--rdf-surfaces');
|
|
43
|
+
if (opt.rdf) args.push('--rdf');
|
|
45
44
|
|
|
46
45
|
if (typeof opt.store === 'string' && opt.store) args.push('--store', opt.store);
|
|
47
46
|
else if (opt.store && typeof opt.store === 'object') {
|
package/lib/cli.js
CHANGED
|
@@ -685,7 +685,7 @@ async function ingestLineBasedRdfSourceToStore(sourceLabel, store, { rdfMode = t
|
|
|
685
685
|
}
|
|
686
686
|
|
|
687
687
|
|
|
688
|
-
async function runStreamMessagesMode(sourceLabels, { rdfMode,
|
|
688
|
+
async function runStreamMessagesMode(sourceLabels, { rdfMode, storeName = null, storePath = null, storeClear = false } = {}) {
|
|
689
689
|
const ordinarySourceLabels = [];
|
|
690
690
|
const messageSourceLabels = [];
|
|
691
691
|
|
|
@@ -723,7 +723,6 @@ async function runStreamMessagesMode(sourceLabels, { rdfMode, rdfSurfacesMode =
|
|
|
723
723
|
keepSourceArtifacts: false,
|
|
724
724
|
sourceLocations: false,
|
|
725
725
|
rdf: rdfMode,
|
|
726
|
-
rdfSurfaces: rdfSurfacesMode,
|
|
727
726
|
}),
|
|
728
727
|
);
|
|
729
728
|
} catch (e) {
|
|
@@ -757,7 +756,6 @@ async function runStreamMessagesMode(sourceLabels, { rdfMode, rdfSurfacesMode =
|
|
|
757
756
|
keepSourceArtifacts: false,
|
|
758
757
|
sourceLocations: false,
|
|
759
758
|
rdf: false,
|
|
760
|
-
rdfSurfaces: false,
|
|
761
759
|
});
|
|
762
760
|
} catch (e) {
|
|
763
761
|
if (e && e.name === 'N3SyntaxError') {
|
|
@@ -812,7 +810,6 @@ async function main() {
|
|
|
812
810
|
` -h, --help Show this help and exit.\n` +
|
|
813
811
|
` -p, --proof Enable proof explanations.\n` +
|
|
814
812
|
` -r, --rdf Enable RDF/TriG input/output compatibility.\n` +
|
|
815
|
-
` --rdf-surfaces Enable RDF Surfaces %not[...%] syntax (implies --rdf).\n` +
|
|
816
813
|
` --stream-messages Process RDF Message Logs one message at a time under -r.\n` +
|
|
817
814
|
` --store <name> Use an optional persistent fact store.\n` +
|
|
818
815
|
` --store-clear Clear the named store before this run.\n` +
|
|
@@ -888,8 +885,7 @@ async function main() {
|
|
|
888
885
|
const showAst = argv.includes('--ast') || argv.includes('-a');
|
|
889
886
|
const streamMode = argv.includes('--stream') || argv.includes('-t');
|
|
890
887
|
const streamMessagesMode = argv.includes('--stream-messages');
|
|
891
|
-
const
|
|
892
|
-
const rdfMode = argv.includes('--rdf') || argv.includes('-r') || rdfSurfacesMode;
|
|
888
|
+
const rdfMode = argv.includes('--rdf') || argv.includes('-r');
|
|
893
889
|
const storeName = argv.__storeName || null;
|
|
894
890
|
const storePath = argv.__storePath || null;
|
|
895
891
|
const storeClear = argv.includes('--store-clear');
|
|
@@ -958,7 +954,7 @@ async function main() {
|
|
|
958
954
|
}
|
|
959
955
|
|
|
960
956
|
if (streamMessagesMode) {
|
|
961
|
-
await runStreamMessagesMode(sourceLabels, { rdfMode,
|
|
957
|
+
await runStreamMessagesMode(sourceLabels, { rdfMode, storeName, storePath, storeClear });
|
|
962
958
|
return;
|
|
963
959
|
}
|
|
964
960
|
|
|
@@ -1012,7 +1008,6 @@ async function main() {
|
|
|
1012
1008
|
keepSourceArtifacts: false,
|
|
1013
1009
|
sourceLocations: false,
|
|
1014
1010
|
rdf: rdfMode,
|
|
1015
|
-
rdfSurfaces: rdfSurfacesMode,
|
|
1016
1011
|
}),
|
|
1017
1012
|
);
|
|
1018
1013
|
} catch (e) {
|
|
@@ -1025,7 +1020,7 @@ async function main() {
|
|
|
1025
1020
|
}
|
|
1026
1021
|
|
|
1027
1022
|
const mergedRuleDocument = mergeParsedDocuments(parsedRuleSources);
|
|
1028
|
-
const result = await engine.runStoreBacked(mergedRuleDocument, store, { rdf: rdfMode
|
|
1023
|
+
const result = await engine.runStoreBacked(mergedRuleDocument, store, { rdf: rdfMode });
|
|
1029
1024
|
const outTriples = result.queryMode ? result.queryTriples || [] : (result.derived || []).map((df) => df.fact);
|
|
1030
1025
|
if (result.queryMode) {
|
|
1031
1026
|
const bodyText = engine.prettyPrintQueryTriples(outTriples, result.prefixes);
|
|
@@ -1060,7 +1055,6 @@ async function main() {
|
|
|
1060
1055
|
keepSourceArtifacts: false,
|
|
1061
1056
|
sourceLocations: engine.getProofCommentsEnabled(),
|
|
1062
1057
|
rdf: rdfMode,
|
|
1063
|
-
rdfSurfaces: rdfSurfacesMode,
|
|
1064
1058
|
}),
|
|
1065
1059
|
);
|
|
1066
1060
|
} catch (e) {
|
|
@@ -1161,7 +1155,6 @@ function factsContainOutputStrings(triplesForOutput) {
|
|
|
1161
1155
|
{
|
|
1162
1156
|
proof: engine.getProofCommentsEnabled(),
|
|
1163
1157
|
rdf: rdfMode,
|
|
1164
|
-
rdfSurfaces: rdfSurfacesMode,
|
|
1165
1158
|
store: { name: storeName, clear: storeClear, path: storePath || undefined },
|
|
1166
1159
|
},
|
|
1167
1160
|
);
|
package/lib/engine.js
CHANGED
|
@@ -3623,14 +3623,12 @@ function reasonStream(input, opts = {}) {
|
|
|
3623
3623
|
skipUnsupportedRdfJs = false,
|
|
3624
3624
|
builtinModules = null,
|
|
3625
3625
|
rdf = false,
|
|
3626
|
-
rdfSurfaces = false,
|
|
3627
3626
|
sourceLabel = '<input>',
|
|
3628
3627
|
} = opts;
|
|
3629
3628
|
|
|
3630
|
-
const useRdfCompatibility = !!rdf
|
|
3631
|
-
const useRdfSurfaces = !!rdfSurfaces;
|
|
3629
|
+
const useRdfCompatibility = !!rdf;
|
|
3632
3630
|
|
|
3633
|
-
const parsedSourceList = parseN3SourceList(input, { baseIri, rdf: useRdfCompatibility,
|
|
3631
|
+
const parsedSourceList = parseN3SourceList(input, { baseIri, rdf: useRdfCompatibility, sourceLocations: proof });
|
|
3634
3632
|
const parsedTextInput = (!parsedSourceList && proof && typeof input === 'string')
|
|
3635
3633
|
? parseN3Text(input, {
|
|
3636
3634
|
baseIri: baseIri || '',
|
|
@@ -3638,7 +3636,6 @@ function reasonStream(input, opts = {}) {
|
|
|
3638
3636
|
keepSourceArtifacts: false,
|
|
3639
3637
|
sourceLocations: true,
|
|
3640
3638
|
rdf: useRdfCompatibility,
|
|
3641
|
-
rdfSurfaces: useRdfSurfaces,
|
|
3642
3639
|
})
|
|
3643
3640
|
: null;
|
|
3644
3641
|
const hasInlineN3 = input && typeof input === 'object' && !Array.isArray(input) && typeof input.n3 === 'string';
|
|
@@ -3683,7 +3680,6 @@ function reasonStream(input, opts = {}) {
|
|
|
3683
3680
|
keepSourceArtifacts: false,
|
|
3684
3681
|
sourceLocations: proof,
|
|
3685
3682
|
rdf: useRdfCompatibility,
|
|
3686
|
-
rdfSurfaces: useRdfSurfaces,
|
|
3687
3683
|
});
|
|
3688
3684
|
prefixes = directDoc.prefixes;
|
|
3689
3685
|
triples = directDoc.triples;
|
|
@@ -3795,11 +3791,10 @@ async function __parseRunAsyncInput(input, opts) {
|
|
|
3795
3791
|
baseIri = null,
|
|
3796
3792
|
proof = false,
|
|
3797
3793
|
rdf = false,
|
|
3798
|
-
rdfSurfaces = false,
|
|
3799
3794
|
sourceLabel = '<input>',
|
|
3800
3795
|
} = opts || {};
|
|
3801
3796
|
|
|
3802
|
-
const parsedSourceList = parseN3SourceList(input, { baseIri, rdf: !!rdf
|
|
3797
|
+
const parsedSourceList = parseN3SourceList(input, { baseIri, rdf: !!rdf, sourceLocations: !!proof });
|
|
3803
3798
|
if (parsedSourceList) return parsedSourceList;
|
|
3804
3799
|
|
|
3805
3800
|
const parsedObject = await normalizeParsedReasonerInputAsync(input);
|
|
@@ -3814,8 +3809,7 @@ async function __parseRunAsyncInput(input, opts) {
|
|
|
3814
3809
|
label: sourceLabel || '<input>',
|
|
3815
3810
|
keepSourceArtifacts: false,
|
|
3816
3811
|
sourceLocations: !!proof,
|
|
3817
|
-
rdf: !!rdf
|
|
3818
|
-
rdfSurfaces: !!rdfSurfaces,
|
|
3812
|
+
rdf: !!rdf,
|
|
3819
3813
|
});
|
|
3820
3814
|
}
|
|
3821
3815
|
|
|
@@ -3891,8 +3885,7 @@ async function __proveGoalsAgainstStore(goals, subst, store, backRules, localFac
|
|
|
3891
3885
|
async function runStoreBacked(input, store, opts = {}) {
|
|
3892
3886
|
const parsed = parseN3SourceList(input, {
|
|
3893
3887
|
baseIri: opts.baseIri || null,
|
|
3894
|
-
rdf: !!opts.rdf
|
|
3895
|
-
rdfSurfaces: !!opts.rdfSurfaces,
|
|
3888
|
+
rdf: !!opts.rdf,
|
|
3896
3889
|
sourceLocations: !!opts.proof,
|
|
3897
3890
|
}) || input;
|
|
3898
3891
|
|
|
@@ -4009,8 +4002,7 @@ async function runAsync(input, opts = {}) {
|
|
|
4009
4002
|
if (!storeConfig) {
|
|
4010
4003
|
const normalizedInput = parseN3SourceList(input, {
|
|
4011
4004
|
baseIri: runOpts.baseIri || null,
|
|
4012
|
-
rdf: !!runOpts.rdf
|
|
4013
|
-
rdfSurfaces: !!runOpts.rdfSurfaces,
|
|
4005
|
+
rdf: !!runOpts.rdf,
|
|
4014
4006
|
sourceLocations: !!runOpts.proof,
|
|
4015
4007
|
}) || (await normalizeReasonerInputAsync(input));
|
|
4016
4008
|
return reasonStream(normalizedInput, runOpts);
|
package/lib/lexer.js
CHANGED
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
|
-
const { normalizeRdfSurfaces } = require('./rdf_surfaces');
|
|
11
|
-
|
|
12
10
|
class Token {
|
|
13
11
|
constructor(typ, value = null, offset = null) {
|
|
14
12
|
this.typ = typ;
|
|
@@ -402,7 +400,7 @@ function normalizeRdfCompatibility(inputText) {
|
|
|
402
400
|
// unless they actually contain RDF 1.2 triple terms, VERSION directives, or a
|
|
403
401
|
// plausible top-level TriG named graph block.
|
|
404
402
|
const hasTripleTerms = text.includes('<<');
|
|
405
|
-
const hasVersionDirective = /^\s*(?:@version|VERSION)\s+(["'])(?:1\.1|1\.2|1\.2-basic
|
|
403
|
+
const hasVersionDirective = /^\s*(?:@version|VERSION)\s+(["'])(?:1\.1|1\.2|1\.2-basic)\1\s*\.?\s*(?:#.*)?$/im.test(text);
|
|
406
404
|
const hasMessageVersionDirective = /^\s*(?:@version|VERSION)\s+(["'])(?:1\.1|1\.2|1\.2-basic)-messages\1\s*\.?\s*(?:#.*)?$/im.test(text);
|
|
407
405
|
const hasNamedGraphCandidate = /(?:^|[.\r\n])\s*(?:GRAPH\s+)?(?:<[^>\r\n]*>|_:[A-Za-z][A-Za-z0-9_-]*|[A-Za-z][A-Za-z0-9_-]*:[^\s{};,.()[\]]*|:[^\s{};,.()[\]]+)\s*\{/m.test(text);
|
|
408
406
|
const hasAnnotationSyntax = /(?:^|\s)~|\{\|/.test(text);
|
|
@@ -871,7 +869,7 @@ function normalizeRdfCompatibility(inputText) {
|
|
|
871
869
|
}
|
|
872
870
|
|
|
873
871
|
function stripVersionDirectives(s) {
|
|
874
|
-
return s.replace(/^\s*(?:@version|VERSION)\s+(["'])(?:1\.1|1\.2|1\.2-basic
|
|
872
|
+
return s.replace(/^\s*(?:@version|VERSION)\s+(["'])(?:1\.1|1\.2|1\.2-basic)(?:-messages)?\1\s*\.?\s*(?:#.*)?$/gim, '');
|
|
875
873
|
}
|
|
876
874
|
|
|
877
875
|
function skipWsAndComments(s, at) {
|
|
@@ -1349,9 +1347,7 @@ function isNumericLikeIdentifier(word) {
|
|
|
1349
1347
|
|
|
1350
1348
|
function lex(inputText, opts = {}) {
|
|
1351
1349
|
const rdf = !!(opts && opts.rdf);
|
|
1352
|
-
const rdfSurfaces = !!(opts && opts.rdfSurfaces);
|
|
1353
1350
|
if (rdf) inputText = normalizeRdfCompatibility(inputText);
|
|
1354
|
-
if (rdfSurfaces) inputText = normalizeRdfSurfaces(inputText);
|
|
1355
1351
|
// Avoid copying large ASCII/BMP inputs into an Array. Array.from() is
|
|
1356
1352
|
// only needed when the text contains surrogate pairs and we want the old
|
|
1357
1353
|
// code-point iteration behavior for non-BMP characters.
|
package/lib/multisource.js
CHANGED
|
@@ -172,10 +172,9 @@ function parseN3Text(text, opts = {}) {
|
|
|
172
172
|
collectUsedPrefixes = false,
|
|
173
173
|
sourceLocations = false,
|
|
174
174
|
rdf = false,
|
|
175
|
-
rdfSurfaces = false,
|
|
176
175
|
} = opts || {};
|
|
177
176
|
|
|
178
|
-
if (rdf
|
|
177
|
+
if (rdf) {
|
|
179
178
|
const fastDoc = tryParseFastRdfText(text, { baseIri, label });
|
|
180
179
|
if (fastDoc) {
|
|
181
180
|
if (sourceLocations) annotateParsedSourceLocations(fastDoc, text, label);
|
|
@@ -184,7 +183,7 @@ function parseN3Text(text, opts = {}) {
|
|
|
184
183
|
}
|
|
185
184
|
}
|
|
186
185
|
|
|
187
|
-
const tokens = lex(text, { rdf
|
|
186
|
+
const tokens = lex(text, { rdf });
|
|
188
187
|
const parser = new Parser(tokens);
|
|
189
188
|
if (baseIri) parser.prefixes.setBase(baseIri);
|
|
190
189
|
const [prefixes, triples, frules, brules, logQueryRules] = parser.parseDocument();
|
|
@@ -383,8 +382,7 @@ function parseN3SourceList(input, opts = {}) {
|
|
|
383
382
|
collectUsedPrefixes: true,
|
|
384
383
|
keepSourceArtifacts: !!opts.keepSourceArtifacts,
|
|
385
384
|
sourceLocations: !!opts.sourceLocations,
|
|
386
|
-
rdf: !!opts.rdf
|
|
387
|
-
rdfSurfaces: !!opts.rdfSurfaces,
|
|
385
|
+
rdf: !!opts.rdf,
|
|
388
386
|
}),
|
|
389
387
|
);
|
|
390
388
|
return mergeParsedDocuments(parsed, {
|
package/lib/rdfjs.js
CHANGED
|
@@ -100,7 +100,8 @@ function termEquals(self, other) {
|
|
|
100
100
|
!!self.datatype &&
|
|
101
101
|
typeof self.datatype.equals === 'function' &&
|
|
102
102
|
self.datatype.equals(other.datatype) &&
|
|
103
|
-
self.language === (other.language || '')
|
|
103
|
+
self.language === (other.language || '') &&
|
|
104
|
+
(self.direction || '') === (other.direction || '')
|
|
104
105
|
);
|
|
105
106
|
}
|
|
106
107
|
|
|
@@ -165,6 +166,7 @@ class Literal {
|
|
|
165
166
|
this.termType = 'Literal';
|
|
166
167
|
this.value = String(value);
|
|
167
168
|
this.language = '';
|
|
169
|
+
this.direction = '';
|
|
168
170
|
this.datatype = null;
|
|
169
171
|
|
|
170
172
|
if (typeof languageOrDatatype === 'string') {
|
|
@@ -172,6 +174,10 @@ class Literal {
|
|
|
172
174
|
this.datatype = new NamedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#langString');
|
|
173
175
|
} else if (isRdfJsTerm(languageOrDatatype)) {
|
|
174
176
|
this.datatype = languageOrDatatype;
|
|
177
|
+
} else if (languageOrDatatype && typeof languageOrDatatype === 'object') {
|
|
178
|
+
this.language = String(languageOrDatatype.language || '');
|
|
179
|
+
this.direction = languageOrDatatype.direction || '';
|
|
180
|
+
this.datatype = new NamedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#langString');
|
|
175
181
|
} else {
|
|
176
182
|
this.datatype = new NamedNode(XSD_NS + 'string');
|
|
177
183
|
}
|
|
@@ -218,6 +224,38 @@ const dataFactory = {
|
|
|
218
224
|
quad(subject, predicate, object, graph) {
|
|
219
225
|
return new Quad(subject, predicate, object, graph || defaultGraphSingleton);
|
|
220
226
|
},
|
|
227
|
+
fromTerm(original) {
|
|
228
|
+
if (!isRdfJsTerm(original)) throw new TypeError('Expected an RDF/JS term');
|
|
229
|
+
|
|
230
|
+
switch (original.termType) {
|
|
231
|
+
case 'NamedNode':
|
|
232
|
+
return new NamedNode(original.value);
|
|
233
|
+
case 'BlankNode':
|
|
234
|
+
return new BlankNode(original.value);
|
|
235
|
+
case 'Literal':
|
|
236
|
+
if (original.language || original.direction) {
|
|
237
|
+
return new Literal(original.value, { language: original.language || '', direction: original.direction || '' });
|
|
238
|
+
}
|
|
239
|
+
return new Literal(original.value, original.datatype ? dataFactory.fromTerm(original.datatype) : undefined);
|
|
240
|
+
case 'Variable':
|
|
241
|
+
return new Variable(original.value);
|
|
242
|
+
case 'DefaultGraph':
|
|
243
|
+
return defaultGraphSingleton;
|
|
244
|
+
case 'Quad':
|
|
245
|
+
return dataFactory.fromQuad(original);
|
|
246
|
+
default:
|
|
247
|
+
throw new TypeError(`Unsupported RDF/JS termType ${JSON.stringify(original.termType)}`);
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
fromQuad(original) {
|
|
251
|
+
if (!isRdfJsQuad(original)) throw new TypeError('Expected an RDF/JS Quad');
|
|
252
|
+
return new Quad(
|
|
253
|
+
dataFactory.fromTerm(original.subject),
|
|
254
|
+
dataFactory.fromTerm(original.predicate),
|
|
255
|
+
dataFactory.fromTerm(original.object),
|
|
256
|
+
dataFactory.fromTerm(original.graph),
|
|
257
|
+
);
|
|
258
|
+
},
|
|
221
259
|
};
|
|
222
260
|
|
|
223
261
|
function getDataFactory(factory) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyeling",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.32.0",
|
|
4
4
|
"description": "A minimal Notation3 (N3) reasoner in JavaScript.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"build": "node tools/bundle.js",
|
|
44
44
|
"test:packlist": "node test/packlist.test.js",
|
|
45
45
|
"test:api": "node test/api.test.js",
|
|
46
|
-
"test:rdf-surfaces": "node test/rdf_surfaces.test.js",
|
|
47
46
|
"test:builtins": "node test/builtins.test.js",
|
|
48
47
|
"test:store": "node test/store.test.js",
|
|
49
48
|
"test:examples": "node test/examples.test.js",
|
|
@@ -61,6 +60,9 @@
|
|
|
61
60
|
"preversion": "npm test",
|
|
62
61
|
"postversion": "git push origin HEAD --follow-tags"
|
|
63
62
|
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"@rdfjs/types": "^2.0.1"
|
|
65
|
+
},
|
|
64
66
|
"devDependencies": {
|
|
65
67
|
"eslint": "^9.0.0",
|
|
66
68
|
"rdf-test-suite": "^2.1.4"
|
package/test/examples.test.js
CHANGED
|
@@ -152,27 +152,6 @@ function resolveExampleTrigInput(root, inputFile) {
|
|
|
152
152
|
return { abs, rel };
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
function resolveExampleRdfSurfaceInput(root, inputFile) {
|
|
156
|
-
const stem = path.basename(inputFile, path.extname(inputFile));
|
|
157
|
-
const rel = path.join('input', `${stem}.trig`);
|
|
158
|
-
const abs = path.join(root, 'examples', rel);
|
|
159
|
-
if (!fs.existsSync(abs)) return null;
|
|
160
|
-
const text = fs.readFileSync(abs, 'utf8');
|
|
161
|
-
if (!text.includes('%not[')) return null;
|
|
162
|
-
return { abs, rel };
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
function exampleOptionFlags(sourceText) {
|
|
167
|
-
const m = String(sourceText || '').match(/^[ \t]*#\s*eyeling-options:\s*(.*?)\s*$/m);
|
|
168
|
-
if (!m) return [];
|
|
169
|
-
return m[1].trim().split(/\s+/).filter(Boolean);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function addUniqueFlag(args, flag) {
|
|
173
|
-
if (!args.includes(flag)) args.push(flag);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
155
|
function resolveExampleBuiltinPath(root, inputFile) {
|
|
177
156
|
const stem = path.basename(inputFile, path.extname(inputFile));
|
|
178
157
|
const rel = path.join('examples', 'builtin', `${stem}.js`);
|
|
@@ -181,13 +160,10 @@ function resolveExampleBuiltinPath(root, inputFile) {
|
|
|
181
160
|
return { abs, rel };
|
|
182
161
|
}
|
|
183
162
|
|
|
184
|
-
function runExampleToFile({ root, examplesDir, eyelingJsPath, nodePath, file, generatedPath, proof = false
|
|
163
|
+
function runExampleToFile({ root, examplesDir, eyelingJsPath, nodePath, file, generatedPath, proof = false }) {
|
|
185
164
|
const builtin = resolveExampleBuiltinPath(root, file);
|
|
186
165
|
const trigInput = resolveExampleTrigInput(root, file);
|
|
187
|
-
const
|
|
188
|
-
const optionFlags = exampleOptionFlags(sourceText);
|
|
189
|
-
const rdfSurfacesMode = !!rdfSurfaceInput || optionFlags.includes('--rdf-surfaces');
|
|
190
|
-
const rdfMode = !!trigInput || rdfSurfacesMode || optionFlags.includes('--rdf') || optionFlags.includes('-r');
|
|
166
|
+
const rdfMode = !!trigInput;
|
|
191
167
|
const modeFlag = proof ? '-p' : '-d';
|
|
192
168
|
const outFd = fs.openSync(generatedPath, 'w');
|
|
193
169
|
|
|
@@ -195,12 +171,7 @@ function runExampleToFile({ root, examplesDir, eyelingJsPath, nodePath, file, ge
|
|
|
195
171
|
if (builtin) {
|
|
196
172
|
const args = [eyelingJsPath, modeFlag];
|
|
197
173
|
if (rdfMode) args.push('-r');
|
|
198
|
-
|
|
199
|
-
if (rdfSurfacesMode) addUniqueFlag(args, '--rdf-surfaces');
|
|
200
|
-
args.push('--builtin');
|
|
201
|
-
args.push(builtin.rel);
|
|
202
|
-
if (rdfSurfaceInput) args.push(path.join('examples', rdfSurfaceInput.rel));
|
|
203
|
-
args.push(path.join('examples', file));
|
|
174
|
+
args.push('--builtin', builtin.rel, path.join('examples', file));
|
|
204
175
|
if (trigInput) args.push(path.join('examples', trigInput.rel));
|
|
205
176
|
return cp.spawnSync(nodePath, args, {
|
|
206
177
|
cwd: root,
|
|
@@ -212,9 +183,6 @@ function runExampleToFile({ root, examplesDir, eyelingJsPath, nodePath, file, ge
|
|
|
212
183
|
|
|
213
184
|
const args = [eyelingJsPath, modeFlag];
|
|
214
185
|
if (rdfMode) args.push('-r');
|
|
215
|
-
for (const flag of optionFlags) addUniqueFlag(args, flag);
|
|
216
|
-
if (rdfSurfacesMode) addUniqueFlag(args, '--rdf-surfaces');
|
|
217
|
-
if (rdfSurfaceInput) args.push(rdfSurfaceInput.rel);
|
|
218
186
|
args.push(file);
|
|
219
187
|
if (trigInput) args.push(trigInput.rel);
|
|
220
188
|
return cp.spawnSync(nodePath, args, {
|
|
@@ -322,7 +290,7 @@ function main() {
|
|
|
322
290
|
// node eyeling.js --builtin examples/builtin/foo.js examples/foo.n3
|
|
323
291
|
// A matching examples/input/<stem>.trig sidecar is external RDF/TriG
|
|
324
292
|
// evidence for this example, so include it and run in -r mode automatically.
|
|
325
|
-
const r = runExampleToFile({ root, examplesDir, eyelingJsPath, nodePath, file, generatedPath
|
|
293
|
+
const r = runExampleToFile({ root, examplesDir, eyelingJsPath, nodePath, file, generatedPath });
|
|
326
294
|
|
|
327
295
|
const rc = r.status == null ? 1 : r.status;
|
|
328
296
|
|
|
@@ -390,7 +358,7 @@ function main() {
|
|
|
390
358
|
const expectedRc = expectedExitCode(n3Text);
|
|
391
359
|
const tmpDir = mkTmpDir();
|
|
392
360
|
const generatedPath = path.join(tmpDir, 'generated.n3');
|
|
393
|
-
const r = runExampleToFile({ root, examplesDir, eyelingJsPath, nodePath, file, generatedPath, proof: true
|
|
361
|
+
const r = runExampleToFile({ root, examplesDir, eyelingJsPath, nodePath, file, generatedPath, proof: true });
|
|
394
362
|
const rc = r.status == null ? 1 : r.status;
|
|
395
363
|
const ms = Date.now() - start;
|
|
396
364
|
|
package/test/run.js
CHANGED
|
@@ -10,7 +10,6 @@ const sections = [
|
|
|
10
10
|
['Packlist checks', 'npm', ['run', 'test:packlist']],
|
|
11
11
|
['API tests', 'npm', ['run', 'test:api']],
|
|
12
12
|
['Streaming RDF Messages tests', 'npm', ['run', 'test:stream-messages']],
|
|
13
|
-
['RDF Surfaces tests', 'npm', ['run', 'test:rdf-surfaces']],
|
|
14
13
|
['Builtin contract tests', 'npm', ['run', 'test:builtins']],
|
|
15
14
|
['Store tests', 'npm', ['run', 'test:store']],
|
|
16
15
|
['Examples tests', 'npm', ['run', 'test:examples']],
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
VERSION "1.2-surfaces"
|
|
2
|
-
# eyeling-options: --rdf-surfaces
|
|
3
|
-
@prefix ex: <http://example.org/> .
|
|
4
|
-
|
|
5
|
-
ex:box ex:contains ex:item42 .
|
|
6
|
-
ex:item42 a ex:AllowedItem .
|
|
7
|
-
|
|
8
|
-
%not[ _:x
|
|
9
|
-
%not[ _:y
|
|
10
|
-
_:x ex:contains _:y .
|
|
11
|
-
%not[
|
|
12
|
-
_:y a ex:AllowedItem .
|
|
13
|
-
%]
|
|
14
|
-
%]
|
|
15
|
-
%not[
|
|
16
|
-
_:x a ex:AllowedContainer .
|
|
17
|
-
%]
|
|
18
|
-
%]
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
VERSION "1.2-surfaces"
|
|
2
|
-
# eyeling-options: --rdf-surfaces
|
|
3
|
-
@prefix ex: <http://example.org/> .
|
|
4
|
-
|
|
5
|
-
ex:box a ex:AllowedContainer .
|
|
6
|
-
ex:box ex:contains ex:item42 .
|
|
7
|
-
|
|
8
|
-
%not[ _:x _:y
|
|
9
|
-
_:x a ex:AllowedContainer .
|
|
10
|
-
_:x ex:contains _:y .
|
|
11
|
-
%not[
|
|
12
|
-
_:y a ex:AllowedItem .
|
|
13
|
-
%]
|
|
14
|
-
%]
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
VERSION "1.2-surfaces"
|
|
2
|
-
# eyeling-options: --rdf-surfaces
|
|
3
|
-
@prefix ex: <http://example.org/> .
|
|
4
|
-
|
|
5
|
-
ex:ann ex:parent ex:bob .
|
|
6
|
-
ex:bob ex:parent ex:cat .
|
|
7
|
-
|
|
8
|
-
%not[ _:x _:y
|
|
9
|
-
_:x ex:parent _:y .
|
|
10
|
-
%not[
|
|
11
|
-
_:x ex:ancestor _:y .
|
|
12
|
-
%]
|
|
13
|
-
%]
|
|
14
|
-
|
|
15
|
-
%not[ _:x _:y _:z
|
|
16
|
-
_:x ex:parent _:y .
|
|
17
|
-
_:y ex:ancestor _:z .
|
|
18
|
-
%not[
|
|
19
|
-
_:x ex:ancestor _:z .
|
|
20
|
-
%]
|
|
21
|
-
%]
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
VERSION "1.2-surfaces"
|
|
2
|
-
# eyeling-options: --rdf-surfaces
|
|
3
|
-
@prefix ex: <http://example.org/> .
|
|
4
|
-
|
|
5
|
-
ex:caseSplit ex:option ex:ManualReview .
|
|
6
|
-
ex:caseSplit ex:option ex:AutomaticHold .
|
|
7
|
-
ex:caseSplit ex:candidateConclusion ex:NeedsHumanAttention .
|
|
8
|
-
ex:caseSplit ex:candidateConclusion ex:NoAction .
|
|
9
|
-
|
|
10
|
-
ex:ManualReview ex:implies ex:NeedsHumanAttention .
|
|
11
|
-
ex:AutomaticHold ex:implies ex:NeedsHumanAttention .
|
|
12
|
-
ex:ManualReview ex:implies ex:HasTicket .
|
|
13
|
-
|
|
14
|
-
# Strong negation: this case split must not collapse to "no action".
|
|
15
|
-
%not[
|
|
16
|
-
ex:caseSplit ex:disjunctionEntails ex:NoAction .
|
|
17
|
-
%]
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
VERSION "1.2-surfaces"
|
|
2
|
-
# eyeling-options: --rdf-surfaces
|
|
3
|
-
@prefix ex: <http://example.org/> .
|
|
4
|
-
|
|
5
|
-
ex:shipment17 a ex:ExpressShipment .
|
|
6
|
-
ex:shipment17 ex:destination ex:CityCenter .
|
|
7
|
-
|
|
8
|
-
# Strong negation: a drone route to the city center is explicitly denied.
|
|
9
|
-
%not[ _:shipment
|
|
10
|
-
_:shipment ex:route ex:Drone .
|
|
11
|
-
_:shipment ex:destination ex:CityCenter .
|
|
12
|
-
%]
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
VERSION "1.2-surfaces"
|
|
2
|
-
# eyeling-options: --rdf-surfaces
|
|
3
|
-
@prefix ex: <http://example.org/> .
|
|
4
|
-
|
|
5
|
-
ex:shipment23 a ex:ExpressShipment .
|
|
6
|
-
ex:shipment23 ex:destination ex:CityCenter .
|
|
7
|
-
|
|
8
|
-
# Explicit RDF Surfaces disjunction: an express shipment can go by rail or by drone.
|
|
9
|
-
%not[ _:shipment
|
|
10
|
-
_:shipment a ex:ExpressShipment .
|
|
11
|
-
%not[
|
|
12
|
-
_:shipment ex:possibleRoute ex:Rail .
|
|
13
|
-
%]
|
|
14
|
-
%not[
|
|
15
|
-
_:shipment ex:possibleRoute ex:Drone .
|
|
16
|
-
%]
|
|
17
|
-
%]
|
|
18
|
-
|
|
19
|
-
# Strong negation: drone delivery to the city center is ruled out.
|
|
20
|
-
%not[ _:shipment
|
|
21
|
-
_:shipment ex:destination ex:CityCenter .
|
|
22
|
-
_:shipment ex:selectedRoute ex:Drone .
|
|
23
|
-
%]
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
VERSION "1.2-surfaces"
|
|
2
|
-
# eyeling-options: --rdf-surfaces
|
|
3
|
-
@prefix ex: <http://example.org/> .
|
|
4
|
-
|
|
5
|
-
ex:case123 ex:hasSymptom ex:Fever .
|
|
6
|
-
ex:case123 ex:hasExposure ex:Travel .
|
|
7
|
-
|
|
8
|
-
%not[ _:x
|
|
9
|
-
_:x ex:hasSymptom ex:Fever .
|
|
10
|
-
_:x ex:hasExposure ex:Travel .
|
|
11
|
-
%not[
|
|
12
|
-
_:x a ex:PriorityCase .
|
|
13
|
-
%]
|
|
14
|
-
%]
|