rete-graph 0.3.2 → 0.3.4
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 +73 -5
- package/dist/index.js +846 -26
- package/dist/rete-graph.js +847 -27
- package/dist/rete-graph.min.js +6 -6
- package/dist/rete_wasm_bg.wasm +0 -0
- package/index.d.ts +129 -3
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ for (const row of g.query("SELECT ?s ?label WHERE { ?s rdfs:label ?label } LIMIT
|
|
|
28
28
|
One self-contained file, engine included — via any npm CDN:
|
|
29
29
|
|
|
30
30
|
```html
|
|
31
|
-
<script src="https://cdn.jsdelivr.net/npm/rete-graph@0.
|
|
31
|
+
<script src="https://cdn.jsdelivr.net/npm/rete-graph@0.3.4/dist/rete-graph.min.js"></script>
|
|
32
32
|
<script>
|
|
33
33
|
(async () => {
|
|
34
34
|
const g = await rete.open(await rete.build("<urn:a> <urn:knows> <urn:b> ."));
|
|
@@ -61,12 +61,80 @@ worker. The host serving the file must send CORS headers and honor `Range`.
|
|
|
61
61
|
`query()` returns `{var: Term}` rows for SELECT, a boolean for ASK, and
|
|
62
62
|
`[s, p, o]` Term triples for CONSTRUCT/DESCRIBE. A `Term` carries `.kind` /
|
|
63
63
|
`.value` / `.datatype` / `.lang`, plus `.toJS()` (number/boolean/BigInt for
|
|
64
|
-
common XSD types) and `.n3`. Also: `queryRaw`, `
|
|
64
|
+
common XSD types) and `.n3`. Also: `queryRaw`, `lastWarnings()` (why a FILTER silently dropped rows:
|
|
65
|
+
CONTAINS on an IRI, STRSTARTS on a number, … — see the docs), `query(q, {reason: true})`
|
|
65
66
|
(OWL 2 QL entailment), `prefixSearch`, `textSearch`, `schema`, `graphNames`,
|
|
66
67
|
`info`, `card()` / `examples()` (the file's embedded Dataset Card and its
|
|
67
|
-
example queries), `shacl(shapes)` (SHACL Core validation),
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
example queries), `shacl(shapes)` (SHACL Core validation), `dump()` /
|
|
69
|
+
`nquads()` / `writeNQuads()` / `toNQuads()` (the streaming export below), and
|
|
70
|
+
on lazily opened graphs `stats()` / `contentHash()`. `wasm` re-exports the raw
|
|
71
|
+
engine for anything this wrapper doesn't wrap.
|
|
72
|
+
|
|
73
|
+
## Streaming the whole graph out
|
|
74
|
+
|
|
75
|
+
`dump()` walks every quad lazily — the engine decodes one triple at a time and
|
|
76
|
+
the wrapper never holds more than a batch of them, so memory does not grow with
|
|
77
|
+
the graph:
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
for await (const [s, p, o, g] of graph.dump()) {
|
|
81
|
+
// g is the graph Term, or null in the default graph
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`dump({graph})` narrows it: omit for the default graph followed by every named
|
|
86
|
+
graph, `null` for the default graph only, an IRI for one named graph.
|
|
87
|
+
`dump({raw: true})` yields the engine's N-Triples tokens instead of `Term`s.
|
|
88
|
+
|
|
89
|
+
For handing a `.rete` to another store, `nquads()` streams ready-made N-Quads
|
|
90
|
+
text (the engine writes the lines; nothing is re-serialized in JavaScript):
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
import { Store } from "oxigraph";
|
|
94
|
+
const store = new Store();
|
|
95
|
+
for await (const chunk of graph.nquads()) store.load(chunk, { format: "application/n-quads" });
|
|
96
|
+
|
|
97
|
+
await graph.writeNQuads(createWriteStream("out.nq")); // Node stream, WritableStream, or fn
|
|
98
|
+
const text = await graph.toNQuads(); // one string — small graphs only
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Under the hood each wasm call hands back **10 000 quads** (`batch`), which the
|
|
102
|
+
generator yields one at a time: one call per quad would make the boundary the
|
|
103
|
+
bottleneck, one call for the graph would rebuild the array these methods exist
|
|
104
|
+
to avoid. `heapBytes()` lets you check the claim rather than take it — the
|
|
105
|
+
engine heap is flat across a full dump, where materializing the same quads with
|
|
106
|
+
`SELECT ?s ?p ?o` costs hundreds of MB (see `test/dump-memory.test.mjs`).
|
|
107
|
+
|
|
108
|
+
This works on **remote graphs too**, with one honest caveat: a full dump
|
|
109
|
+
resolves every term and visits every tile, so it ends up fetching essentially
|
|
110
|
+
the whole file (and the tiles stay cached). It is how you *export* a remote
|
|
111
|
+
graph, not how you peek at one — for that, run a `LIMIT` query.
|
|
112
|
+
|
|
113
|
+
## RDF 1.2 and quoted triples
|
|
114
|
+
|
|
115
|
+
The CLI's `--quoted-triple-syntax` vocabulary and defaults, in both directions:
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
// Reading: what Turtle/TriG `<< s p o >>` means. "rdf-star" (default) = a quoted
|
|
119
|
+
// triple, as before; "rdf12" = RDF 1.2 (`<<( s p o )>>` triple terms, `<< … >>`
|
|
120
|
+
// reifiers, `{| … |}` annotations). N-Triples/N-Quads ignore it.
|
|
121
|
+
await build(ttlText, "ttl", { quotedTripleSyntax: "rdf12" });
|
|
122
|
+
await build(trigText, "trig", { quotedTripleSyntax: "rdf12" });
|
|
123
|
+
|
|
124
|
+
// Writing: the N-Quads writers spell a quoted triple as the RDF 1.2 triple term
|
|
125
|
+
// `<<( s p o )>>` by default — what Oxigraph 0.5 and Jena 5 load. "rdf-star"
|
|
126
|
+
// writes rete's stored `<<s p o>>`. RDF 1.2 has no subject-position triple term,
|
|
127
|
+
// so such a statement makes the stream throw under "rdf12".
|
|
128
|
+
await graph.toNQuads(); // rdf12
|
|
129
|
+
await graph.toNQuads({ quotedTripleSyntax: "rdf-star" });
|
|
130
|
+
|
|
131
|
+
// The card says whether a file holds any — from its header, so old files answer:
|
|
132
|
+
graph.card().signals.quoted_triples;
|
|
133
|
+
// { present: true, export_surfaces: ["rdf12", "rdf-star"], export_default: "rdf12" }
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
`dump()` still yields the stored tokens. A graph with no quoted triples is
|
|
137
|
+
written byte-for-byte the same under either value.
|
|
70
138
|
|
|
71
139
|
## Local files, read lazily (Node)
|
|
72
140
|
|