eyemind 0.9.9 → 0.9.11
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/LE-SPEC.md +7 -1
- package/LS-SPEC.md +1 -1
- package/README.md +9 -5
- package/package.json +1 -1
- package/src/le-explain.js +15 -20
- package/src/le.js +7 -3
- package/src/version.js +1 -1
package/LE-SPEC.md
CHANGED
|
@@ -13,6 +13,11 @@ extension: the meaning of the compiled program is defined by the
|
|
|
13
13
|
document says how eyemind reads LE and what it compiles each part to. Where the
|
|
14
14
|
two LE implementations differ, it says which reading eyemind follows.
|
|
15
15
|
|
|
16
|
+
The [Logical English conformance suite](https://eyereasoner.github.io/eyemind/le-conformance/)
|
|
17
|
+
has cases for each section of this reference. Run them with
|
|
18
|
+
`node le-conformance/run.js` or in the
|
|
19
|
+
[LE browser runner](https://eyereasoner.github.io/eyemind/playground/conformance?suite=le).
|
|
20
|
+
|
|
16
21
|
## Documents
|
|
17
22
|
|
|
18
23
|
A document is a sequence of sections. Each section starts with a header that
|
|
@@ -510,7 +515,8 @@ through its template, with the values of that solution:
|
|
|
510
515
|
- an aggregate gives its value, its condition and the values it collected, after
|
|
511
516
|
`namely`;
|
|
512
517
|
- a comparison of dates is `is before`, `is after` or `is the same day as`, a
|
|
513
|
-
date count `is N days after`, and arithmetic the formula with its values
|
|
518
|
+
date count `is N days after`, and arithmetic the formula with its values and
|
|
519
|
+
parentheses to preserve the order of operations;
|
|
514
520
|
- a sentence a relation states at another level of an unfolding, or the base
|
|
515
521
|
relation of an `only if` rule, gives its own conditions instead of
|
|
516
522
|
repeating the answer;
|
package/LS-SPEC.md
CHANGED
package/README.md
CHANGED
|
@@ -13,13 +13,16 @@ program, a JavaScript library and a browser application.
|
|
|
13
13
|
- [Playground](https://eyereasoner.github.io/eyemind/playground/): run any
|
|
14
14
|
example or your own program in the browser, with its proof and check report.
|
|
15
15
|
- [Examples](https://eyereasoner.github.io/eyemind/examples/): the
|
|
16
|
-
|
|
16
|
+
175 runnable programs, each with a card deck and saved conclusions; all but
|
|
17
17
|
the two streamed examples also save proofs and check reports.
|
|
18
18
|
- [Specification](https://eyereasoner.github.io/eyemind/LS-SPEC): the
|
|
19
19
|
language, the proof format and how a proof is checked.
|
|
20
|
-
- [
|
|
21
|
-
1247
|
|
22
|
-
[in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
|
|
20
|
+
- [Logic Script conformance](https://eyereasoner.github.io/eyemind/conformance/)
|
|
21
|
+
has 1247 Logic Script cases, including proof checking.
|
|
22
|
+
[Run LS in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
|
|
23
|
+
- [Logical English conformance](https://eyereasoner.github.io/eyemind/le-conformance/)
|
|
24
|
+
has 599 Logical English cases for the LE reference.
|
|
25
|
+
[Run LE in your browser](https://eyereasoner.github.io/eyemind/playground/conformance?suite=le).
|
|
23
26
|
- [Book](https://eyereasoner.github.io/eyemind/BOOK): The Art of eyemind, an
|
|
24
27
|
illustrated introduction for a wide audience, and
|
|
25
28
|
[The Art of Logical English](https://eyereasoner.github.io/eyemind/LE-BOOK),
|
|
@@ -807,7 +810,8 @@ npm test -- -k skolem # only tests whose line co
|
|
|
807
810
|
EYEMIND_PROPERTY_SCALE=20 npm test -- -k properties # deeper generated tests
|
|
808
811
|
node tools/update-examples.js # regenerate example artifacts after an intended change
|
|
809
812
|
npm run sync # refresh the cached upstream test suites and the QUDT catalog
|
|
810
|
-
node conformance/run.js --command "my-eyemind" #
|
|
813
|
+
node conformance/run.js --command "my-eyemind" # test a Logic Script implementation
|
|
814
|
+
node le-conformance/run.js --command "my-le" # test a Logical English implementation
|
|
811
815
|
npm run bench # the RDF reasoning benchmark; see bench/README.md
|
|
812
816
|
./release patch "Describe the changes" # test, tag and publish a release
|
|
813
817
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyemind",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.11",
|
|
4
4
|
"description": "A dependency-free Logic Script (LS) reasoner with forward and backward reasoning, checkable proofs, and RDF 1.2, Notation3 (N3), SPARQL 1.2 RL (SRL) and Logical English (LE) interoperability.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/le-explain.js
CHANGED
|
@@ -20,7 +20,6 @@ const SILENT = new Set(['le:scenario/1', 'is_var/1', 'is_nonvar/1', 'true/0']);
|
|
|
20
20
|
const AGGREGATE_WORDS = { 'le:sum': 'sum', 'le:count': 'count', 'le:average': 'average', 'le:min': 'min', 'le:max': 'max' };
|
|
21
21
|
const OPERATORS = { add: '+', sub: '-', mul: '*', div: '/', floordiv: '//', mod: 'mod' };
|
|
22
22
|
const PRECEDENCE = { add: 1, sub: 1, mul: 2, div: 2, floordiv: 2, mod: 2 };
|
|
23
|
-
const ASSOCIATIVE = new Set(['add', 'mul']);
|
|
24
23
|
const COMPARISONS = { lt: '<', gt: '>', le: '=<', ge: '>=', eq: '=', ne: '!=' };
|
|
25
24
|
|
|
26
25
|
// The explanations of every answer of a Logical English run, as LE text: under
|
|
@@ -263,22 +262,19 @@ class Writer {
|
|
|
263
262
|
return /^[aeiou]/.test(words) ? `an ${words}` : `a ${words}`;
|
|
264
263
|
}
|
|
265
264
|
|
|
266
|
-
value(term, noun = null) {
|
|
265
|
+
value(term, noun = null, minPrecedence = 0) {
|
|
267
266
|
// A value a helper computed is written as the formula it came from.
|
|
268
|
-
|
|
269
|
-
term = deref(term, this.env);
|
|
270
|
-
if (term instanceof Var) return this.
|
|
267
|
+
const pending = term instanceof Var ? this.pending.get(term) : null;
|
|
268
|
+
term = pending instanceof Struct ? pending : deref(term, this.env);
|
|
269
|
+
if (term instanceof Var) return this.phrase(term, noun);
|
|
271
270
|
if (term instanceof Struct && OPERATORS[term.name] && term.args.length === 2) {
|
|
272
|
-
//
|
|
273
|
-
//
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
return own < outer || (right && own === outer && !ASSOCIATIVE.has(term.name)) ? `(${text})` : text;
|
|
280
|
-
};
|
|
281
|
-
return `${side(term.args[0], false)} ${OPERATORS[term.name]} ${side(term.args[1], true)}`;
|
|
271
|
+
// LE reads operators of equal precedence from left to right. Keep a
|
|
272
|
+
// grouped right operand even for + and *, since floats can round.
|
|
273
|
+
const precedence = PRECEDENCE[term.name];
|
|
274
|
+
const left = this.value(term.args[0], null, precedence);
|
|
275
|
+
const right = this.value(term.args[1], null, precedence + 1);
|
|
276
|
+
const text = `${left} ${OPERATORS[term.name]} ${right}`;
|
|
277
|
+
return precedence < minPrecedence ? `(${text})` : text;
|
|
282
278
|
}
|
|
283
279
|
if (term instanceof Struct && (term.name === 'min' || term.name === 'max') && term.args.length === 2) {
|
|
284
280
|
return `the ${term.name === 'min' ? 'minimum' : 'maximum'} of ${this.value(term.args[0])} and ${this.value(term.args[1])}`;
|
|
@@ -328,8 +324,7 @@ class Writer {
|
|
|
328
324
|
const each = named === undefined ? null : ID.test(named) ? named : named.replace(/([a-z0-9])([A-Z])/g, '$1 $2').toLowerCase();
|
|
329
325
|
if (item instanceof Var) this.seen.add(item);
|
|
330
326
|
const such = `each ${each ?? this.value(item)} such that ${this.conjunction(args[1])}`;
|
|
331
|
-
|
|
332
|
-
this.pending.set(args[2] instanceof Var ? args[2] : list, { such, items });
|
|
327
|
+
this.pending.set(args[2] instanceof Var ? args[2] : list, { such });
|
|
333
328
|
return null;
|
|
334
329
|
}
|
|
335
330
|
if (AGGREGATE_WORDS[name] && args.length === 2) {
|
|
@@ -340,12 +335,12 @@ class Writer {
|
|
|
340
335
|
}
|
|
341
336
|
if (name === 'le:divide' && args.length === 3) {
|
|
342
337
|
// The quotient is written where the formula that divides uses it.
|
|
343
|
-
const formula =
|
|
338
|
+
const formula = new Struct('div', args.slice(0, 2));
|
|
344
339
|
if (args[2] instanceof Var) {
|
|
345
340
|
this.pending.set(args[2], formula);
|
|
346
341
|
return null;
|
|
347
342
|
}
|
|
348
|
-
return `${this.value(args[2])} = ${formula}`;
|
|
343
|
+
return `${this.value(args[2])} = ${this.value(formula)}`;
|
|
349
344
|
}
|
|
350
345
|
if (name === 'le:days_after' && args.length === 3) return `${this.value(args[0])} is ${this.value(args[1])} days after ${this.value(args[2])}`;
|
|
351
346
|
if (name === 'is' && args.length === 2) {
|
|
@@ -380,7 +375,7 @@ class Writer {
|
|
|
380
375
|
// The items a collection gathered, for the aggregate that takes them.
|
|
381
376
|
collected(list) {
|
|
382
377
|
const pending = this.pending.get(list instanceof Var ? list : deref(list, this.env));
|
|
383
|
-
if (!pending ||
|
|
378
|
+
if (!pending || pending instanceof Struct) return null;
|
|
384
379
|
const items = copyResolved(list, this.env);
|
|
385
380
|
const values = [];
|
|
386
381
|
let rest = items;
|
package/src/le.js
CHANGED
|
@@ -192,7 +192,7 @@ function bracketedName(tokens) {
|
|
|
192
192
|
const lower = (token) => token.kind === 'word' ? token.text.toLowerCase() : token.text;
|
|
193
193
|
const isWord = (token, ...words) => token.kind === 'word' && words.includes(token.text.toLowerCase());
|
|
194
194
|
// Words joined as written: no space before a comma, a closing bracket or 's.
|
|
195
|
-
const joined = (words) => words.join(' ').replace(/ ([,:\])])
|
|
195
|
+
const joined = (words) => words.join(' ').replace(/ ([,:\])])/g, '$1').replace(/([[(]) /g, '$1').replace(/ (['’]s)(?= |$)/g, '$1').replace(/ +$/, '');
|
|
196
196
|
const phrase = (tokens) => joined(tokens.map((t) => t.text));
|
|
197
197
|
// Whether tokens start with these words, compared without case.
|
|
198
198
|
const startsWith = (tokens, words, at = 0) => words.every((word, i) => tokens[at + i] && lower(tokens[at + i]) === word);
|
|
@@ -2209,8 +2209,12 @@ export function writeLe(result, loaded) {
|
|
|
2209
2209
|
// on; an answer that also holds without any is definite.
|
|
2210
2210
|
const found = new Map();
|
|
2211
2211
|
// A negative assumption reads "it is not the case that S".
|
|
2212
|
-
const unknown = (term) =>
|
|
2213
|
-
|
|
2212
|
+
const unknown = (term) => {
|
|
2213
|
+
if (term instanceof Struct && term.name === 'le:not' && term.args.length === 1) return `it is not the case that ${unknown(term.args[0])}`;
|
|
2214
|
+
// Without a scenario argument a sentence with no places is an atom.
|
|
2215
|
+
if (typeof term === 'string') return leValue(new Struct(term, []), templates);
|
|
2216
|
+
return leValue(threaded && term instanceof Struct ? new Struct(term.name, term.args.slice(1)) : term, templates);
|
|
2217
|
+
};
|
|
2214
2218
|
for (const answer of result.answers) {
|
|
2215
2219
|
const term = readTerm(answer);
|
|
2216
2220
|
if (!(term instanceof Struct) || term.name !== ANSWER) continue;
|
package/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// The release this checkout is; ./release keeps it in step with package.json.
|
|
2
|
-
export const VERSION = '0.9.
|
|
2
|
+
export const VERSION = '0.9.11';
|