eyeling 1.6.7 → 1.6.8
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/eyeling.js +27 -3
- package/package.json +1 -1
package/eyeling.js
CHANGED
|
@@ -3311,6 +3311,17 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen) {
|
|
|
3311
3311
|
s2[g.o.name] = lit;
|
|
3312
3312
|
return [s2];
|
|
3313
3313
|
}
|
|
3314
|
+
if (g.o instanceof Blank) return [{ ...subst }];
|
|
3315
|
+
|
|
3316
|
+
const oi = parseIntLiteral(g.o);
|
|
3317
|
+
if (oi !== null && oi === q) return [{ ...subst }];
|
|
3318
|
+
|
|
3319
|
+
// Only do numeric compare when safe enough to convert
|
|
3320
|
+
const qNum = Number(q);
|
|
3321
|
+
if (Number.isFinite(qNum) && Math.abs(qNum) <= Number.MAX_SAFE_INTEGER) {
|
|
3322
|
+
if (numEqualTerm(g.o, qNum)) return [{ ...subst }];
|
|
3323
|
+
}
|
|
3324
|
+
|
|
3314
3325
|
const s2 = unifyTerm(g.o, lit, subst);
|
|
3315
3326
|
return s2 !== null ? [s2] : [];
|
|
3316
3327
|
}
|
|
@@ -3329,6 +3340,10 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen) {
|
|
|
3329
3340
|
s2[g.o.name] = lit;
|
|
3330
3341
|
return [s2];
|
|
3331
3342
|
}
|
|
3343
|
+
if (g.o instanceof Blank) return [{ ...subst }];
|
|
3344
|
+
|
|
3345
|
+
if (numEqualTerm(g.o, q)) return [{ ...subst }];
|
|
3346
|
+
|
|
3332
3347
|
const s2 = unifyTerm(g.o, lit, subst);
|
|
3333
3348
|
return s2 !== null ? [s2] : [];
|
|
3334
3349
|
}
|
|
@@ -3509,18 +3524,27 @@ function evalBuiltin(goal, subst, facts, backRules, depth, varGen) {
|
|
|
3509
3524
|
// math:rounded
|
|
3510
3525
|
// Round to nearest integer.
|
|
3511
3526
|
// If there are two such numbers, then the one closest to positive infinity is returned.
|
|
3512
|
-
// Schema: $s math:rounded $o
|
|
3527
|
+
// Schema: $s+ math:rounded $o-
|
|
3528
|
+
// Note: spec says $o is xsd:integer, but we also accept any numeric $o that equals the rounded value.
|
|
3513
3529
|
if (g.p instanceof Iri && g.p.value === MATH_NS + 'rounded') {
|
|
3514
3530
|
const a = parseNum(g.s);
|
|
3515
3531
|
if (a === null) return [];
|
|
3516
|
-
|
|
3517
|
-
|
|
3532
|
+
if (Number.isNaN(a)) return [];
|
|
3533
|
+
|
|
3534
|
+
const rVal = Math.round(a); // ties go toward +∞ in JS (e.g., -1.5 -> -1)
|
|
3535
|
+
const lit = new Literal(String(rVal)); // integer token
|
|
3518
3536
|
|
|
3519
3537
|
if (g.o instanceof Var) {
|
|
3520
3538
|
const s2 = { ...subst };
|
|
3521
3539
|
s2[g.o.name] = lit;
|
|
3522
3540
|
return [s2];
|
|
3523
3541
|
}
|
|
3542
|
+
if (g.o instanceof Blank) return [{ ...subst }];
|
|
3543
|
+
|
|
3544
|
+
// Accept typed numeric literals too (e.g., "3"^^xsd:float) if numerically equal.
|
|
3545
|
+
if (numEqualTerm(g.o, rVal)) return [{ ...subst }];
|
|
3546
|
+
|
|
3547
|
+
// Fallback to strict unification
|
|
3524
3548
|
const s2 = unifyTerm(g.o, lit, subst);
|
|
3525
3549
|
return s2 !== null ? [s2] : [];
|
|
3526
3550
|
}
|