eyeling 1.5.32 → 1.5.33
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/examples/json-pointer.n3 +2 -1
- package/examples/json-reconcile-vat.n3 +356 -0
- package/examples/output/age.n3 +2 -2
- package/examples/output/json-pointer.n3 +103 -103
- package/examples/output/json-reconcile-vat.n3 +33530 -0
- package/examples/output/math-builtins-tests.n3 +21 -20
- package/eyeling.js +36 -7
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
@prefix : <http://example.org/math-tests#> .
|
|
2
2
|
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
|
|
3
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
|
3
4
|
|
|
4
5
|
# ----------------------------------------------------------------------
|
|
5
6
|
# Proof for derived triple:
|
|
@@ -3431,16 +3432,16 @@
|
|
|
3431
3432
|
# Proof for derived triple:
|
|
3432
3433
|
# :test-rounded-1 a :MathBuiltinTest .
|
|
3433
3434
|
# It holds because the following instance of the rule body is provable:
|
|
3434
|
-
# "3.3"
|
|
3435
|
+
# "3.3"^^xsd:double math:rounded 3 .
|
|
3435
3436
|
# 3 math:equalTo 3 .
|
|
3436
3437
|
# via the schematic forward rule:
|
|
3437
3438
|
# {
|
|
3438
|
-
# "3.3"
|
|
3439
|
+
# "3.3"^^xsd:double math:rounded ?r .
|
|
3439
3440
|
# ?r math:equalTo 3 .
|
|
3440
3441
|
# } => {
|
|
3441
3442
|
# :test-rounded-1 a :MathBuiltinTest .
|
|
3442
3443
|
# :test-rounded-1 :builtin math:rounded .
|
|
3443
|
-
# :test-rounded-1 :input "3.3"
|
|
3444
|
+
# :test-rounded-1 :input "3.3"^^xsd:double .
|
|
3444
3445
|
# :test-rounded-1 :expected 3 .
|
|
3445
3446
|
# :test-rounded-1 :actual ?r .
|
|
3446
3447
|
# :test-rounded-1 :status :pass .
|
|
@@ -3456,16 +3457,16 @@
|
|
|
3456
3457
|
# Proof for derived triple:
|
|
3457
3458
|
# :test-rounded-1 :builtin math:rounded .
|
|
3458
3459
|
# It holds because the following instance of the rule body is provable:
|
|
3459
|
-
# "3.3"
|
|
3460
|
+
# "3.3"^^xsd:double math:rounded 3 .
|
|
3460
3461
|
# 3 math:equalTo 3 .
|
|
3461
3462
|
# via the schematic forward rule:
|
|
3462
3463
|
# {
|
|
3463
|
-
# "3.3"
|
|
3464
|
+
# "3.3"^^xsd:double math:rounded ?r .
|
|
3464
3465
|
# ?r math:equalTo 3 .
|
|
3465
3466
|
# } => {
|
|
3466
3467
|
# :test-rounded-1 a :MathBuiltinTest .
|
|
3467
3468
|
# :test-rounded-1 :builtin math:rounded .
|
|
3468
|
-
# :test-rounded-1 :input "3.3"
|
|
3469
|
+
# :test-rounded-1 :input "3.3"^^xsd:double .
|
|
3469
3470
|
# :test-rounded-1 :expected 3 .
|
|
3470
3471
|
# :test-rounded-1 :actual ?r .
|
|
3471
3472
|
# :test-rounded-1 :status :pass .
|
|
@@ -3479,18 +3480,18 @@
|
|
|
3479
3480
|
|
|
3480
3481
|
# ----------------------------------------------------------------------
|
|
3481
3482
|
# Proof for derived triple:
|
|
3482
|
-
# :test-rounded-1 :input "3.3"
|
|
3483
|
+
# :test-rounded-1 :input "3.3"^^xsd:double .
|
|
3483
3484
|
# It holds because the following instance of the rule body is provable:
|
|
3484
|
-
# "3.3"
|
|
3485
|
+
# "3.3"^^xsd:double math:rounded 3 .
|
|
3485
3486
|
# 3 math:equalTo 3 .
|
|
3486
3487
|
# via the schematic forward rule:
|
|
3487
3488
|
# {
|
|
3488
|
-
# "3.3"
|
|
3489
|
+
# "3.3"^^xsd:double math:rounded ?r .
|
|
3489
3490
|
# ?r math:equalTo 3 .
|
|
3490
3491
|
# } => {
|
|
3491
3492
|
# :test-rounded-1 a :MathBuiltinTest .
|
|
3492
3493
|
# :test-rounded-1 :builtin math:rounded .
|
|
3493
|
-
# :test-rounded-1 :input "3.3"
|
|
3494
|
+
# :test-rounded-1 :input "3.3"^^xsd:double .
|
|
3494
3495
|
# :test-rounded-1 :expected 3 .
|
|
3495
3496
|
# :test-rounded-1 :actual ?r .
|
|
3496
3497
|
# :test-rounded-1 :status :pass .
|
|
@@ -3500,22 +3501,22 @@
|
|
|
3500
3501
|
# Therefore the derived triple above is entailed by the rules and facts.
|
|
3501
3502
|
# ----------------------------------------------------------------------
|
|
3502
3503
|
|
|
3503
|
-
:test-rounded-1 :input "3.3"
|
|
3504
|
+
:test-rounded-1 :input "3.3"^^xsd:double .
|
|
3504
3505
|
|
|
3505
3506
|
# ----------------------------------------------------------------------
|
|
3506
3507
|
# Proof for derived triple:
|
|
3507
3508
|
# :test-rounded-1 :expected 3 .
|
|
3508
3509
|
# It holds because the following instance of the rule body is provable:
|
|
3509
|
-
# "3.3"
|
|
3510
|
+
# "3.3"^^xsd:double math:rounded 3 .
|
|
3510
3511
|
# 3 math:equalTo 3 .
|
|
3511
3512
|
# via the schematic forward rule:
|
|
3512
3513
|
# {
|
|
3513
|
-
# "3.3"
|
|
3514
|
+
# "3.3"^^xsd:double math:rounded ?r .
|
|
3514
3515
|
# ?r math:equalTo 3 .
|
|
3515
3516
|
# } => {
|
|
3516
3517
|
# :test-rounded-1 a :MathBuiltinTest .
|
|
3517
3518
|
# :test-rounded-1 :builtin math:rounded .
|
|
3518
|
-
# :test-rounded-1 :input "3.3"
|
|
3519
|
+
# :test-rounded-1 :input "3.3"^^xsd:double .
|
|
3519
3520
|
# :test-rounded-1 :expected 3 .
|
|
3520
3521
|
# :test-rounded-1 :actual ?r .
|
|
3521
3522
|
# :test-rounded-1 :status :pass .
|
|
@@ -3531,16 +3532,16 @@
|
|
|
3531
3532
|
# Proof for derived triple:
|
|
3532
3533
|
# :test-rounded-1 :actual 3 .
|
|
3533
3534
|
# It holds because the following instance of the rule body is provable:
|
|
3534
|
-
# "3.3"
|
|
3535
|
+
# "3.3"^^xsd:double math:rounded 3 .
|
|
3535
3536
|
# 3 math:equalTo 3 .
|
|
3536
3537
|
# via the schematic forward rule:
|
|
3537
3538
|
# {
|
|
3538
|
-
# "3.3"
|
|
3539
|
+
# "3.3"^^xsd:double math:rounded ?r .
|
|
3539
3540
|
# ?r math:equalTo 3 .
|
|
3540
3541
|
# } => {
|
|
3541
3542
|
# :test-rounded-1 a :MathBuiltinTest .
|
|
3542
3543
|
# :test-rounded-1 :builtin math:rounded .
|
|
3543
|
-
# :test-rounded-1 :input "3.3"
|
|
3544
|
+
# :test-rounded-1 :input "3.3"^^xsd:double .
|
|
3544
3545
|
# :test-rounded-1 :expected 3 .
|
|
3545
3546
|
# :test-rounded-1 :actual ?r .
|
|
3546
3547
|
# :test-rounded-1 :status :pass .
|
|
@@ -3556,16 +3557,16 @@
|
|
|
3556
3557
|
# Proof for derived triple:
|
|
3557
3558
|
# :test-rounded-1 :status :pass .
|
|
3558
3559
|
# It holds because the following instance of the rule body is provable:
|
|
3559
|
-
# "3.3"
|
|
3560
|
+
# "3.3"^^xsd:double math:rounded 3 .
|
|
3560
3561
|
# 3 math:equalTo 3 .
|
|
3561
3562
|
# via the schematic forward rule:
|
|
3562
3563
|
# {
|
|
3563
|
-
# "3.3"
|
|
3564
|
+
# "3.3"^^xsd:double math:rounded ?r .
|
|
3564
3565
|
# ?r math:equalTo 3 .
|
|
3565
3566
|
# } => {
|
|
3566
3567
|
# :test-rounded-1 a :MathBuiltinTest .
|
|
3567
3568
|
# :test-rounded-1 :builtin math:rounded .
|
|
3568
|
-
# :test-rounded-1 :input "3.3"
|
|
3569
|
+
# :test-rounded-1 :input "3.3"^^xsd:double .
|
|
3569
3570
|
# :test-rounded-1 :expected 3 .
|
|
3570
3571
|
# :test-rounded-1 :actual ?r .
|
|
3571
3572
|
# :test-rounded-1 :status :pass .
|
package/eyeling.js
CHANGED
|
@@ -34,6 +34,28 @@ const LIST_NS = "http://www.w3.org/2000/10/swap/list#";
|
|
|
34
34
|
const LOG_NS = "http://www.w3.org/2000/10/swap/log#";
|
|
35
35
|
const STRING_NS = "http://www.w3.org/2000/10/swap/string#";
|
|
36
36
|
const SKOLEM_NS = "https://eyereasoner.github.io/.well-known/genid/";
|
|
37
|
+
const RDF_JSON_DT = RDF_NS + "JSON";
|
|
38
|
+
|
|
39
|
+
function isRdfJsonDatatype(dt) {
|
|
40
|
+
// dt comes from literalParts() and may be expanded or prefixed depending on parsing/printing.
|
|
41
|
+
return dt === null || dt === RDF_JSON_DT || dt === "rdf:JSON";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function termToJsonText(t) {
|
|
45
|
+
if (!(t instanceof Literal)) return null;
|
|
46
|
+
const [lex, dt] = literalParts(t.value);
|
|
47
|
+
if (!isRdfJsonDatatype(dt)) return null;
|
|
48
|
+
// decode escapes for short literals; long literals are taken verbatim
|
|
49
|
+
return termToJsStringDecoded(t);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function makeRdfJsonLiteral(jsonText) {
|
|
53
|
+
// Prefer a readable long literal when safe; fall back to short if needed.
|
|
54
|
+
if (!jsonText.includes('"""')) {
|
|
55
|
+
return new Literal('"""' + jsonText + '"""^^<' + RDF_JSON_DT + '>');
|
|
56
|
+
}
|
|
57
|
+
return new Literal(JSON.stringify(jsonText) + '^^<' + RDF_JSON_DT + '>');
|
|
58
|
+
}
|
|
37
59
|
|
|
38
60
|
// For a single reasoning run, this maps a canonical representation
|
|
39
61
|
// of the subject term in log:skolem to a Skolem IRI.
|
|
@@ -552,6 +574,9 @@ function collectIrisInTerm(t) {
|
|
|
552
574
|
const out = [];
|
|
553
575
|
if (t instanceof Iri) {
|
|
554
576
|
out.push(t.value);
|
|
577
|
+
} else if (t instanceof Literal) {
|
|
578
|
+
const [_lex, dt] = literalParts(t.value);
|
|
579
|
+
if (dt) out.push(dt); // so rdf/xsd prefixes are emitted when only used in ^^...
|
|
555
580
|
} else if (t instanceof ListTerm) {
|
|
556
581
|
for (const x of t.elems) out.push(...collectIrisInTerm(x));
|
|
557
582
|
} else if (t instanceof OpenListTerm) {
|
|
@@ -1951,10 +1976,7 @@ function jsonToTerm(v) {
|
|
|
1951
1976
|
if (Array.isArray(v)) return new ListTerm(v.map(jsonToTerm));
|
|
1952
1977
|
|
|
1953
1978
|
if (v && typeof v === "object") {
|
|
1954
|
-
|
|
1955
|
-
// without needing escape decoding.
|
|
1956
|
-
const raw = JSON.stringify(v);
|
|
1957
|
-
return new Literal('"""' + raw + '"""');
|
|
1979
|
+
return makeRdfJsonLiteral(JSON.stringify(v));
|
|
1958
1980
|
}
|
|
1959
1981
|
return null;
|
|
1960
1982
|
}
|
|
@@ -3566,8 +3588,9 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen) {
|
|
|
3566
3588
|
// Schema: ( $jsonText $pointer ) string:jsonPointer $value
|
|
3567
3589
|
if (g.p instanceof Iri && g.p.value === STRING_NS + "jsonPointer") {
|
|
3568
3590
|
if (!(g.s instanceof ListTerm) || g.s.elems.length !== 2) return [];
|
|
3569
|
-
|
|
3570
|
-
const
|
|
3591
|
+
|
|
3592
|
+
const jsonText = termToJsonText(g.s.elems[0]); // <-- changed
|
|
3593
|
+
const ptr = termToJsStringDecoded(g.s.elems[1]);
|
|
3571
3594
|
if (jsonText === null || ptr === null) return [];
|
|
3572
3595
|
|
|
3573
3596
|
const valTerm = jsonPointerLookup(jsonText, ptr);
|
|
@@ -4174,7 +4197,13 @@ function termToN3(t, pref) {
|
|
|
4174
4197
|
if (i.startsWith("_:")) return i;
|
|
4175
4198
|
return `<${i}>`;
|
|
4176
4199
|
}
|
|
4177
|
-
|
|
4200
|
+
if (t instanceof Literal) {
|
|
4201
|
+
const [lex, dt] = literalParts(t.value);
|
|
4202
|
+
if (!dt) return t.value; // keep numbers, booleans, lang-tagged strings, etc.
|
|
4203
|
+
const qdt = pref.shrinkIri(dt);
|
|
4204
|
+
if (qdt !== null) return `${lex}^^${qdt}`; // e.g. ^^rdf:JSON
|
|
4205
|
+
return `${lex}^^<${dt}>`; // fallback
|
|
4206
|
+
}
|
|
4178
4207
|
if (t instanceof Var) return `?${t.name}`;
|
|
4179
4208
|
if (t instanceof Blank) return t.label;
|
|
4180
4209
|
if (t instanceof ListTerm) {
|