eyemind 0.9.20 → 0.9.21
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/LS-SPEC.md +1 -1
- package/README.md +12 -7
- package/package.json +1 -1
- package/src/cli.js +6 -3
- package/src/messages.js +5 -4
- package/src/qudt.js +5 -1
- package/src/rdf-logic.js +11 -7
- package/src/specialize.js +3 -3
- package/src/version.js +1 -1
package/LS-SPEC.md
CHANGED
package/README.md
CHANGED
|
@@ -13,8 +13,8 @@ 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
|
-
|
|
17
|
-
the
|
|
16
|
+
177 runnable programs, each with a card deck and saved conclusions; all but
|
|
17
|
+
the three 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
20
|
- [Logic Script conformance](https://eyereasoner.github.io/eyemind/conformance/)
|
|
@@ -364,10 +364,13 @@ the same as running the whole program over the background and the message,
|
|
|
364
364
|
and the whole program runs instead when new triples could have any property,
|
|
365
365
|
as `owl:sameAs` between individuals makes, or when a negation could retract
|
|
366
366
|
a background conclusion. With `--qudt`, the compiler reads the units and
|
|
367
|
-
metadata of each message
|
|
368
|
-
|
|
367
|
+
metadata of each message: a message whose units need catalog facts the
|
|
368
|
+
background lacks runs the whole program, compiled with its own units, and the
|
|
369
|
+
others, such as those of QUDT's builtin units, use the specialized rules.
|
|
369
370
|
`--program` prints the specialized program of each new shape, and `--stats`
|
|
370
|
-
says whether each message used one.
|
|
371
|
+
says whether each message used one. `--to` writes each message's triples as
|
|
372
|
+
`turtle`, `trig`, `n-triples`, `n-quads` or `jelly`; Jelly messages, one per
|
|
373
|
+
message, form one Jelly stream. Streamed messages have no proofs.
|
|
371
374
|
|
|
372
375
|
An [output contract](#rdf-logic-profiles) prunes the specialized rules to
|
|
373
376
|
those that can contribute to a triple it asks for, following premises back
|
|
@@ -397,7 +400,9 @@ property or class in a rule takes the values its schema premise has in the
|
|
|
397
400
|
background, as partial evaluation gives them. Planned rules derive what the shapes lead to,
|
|
398
401
|
not every OWL 2 RL consequence: equality that the output does not ask for is
|
|
399
402
|
not derived. See the
|
|
400
|
-
[shape-planning](https://eyereasoner.github.io/eyemind/examples/deck/shape-planning-owl2rl) deck
|
|
403
|
+
[shape-planning](https://eyereasoner.github.io/eyemind/examples/deck/shape-planning-owl2rl) deck,
|
|
404
|
+
and the [readings](https://eyereasoner.github.io/eyemind/examples/deck/readings-skos-qudt)
|
|
405
|
+
deck for SKOS and QUDT over messages in Jelly.
|
|
401
406
|
|
|
402
407
|
```sh
|
|
403
408
|
eyemind --owl2rl --stream-messages ontology.ttl messages.trig # each message's new triples
|
|
@@ -654,7 +659,7 @@ A clause is listed when no conclusion's proof uses it; a clause only a negation
|
|
|
654
659
|
|
|
655
660
|
## Examples and the playground
|
|
656
661
|
|
|
657
|
-
The [examples](https://eyereasoner.github.io/eyemind/examples/) range from classics (Ackermann, the zebra puzzle) to planning, policy reasoning, mathematics, RDF 1.2 data and a hundred-thousand-level taxonomy. Each has its conclusions saved in `examples/output/`, all but the
|
|
662
|
+
The [examples](https://eyereasoner.github.io/eyemind/examples/) range from classics (Ackermann, the zebra puzzle) to planning, policy reasoning, mathematics, RDF 1.2 data and a hundred-thousand-level taxonomy. Each has its conclusions saved in `examples/output/`, all but the three streamed examples their proof and check report in `examples/proof/` and `examples/check/`, and each a card deck for a wide audience. Change a fact, run it, and compare with the saved output.
|
|
658
663
|
|
|
659
664
|
The [playground](https://eyereasoner.github.io/eyemind/playground/) runs eyemind in a worker in your browser, so **Stop** ends a long run. Choose an example, edit it, pick an output (conclusions, proof, checked answers, check of a saved proof, unused clauses, Logical English answers explained, or independent RDF Messages) and press **Run** or Ctrl+Enter. A line an error names is marked red, the options panel shows the equivalent command, and **Share link** copies a link with the program and options.
|
|
660
665
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyemind",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.21",
|
|
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/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { COMPILED_LIMITS, run, unusedClauses } from './engine.js';
|
|
3
3
|
import { OUTPUT_FORMATS, RDF_PROFILES, defaultFormat, inputKind, isLog, loadInputs, loadMessageReasoner, rdfMessageFormat, scopeOf, writeConclusions } from './formats.js';
|
|
4
4
|
import { explainLe } from './le-explain.js';
|
|
5
|
-
import { replayMessages, RdfMessageReader } from './messages.js';
|
|
5
|
+
import { replayMessages, RdfMessageReader, writeRdfMessages } from './messages.js';
|
|
6
6
|
import { checkProof, checkReport, publicReport } from './proof.js';
|
|
7
7
|
import { writeRdf } from './rdf.js';
|
|
8
8
|
import { programText } from './specialize.js';
|
|
@@ -54,7 +54,7 @@ Exit codes: 0 success, 1 error, 2 invalid proof, 65 contradiction.
|
|
|
54
54
|
const LIMITS = { '--max-depth': 'maxDepth', '--max-iterations': 'maxIterations', '--max-inferences': 'maxInferences' };
|
|
55
55
|
const ALIASES = new Map([['-p', '--proof'], ['-c', '--prove-and-check'], ['-v', '--version'], ['-h', '--help']]);
|
|
56
56
|
|
|
57
|
-
const RDF_FORMATS = ['turtle', 'trig', 'n-triples', 'n-quads'];
|
|
57
|
+
const RDF_FORMATS = ['turtle', 'trig', 'n-triples', 'n-quads', 'jelly'];
|
|
58
58
|
|
|
59
59
|
class UsageError extends Error {}
|
|
60
60
|
|
|
@@ -197,7 +197,10 @@ export function main(argv, io) {
|
|
|
197
197
|
else if (!result.specialized && messageNumber === 1) stdout(`// These rules are not specialized: ${reasoner.reason ?? 'a message has a shape they cannot be specialized to'}.\n`);
|
|
198
198
|
return 0;
|
|
199
199
|
}
|
|
200
|
-
|
|
200
|
+
const prefixes = { ...reasoner.prefixes, ...message.prefixes };
|
|
201
|
+
// A Jelly log per message, all of quads, so that they concatenate.
|
|
202
|
+
stdout(format === 'jelly' ? writeRdfMessages([result.quads], { format, prefixes, physicalType: 'quads' })
|
|
203
|
+
: writeRdf(result.quads, { format: format ?? 'turtle', prefixes, blankNodePrefix: `m${messageNumber}_` }));
|
|
201
204
|
if (stats) stderr(`${JSON.stringify({ message: message.index, specialized: result.specialized, dropped: result.dropped, conforms: result.conforms, ...result.stats })}\n`);
|
|
202
205
|
return result.haltCode || 0;
|
|
203
206
|
};
|
package/src/messages.js
CHANGED
|
@@ -359,12 +359,13 @@ export function parseRdfMessages(text, options = {}) {
|
|
|
359
359
|
// An RDF Message Log of messages, each its quads: VERSION "1.2-messages"
|
|
360
360
|
// and a MESSAGE delimiter between messages in Turtle, TriG, N-Triples and
|
|
361
361
|
// N-Quads, an rdf:RDF per message in RDF/XML, a line per message in
|
|
362
|
-
// NDJSON-LD, and message boundaries in Jelly, whose log is bytes
|
|
363
|
-
//
|
|
364
|
-
|
|
362
|
+
// NDJSON-LD, and message boundaries in Jelly, whose log is bytes; Jelly logs
|
|
363
|
+
// of the same physicalType concatenate into one. A final empty message needs
|
|
364
|
+
// one more delimiter, as a trailing delimiter alone opens no message.
|
|
365
|
+
export function writeRdfMessages(messages, { format = 'trig', prefixes = {}, physicalType } = {}) {
|
|
365
366
|
if (format === 'jelly') {
|
|
366
367
|
try {
|
|
367
|
-
return writeJelly(messages.map((quads) => neutralQuads(quads)), { messages: true, namespaces: prefixes });
|
|
368
|
+
return writeJelly(messages.map((quads) => neutralQuads(quads)), { messages: true, namespaces: prefixes, physicalType });
|
|
368
369
|
} catch (error) {
|
|
369
370
|
throw new EyemindError(error.message);
|
|
370
371
|
}
|
package/src/qudt.js
CHANGED
|
@@ -136,8 +136,12 @@ implies([qu_input(S, P, Q, Kind, U, V, T, Code, DT, G), qu_ratio(V, U, G, R), qu
|
|
|
136
136
|
rdf(S, qc('normalizedQuantity'), B, G), rdf(S, qc('normalizedUcumLiteral'), literal(Lexical, datatype('https://w3id.org/cdt/ucum')), G),
|
|
137
137
|
rdf(S, qc('normalizedCdtLiteral'), literal(Lexical, datatype(DT)), G),
|
|
138
138
|
rdf(B, iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), qu('QuantityValue'), G),
|
|
139
|
-
rdf(B, qu('numericValue'), Number, G), rdf(B, qu('unit'), T, G), rdf(B, qc('sourceProperty'), P, G),
|
|
139
|
+
rdf(B, qu('numericValue'), Number, G), rdf(B, qu('unit'), T, G), rdf(B, qc('sourceProperty'), P, G), qu_source(B, Kind, Q, G), rdf(B, qc('sourceUnit'), U, G)
|
|
140
140
|
]);
|
|
141
|
+
// The source of a normalized quantity, with the property of its kind, so that
|
|
142
|
+
// every rule names the properties it concludes and messages can be specialized.
|
|
143
|
+
implies(qu_source(B, qc('sourceQuantity'), Q, G), rdf(B, qc('sourceQuantity'), Q, G));
|
|
144
|
+
implies(qu_source(B, qc('sourceLiteral'), Q, G), rdf(B, qc('sourceLiteral'), Q, G));
|
|
141
145
|
// Units composed in the input from factor units or a prefix (qudtUnits).
|
|
142
146
|
implied_by(qu_unit(U, G, D, M, float(0)), [qu_derived(U, G, D, M), not(qu_custom(U, G))]);
|
|
143
147
|
// A quantity whose unit is not known, composed or aligned is reported.
|
package/src/rdf-logic.js
CHANGED
|
@@ -330,16 +330,19 @@ export function messageReasoner({ quads, prefixes, wanted = null, expected = nul
|
|
|
330
330
|
const options = { profiles, source };
|
|
331
331
|
const whole = { ...options, stableRuleIds: true };
|
|
332
332
|
// QUDT adds catalog facts during compilation from the units and metadata
|
|
333
|
-
//
|
|
333
|
+
// of the graph. A message whose units need facts that the background's
|
|
334
|
+
// program lacks runs the whole program, compiled with its own units; the
|
|
335
|
+
// others, such as those of QUDT's builtin units, are specialized.
|
|
334
336
|
const qudt = profiles.includes('qudt'), usePlan = planned && !qudt;
|
|
335
|
-
const
|
|
337
|
+
const backgroundUnits = qudt ? qudtUnits(quads) : '';
|
|
338
|
+
const background = compileRdfLogic({ quads, prefixes }, { ...options, stream: true });
|
|
336
339
|
// Trusted SHACL shapes plan the rules first, as rdfjs-inference-engine does.
|
|
337
340
|
const program = usePlan ? planRules(background.program, quads, { input: expected && vocabularyOf(expected.patterns),
|
|
338
341
|
output: wanted && vocabularyOf(wanted) }) : background.program;
|
|
339
|
-
const specializer =
|
|
342
|
+
const specializer = new Specializer(program, { quads: ['rdf/4', 'ent_base/4'], limits,
|
|
340
343
|
wanted: wanted && wanted.flatMap((pattern) => [pattern, new Struct('ent_report', pattern.args)]) });
|
|
341
344
|
// The program for the messages an input shape describes is made at once.
|
|
342
|
-
if (expected) specializer
|
|
345
|
+
if (expected) specializer.expect(expected.patterns.flatMap((pattern) => [pattern, new Struct('ent_base', pattern.args)]));
|
|
343
346
|
let serial = 0;
|
|
344
347
|
const matches = (quad, patterns) => patterns.some((pattern) => unify(new Struct('rdf', quad), freshTerm(pattern, `w${++serial}`), new Env()));
|
|
345
348
|
const kept = (quad) => wanted === null || matches(quad, wanted);
|
|
@@ -347,7 +350,7 @@ export function messageReasoner({ quads, prefixes, wanted = null, expected = nul
|
|
|
347
350
|
const answers = (program, limits) => run(program, limits).conclusions.filter((t) => t instanceof Struct && t.name === 'result_rdf');
|
|
348
351
|
return {
|
|
349
352
|
prefixes: background.prefixes,
|
|
350
|
-
reason:
|
|
353
|
+
reason: specializer.reason,
|
|
351
354
|
specializer,
|
|
352
355
|
// limits are run()'s bounds. The result has the added quads, whether
|
|
353
356
|
// the rules were specialized, and the specialized program's sources the
|
|
@@ -358,7 +361,8 @@ export function messageReasoner({ quads, prefixes, wanted = null, expected = nul
|
|
|
358
361
|
if (expected?.allowed) message = message.filter((quad) => quad[1].name === 'iri' && expected.allowed.has(quad[1].args[0]));
|
|
359
362
|
const shaped = expected ? { dropped: all.length - message.length } : {};
|
|
360
363
|
const facts = message.flatMap((q) => [new Struct('rdf', q), new Struct('ent_base', q)]);
|
|
361
|
-
const
|
|
364
|
+
const ownUnits = qudt && qudtUnits([...quads, ...message]) !== backgroundUnits;
|
|
365
|
+
const special = ownUnits ? null : specializer.specialize(facts);
|
|
362
366
|
if (special !== null) {
|
|
363
367
|
const result = run(special.program, runLimits);
|
|
364
368
|
const added = result.derived.map((node) => node.goal).filter((t) => !special.old.has(identity(t)) &&
|
|
@@ -375,7 +379,7 @@ export function messageReasoner({ quads, prefixes, wanted = null, expected = nul
|
|
|
375
379
|
(t.name === 'ent_report' || (t.name === 'rdf' && RESOURCES.has(t.args[0].name) && t.args[1].name === 'iri')));
|
|
376
380
|
return { quads: added.map((t) => t.args).filter(kept), specialized: false, stats: result.stats, haltCode: result.haltCode, sources: null, ...shaped };
|
|
377
381
|
}
|
|
378
|
-
alone ??= new Set(answers(
|
|
382
|
+
alone ??= new Set(answers(compileRdfLogic({ quads, prefixes }, whole).program, runLimits).map(identity));
|
|
379
383
|
const result = run(compileRdfLogic({ quads: [...quads, ...message], prefixes, shapes: quads }, whole).program, runLimits);
|
|
380
384
|
const added = result.conclusions.filter((t) => t instanceof Struct && t.name === 'result_rdf' && !alone.has(identity(t)));
|
|
381
385
|
return { quads: added.map((t) => t.args).filter(kept), specialized: false, stats: result.stats, haltCode: result.haltCode, sources: null, ...shaped };
|
package/src/specialize.js
CHANGED
|
@@ -109,10 +109,10 @@ function canonical(pattern) {
|
|
|
109
109
|
// A literal keeps its datatype.
|
|
110
110
|
export const shape = (term) => term instanceof Var ? term : !(term instanceof Struct) ? variable()
|
|
111
111
|
: term.name === 'datatype' && term.args.length === 1 ? term : new Struct(term.name, term.args.map(shape));
|
|
112
|
-
// The functors of a term to a depth, and the datatypes of its
|
|
113
|
-
// patterns with the same skeleton are generalized into one.
|
|
112
|
+
// The functors of a term to a depth, and the known datatypes of its
|
|
113
|
+
// literals: patterns with the same skeleton are generalized into one.
|
|
114
114
|
const skeleton = (term, depth) => term instanceof Var || !depth ? '*' : !(term instanceof Struct) ? typeof term
|
|
115
|
-
: term.name === 'datatype' && term.args.length === 1 ? identity(term)
|
|
115
|
+
: term.name === 'datatype' && term.args.length === 1 ? (isGround(term) ? identity(term) : '*')
|
|
116
116
|
: `${term.name}(${term.args.map((arg) => skeleton(arg, depth - 1)).join(',')})`;
|
|
117
117
|
|
|
118
118
|
// Sources as Logic Script statements.
|
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.21';
|