n3 2.7.12 → 2.9.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/README.md +46 -2
- package/browser/n3.esm.min.js +11 -11
- package/browser/n3.min.js +9 -9
- package/lib/N3Parser.js +42 -21
- package/lib/N3Reasoner.js +13 -4
- package/lib/N3Store.js +385 -27
- package/package.json +1 -1
- package/src/N3Parser.js +47 -26
- package/src/N3Reasoner.js +14 -4
- package/src/N3Store.js +418 -32
package/README.md
CHANGED
|
@@ -129,12 +129,12 @@ the callback is invoked one last time with `null` for `quad`
|
|
|
129
129
|
and a hash of prefixes as third argument.
|
|
130
130
|
<br>
|
|
131
131
|
|
|
132
|
-
Alternatively, an object can be supplied
|
|
132
|
+
Alternatively, an object can be supplied with named callbacks for quads, prefixes, comments, and token processing:
|
|
133
133
|
```JavaScript
|
|
134
134
|
const parser = new N3.Parser();
|
|
135
135
|
|
|
136
136
|
parser.parse(tomAndJerry, {
|
|
137
|
-
// onQuad (
|
|
137
|
+
// onQuad (optional) receives errors, quads, and completion
|
|
138
138
|
onQuad: (err, quad) => { console.log(quad); },
|
|
139
139
|
// onPrefix (optional) accepts a listener of type (prefix: string, iri: NamedNode) => void
|
|
140
140
|
onPrefix: (prefix, iri) => { console.log(prefix, 'expands to', iri.value); },
|
|
@@ -143,6 +143,17 @@ parser.parse(tomAndJerry, {
|
|
|
143
143
|
});
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
+
`onToken(token)` runs immediately before a lexer token is processed, and
|
|
147
|
+
`onTokenEnd(token)` runs immediately afterwards, including when processing throws.
|
|
148
|
+
|
|
149
|
+
```JavaScript
|
|
150
|
+
const tokens = [];
|
|
151
|
+
const quads = parser.parse('<a> <b> "hello"@en.', {
|
|
152
|
+
onToken: token => tokens.push(token),
|
|
153
|
+
onTokenEnd: token => { /* Finish per-token bookkeeping here. */ },
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
146
157
|
If no callbacks are provided, parsing happens synchronously returning an array of quads:
|
|
147
158
|
|
|
148
159
|
```JavaScript
|
|
@@ -464,6 +475,39 @@ The store provides the following search methods
|
|
|
464
475
|
- `getGraphs` returns an array of unique graphs occurring in matching quad
|
|
465
476
|
- `forGraphs` executes a callback on unique graphs occurring in matching quads
|
|
466
477
|
|
|
478
|
+
### Configuring `match()` semantics
|
|
479
|
+
|
|
480
|
+
The behaviour of `match()` can be configured as a store-wide default or per-call as follows:
|
|
481
|
+
|
|
482
|
+
```JavaScript
|
|
483
|
+
import { Store, DataFactory } from 'n3';
|
|
484
|
+
const { namedNode } = DataFactory;
|
|
485
|
+
|
|
486
|
+
const store = new Store([], { matchSemantics: 'snapshot' });
|
|
487
|
+
const snapshot = store.match(namedNode('s'));
|
|
488
|
+
const forwarded = store.match(namedNode('s'), null, null, null, { matchSemantics: 'forwarded' });
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
Supported values:
|
|
492
|
+
|
|
493
|
+
- `'lazy'` (default) — the view (return value of `Store#match`) reflects the
|
|
494
|
+
parent store until the first operation that materializes it (a mutation, or a
|
|
495
|
+
materializing read such as `size` or `has`), after which it is frozen to a
|
|
496
|
+
snapshot. Parent mutations made before that point remain visible in the view.
|
|
497
|
+
In the next major version, only mutating operations will materialize a lazy
|
|
498
|
+
view.
|
|
499
|
+
- `'snapshot'` — the view reflects the parent contents *at the time of*
|
|
500
|
+
`match()`. Later parent mutations never affect it. This is the most
|
|
501
|
+
spec-correct interpretation of an RDF/JS dataset and will become the default
|
|
502
|
+
in the next major version.
|
|
503
|
+
- `'forwarded'` — the view always reflects the parent state, and mutations to the view are written through to the parent. Attempts to mutate on the view which do not match the views `#match` pattern result in an error.
|
|
504
|
+
|
|
505
|
+
A sub-view inherits its parent's `matchSemantics`.
|
|
506
|
+
|
|
507
|
+
For `'snapshot'` and `'forwarded'`, an iteration (synchronous or via the
|
|
508
|
+
stream) that is already in progress keeps a stable view of the quads as of when it started.
|
|
509
|
+
|
|
510
|
+
|
|
467
511
|
## Reasoning
|
|
468
512
|
|
|
469
513
|
N3.js supports reasoning as follows:
|