eyeling 1.5.30 → 1.5.31
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 +29 -3
- package/package.json +1 -1
package/eyeling.js
CHANGED
|
@@ -676,8 +676,23 @@ class Parser {
|
|
|
676
676
|
this.expectDot();
|
|
677
677
|
backwardRules.push(this.makeRule(first, second, false));
|
|
678
678
|
} else {
|
|
679
|
-
|
|
680
|
-
|
|
679
|
+
let more;
|
|
680
|
+
|
|
681
|
+
if (this.peek().typ === "Dot") {
|
|
682
|
+
// Allow a bare blank-node property list statement, e.g. `[ a :Statement ].`
|
|
683
|
+
const lastTok = this.toks[this.pos - 1];
|
|
684
|
+
if (this.pendingTriples.length > 0 && lastTok && lastTok.typ === "RBracket") {
|
|
685
|
+
more = this.pendingTriples;
|
|
686
|
+
this.pendingTriples = [];
|
|
687
|
+
this.next(); // consume '.'
|
|
688
|
+
} else {
|
|
689
|
+
throw new Error(`Unexpected '.' after term; missing predicate/object list`);
|
|
690
|
+
}
|
|
691
|
+
} else {
|
|
692
|
+
more = this.parsePredicateObjectList(first);
|
|
693
|
+
this.expectDot();
|
|
694
|
+
}
|
|
695
|
+
|
|
681
696
|
// normalize explicit log:implies / log:impliedBy at top-level
|
|
682
697
|
for (const tr of more) {
|
|
683
698
|
if (isLogImplies(tr.p) && tr.s instanceof FormulaTerm && tr.o instanceof FormulaTerm) {
|
|
@@ -692,7 +707,6 @@ class Parser {
|
|
|
692
707
|
}
|
|
693
708
|
}
|
|
694
709
|
|
|
695
|
-
// console.log(JSON.stringify([this.prefixes, triples, forwardRules, backwardRules], null, 2));
|
|
696
710
|
return [this.prefixes, triples, forwardRules, backwardRules];
|
|
697
711
|
}
|
|
698
712
|
|
|
@@ -929,6 +943,17 @@ class Parser {
|
|
|
929
943
|
throw new Error(`Expected '.' or '}', got ${this.peek().toString()}`);
|
|
930
944
|
}
|
|
931
945
|
} else {
|
|
946
|
+
// Allow a bare blank-node property list statement inside a formula, e.g. `{ [ a :X ]. }`
|
|
947
|
+
if (this.peek().typ === "Dot" || this.peek().typ === "RBrace") {
|
|
948
|
+
const lastTok = this.toks[this.pos - 1];
|
|
949
|
+
if (this.pendingTriples.length > 0 && lastTok && lastTok.typ === "RBracket") {
|
|
950
|
+
triples.push(...this.pendingTriples);
|
|
951
|
+
this.pendingTriples = [];
|
|
952
|
+
if (this.peek().typ === "Dot") this.next();
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
932
957
|
triples.push(...this.parsePredicateObjectList(left));
|
|
933
958
|
if (this.peek().typ === "Dot") this.next();
|
|
934
959
|
else if (this.peek().typ === "RBrace") {
|
|
@@ -4187,6 +4212,7 @@ function main() {
|
|
|
4187
4212
|
const toks = lex(text);
|
|
4188
4213
|
const parser = new Parser(toks);
|
|
4189
4214
|
const [prefixes, triples, frules, brules] = parser.parseDocument();
|
|
4215
|
+
// console.log(JSON.stringify([prefixes, triples, frules, brules], null, 2));
|
|
4190
4216
|
|
|
4191
4217
|
const facts = triples.filter(tr => isGroundTriple(tr));
|
|
4192
4218
|
const derived = forwardChain(facts, frules, brules);
|