eyeling 1.15.14 → 1.16.0
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/HANDBOOK.md +25 -5
- package/README.md +77 -0
- package/eyeling.js +894 -9
- package/index.d.ts +184 -1
- package/index.js +17 -7
- package/lib/engine.js +92 -8
- package/lib/entry.js +3 -0
- package/lib/rdfjs.js +795 -0
- package/package.json +1 -1
- package/test/api.test.js +263 -0
- package/tools/bundle.js +1 -1
package/HANDBOOK.md
CHANGED
|
@@ -1747,6 +1747,13 @@ The engine’s `reasonStream` API can accept an `onDerived` callback. Each time
|
|
|
1747
1747
|
|
|
1748
1748
|
This is especially useful in interactive demos (and is the basis of the playground streaming tab).
|
|
1749
1749
|
|
|
1750
|
+
The same API can now also emit RDF/JS output. When `rdfjs: true` is passed, every `onDerived(...)` payload includes both:
|
|
1751
|
+
|
|
1752
|
+
- `triple` — Eyeling’s N3 string form
|
|
1753
|
+
- `quad` — the same fact as an RDF/JS default-graph quad
|
|
1754
|
+
|
|
1755
|
+
For fully stream-oriented RDF/JS consumers there is also `reasonRdfJs(...)`, which exposes the derived facts as an async iterable of RDF/JS quads.
|
|
1756
|
+
|
|
1750
1757
|
---
|
|
1751
1758
|
|
|
1752
1759
|
<a id="ch14"></a>
|
|
@@ -1783,22 +1790,35 @@ The current CLI supports a small set of flags (see `lib/cli.js`):
|
|
|
1783
1790
|
|
|
1784
1791
|
`lib/entry.js` exports:
|
|
1785
1792
|
|
|
1786
|
-
- public APIs: `reasonStream`, `main`, `version`
|
|
1793
|
+
- public APIs: `reasonStream`, `reasonRdfJs`, `rdfjs`, `main`, `version`
|
|
1787
1794
|
- plus a curated set of internals used by the demo (`lex`, `Parser`, `forwardChain`, etc.)
|
|
1788
1795
|
|
|
1796
|
+
`rdfjs` is a small built-in RDF/JS `DataFactory`, so browser / worker code can construct quads without pulling in another package first.
|
|
1797
|
+
|
|
1789
1798
|
### 14.3 `index.js`: the npm API wrapper
|
|
1790
1799
|
|
|
1791
1800
|
The npm `reason(...)` function does something intentionally simple and robust:
|
|
1792
1801
|
|
|
1793
|
-
-
|
|
1802
|
+
- normalize the JavaScript input into N3 text
|
|
1803
|
+
- write that N3 input to a temp file
|
|
1794
1804
|
- spawn the bundled CLI (`node eyeling.js ... input.n3`)
|
|
1795
1805
|
- return stdout (and forward stderr)
|
|
1796
1806
|
|
|
1797
|
-
This
|
|
1807
|
+
This keeps the observable output identical to the CLI while still allowing richer JS-side inputs.
|
|
1808
|
+
|
|
1809
|
+
In particular, the npm API now accepts:
|
|
1810
|
+
|
|
1811
|
+
- raw N3 strings
|
|
1812
|
+
- RDF/JS fact inputs (`quads`, `facts`, or `dataset`)
|
|
1813
|
+
- Eyeling rule objects or full AST bundles like `[prefixes, triples, frules, brules]`
|
|
1814
|
+
|
|
1815
|
+
For structured JavaScript input, rules are supplied as current Eyeling `Rule` / `Triple` object graphs or as JSON-serialized `--ast` output with `_type` markers.
|
|
1816
|
+
|
|
1817
|
+
If you want to use N3 source text, pass the whole input as a plain N3 string.
|
|
1798
1818
|
|
|
1799
|
-
One practical implication:
|
|
1819
|
+
One practical implication remains:
|
|
1800
1820
|
|
|
1801
|
-
- if you want _in-process_ access to the engine objects (facts arrays, derived proof objects), use `reasonStream` from the bundle entry rather than the subprocess-based API.
|
|
1821
|
+
- if you want _in-process_ access to the engine objects (facts arrays, derived proof objects), use `reasonStream` / `reasonRdfJs` from the bundle entry rather than the subprocess-based API.
|
|
1802
1822
|
|
|
1803
1823
|
---
|
|
1804
1824
|
|
package/README.md
CHANGED
|
@@ -99,6 +99,64 @@ Notes:
|
|
|
99
99
|
- By default, the npm helper keeps output machine-friendly (`proofComments: false`).
|
|
100
100
|
- The npm helper shells out to the bundled `eyeling.js` CLI for simplicity and robustness.
|
|
101
101
|
|
|
102
|
+
### RDF/JS and Eyeling rule-object interop
|
|
103
|
+
|
|
104
|
+
The JavaScript APIs now accept three input styles:
|
|
105
|
+
|
|
106
|
+
1. plain N3 text
|
|
107
|
+
2. RDF/JS facts (`quads`, `facts`, or `dataset`)
|
|
108
|
+
3. Eyeling rule objects / AST bundles (the same shapes you get from `eyeling --ast`)
|
|
109
|
+
|
|
110
|
+
If you want to use N3 source text, pass the whole input as a plain N3 string.
|
|
111
|
+
|
|
112
|
+
For RDF/JS facts, the graph must be the default graph. Named-graph quads are rejected.
|
|
113
|
+
|
|
114
|
+
For structured inputs, `rules` is supplied as current Eyeling rule objects:
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
const { reason, rdfjs } = require('eyeling');
|
|
118
|
+
|
|
119
|
+
const ex = 'http://example.org/';
|
|
120
|
+
|
|
121
|
+
const rule = {
|
|
122
|
+
_type: 'Rule',
|
|
123
|
+
premise: [
|
|
124
|
+
{
|
|
125
|
+
_type: 'Triple',
|
|
126
|
+
s: { _type: 'Var', name: 'x' },
|
|
127
|
+
p: { _type: 'Iri', value: ex + 'parent' },
|
|
128
|
+
o: { _type: 'Var', name: 'y' },
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
conclusion: [
|
|
132
|
+
{
|
|
133
|
+
_type: 'Triple',
|
|
134
|
+
s: { _type: 'Var', name: 'x' },
|
|
135
|
+
p: { _type: 'Iri', value: ex + 'ancestor' },
|
|
136
|
+
o: { _type: 'Var', name: 'y' },
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
isForward: true,
|
|
140
|
+
isFuse: false,
|
|
141
|
+
headBlankLabels: [],
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const out = reason(
|
|
145
|
+
{ proofComments: false },
|
|
146
|
+
{
|
|
147
|
+
quads: [rdfjs.quad(rdfjs.namedNode(ex + 'alice'), rdfjs.namedNode(ex + 'parent'), rdfjs.namedNode(ex + 'bob'))],
|
|
148
|
+
rules: [rule],
|
|
149
|
+
},
|
|
150
|
+
);
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
You can also pass a full AST bundle directly:
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
const ast = [prefixes, triples, forwardRules, backwardRules];
|
|
157
|
+
const out2 = reason({ proofComments: false }, ast);
|
|
158
|
+
```
|
|
159
|
+
|
|
102
160
|
### Direct bundle / browser-worker API: `reasonStream()`
|
|
103
161
|
|
|
104
162
|
For in-process reasoning (browser, worker, or direct use of `eyeling.js`):
|
|
@@ -113,6 +171,8 @@ const result = eyeling.reasonStream(input, {
|
|
|
113
171
|
console.log(result.closureN3);
|
|
114
172
|
```
|
|
115
173
|
|
|
174
|
+
`eyeling.js` now also exposes `eyeling.rdfjs` and `eyeling.reasonRdfJs(...)` for RDF/JS workflows.
|
|
175
|
+
|
|
116
176
|
#### `reasonStream()` output behavior
|
|
117
177
|
|
|
118
178
|
`closureN3` is also mode-dependent:
|
|
@@ -126,8 +186,25 @@ To exclude input facts from the normal-mode closure, pass:
|
|
|
126
186
|
includeInputFactsInClosure: false;
|
|
127
187
|
```
|
|
128
188
|
|
|
189
|
+
When `rdfjs: true` is passed, `onDerived` also receives a `quad` field and the result may include `closureQuads` / `queryQuads`.
|
|
190
|
+
|
|
129
191
|
The returned object also includes `queryMode`, `queryTriples`, and `queryDerived` (and in normal mode, `onDerived` fires for newly derived facts; in `log:query` mode it fires for the query-selected derived triples).
|
|
130
192
|
|
|
193
|
+
### `reasonRdfJs()`
|
|
194
|
+
|
|
195
|
+
`reasonRdfJs(input, opts)` exposes derived results as an async iterable of RDF/JS quads as they are produced:
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
const { reasonRdfJs, rdfjs } = require('eyeling');
|
|
199
|
+
|
|
200
|
+
for await (const quad of reasonRdfJs({
|
|
201
|
+
quads: [rdfjs.quad(rdfjs.namedNode(ex + 'alice'), rdfjs.namedNode(ex + 'parent'), rdfjs.namedNode(ex + 'bob'))],
|
|
202
|
+
rules: [rule],
|
|
203
|
+
})) {
|
|
204
|
+
console.log(quad.subject.value, quad.predicate.value, quad.object.value);
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
131
208
|
## Builtins
|
|
132
209
|
|
|
133
210
|
Builtins are defined in [eyeling-builtins.ttl](https://github.com/eyereasoner/eyeling/blob/main/eyeling-builtins.ttl) and described in the [Handbook (Chapter 11)](https://eyereasoner.github.io/eyeling/HANDBOOK#ch11).
|