Expand description
Ingestion: parse RDF text (N-Triples / N-Quads / Turtle) and assemble a
complete .rete file image. Shared by the CLI’s build/validate commands
and the wasm bindings (the playground’s in-browser builder).
The N-Triples/N-Quads reader is line-based and keeps terms as their exact
canonical token strings (<iri>, _:bnode, "lit", "lit"^^<dt>,
"lit"@lang) so they double as dictionary keys and so a query can match
by the same string. This is not a full RDF 1.1 parser — it covers the
canonical N-Triples surface (and is deliberately tolerant of IRIs a strict
parser would reject), enough for v0 ingestion. Turtle goes through oxttl.
That tolerance is measured, not silent: pass an IriAudit to any of the
*_audited entry points and the parse counts every IRI outside the
N-Triples IRIREF grammar / RFC 3987 (see crate::iri) — or, with
strict, refuses the input on the first one. rete build always audits.
Assembly degrades with the build features: without the compression
feature (e.g. on wasm) sections are written with the NONE codec — larger
files, byte-compatible readers.
Structs§
- Build
Stats - Counts describing an assembled file, for status lines and UIs.
- Deferred
Metadata - A metadata payload whose final form needs the written (deduplicated) counts.
See
IntoMetadata. - Final
Counts - The deduplicated counts of the file being written — what the header records, and therefore what any embedded metadata has to report.
- IriAudit
- Policy and tally for the invalid-IRI check that runs during ingest.
Enums§
- Ingest
Error - Why an ingest failed. Parser errors from
oxttl/oxrdfxmland I/O errors are flattened to theirDisplaystring rather than wrapped: the variants then carry no foreign types, which keeps the error usable from the wasm bindings and stable across upstream parser upgrades. - Quoted
Triple Surface - Which surface a
<< … >>in Turtle/TriG input is read as — the input half ofrete export --quoted-triple-syntax, same vocabulary, same two values.
Traits§
- Into
Metadata - What a build’s metadata callback may return.
Functions§
- assemble_
dataset - Assemble a complete
.retefile image from parsed quads: one shared dictionary, the default-graph index, one index per named graph, and the community pyramid.metadatais the opaque metadata-section payload (the CLI puts a JSON Dataset Card there); pass&[]for none — that is byte-identical to a metadata-free build. - assemble_
dataset_ streaming - Two-pass, low-RAM assembly: build a
.reteby streaming the input(s) twice instead of holding every parsed quad in memory.streamis invoked twice and MUST replay the exact same quads in the same order each time — pass 1 observes every term into the dictionary; pass 2 encodes them to id-triples. The raw string quads (every term an owned String, heavily duplicated — by far the largest working set on a big graph) are never collected, so peak RAM is bounded by the dictionary + id-triples + index rather than the string-quad multiset. Output is byte-identical toassemble_dataset_with_optson the same quads (same dictionary, same id-triples in file order, same downstream pipeline). - assemble_
dataset_ streaming_ algo - Like
assemble_dataset_streaming, but selects the communityPyramidAlgo(the streaming, low-RAM build path forrete build --pyramid-algo …). - assemble_
dataset_ streaming_ with_ perms - Like
assemble_dataset_streaming_algo, but writes only the permutations inperms— the two-pass low-RAM twin ofassemble_dataset_with_perms. - assemble_
dataset_ with - Like
assemble_dataset, but the metadata payload is derived from theBuildStatsand the source quads while they are still resident — for metadata that describes the graph (the Dataset Card). Returning an emptyVecis byte-identical to a metadata-free build; return aDeferredMetadatafor a payload that must also carry the file’s deduplicated counts, which exist only once the indexes are built. - assemble_
dataset_ with_ opts - Like
assemble_dataset_with, butwith_pyramid = falseskips the Louvain community pyramid entirely — no pyramid section is written (header length 0). SPARQL / SHACL / triple / reachability queries don’t use the pyramid, so a pyramid-less file is fully queryable and markedly smaller (the pyramid is the largest section on highly-connected graphs). Only the community / summary / progressive paths need it. - assemble_
dataset_ with_ opts_ algo - Like
assemble_dataset_with_opts, but selects the communityPyramidAlgo(the in-memory build path forrete build --pyramid-algo …). - assemble_
dataset_ with_ perms - Like
assemble_dataset_with_opts_algo, but writes only the permutations inperms(rete build --permutations 3). Every other byte of the file is unchanged;crate::index::PermSet::ALLreproduces the default build exactly, down to the header byte. - parse
- Parse N-Triples text into raw term-token triples, skipping blank/comment lines.
- parse_
audited parsewith an optionalIriAudit.- parse_
quads - Parse N-Quads text:
subject predicate object [graph] .per line. - parse_
quads_ audited parse_quadswith an optionalIriAudit.- parse_
rdfxml - Parse RDF/XML into canonical N-Triples-token triples via oxrdfxml. This is how
most OWL ontologies ship (
.rdf/.owl/.xmlwith anrdf:RDFroot) — so rete ingests them directly, no external conversion. (OWL/XML — the non-RDF functional XML serialization — is a different language; convert it with owlready2 first.) - parse_
reader - Stream-parse N-Triples (
"nt") or N-Quads ("nq") from a reader, one line at a time, so the whole input text is never resident — the big-build memory win over reading the file into aStringfirst (each line String is transient, freed every iteration).cappre-sizes the outputVec(e.g.file_len / 64) to avoid reallocation doublings of the large spine. Turtle is not streamable here (oxttl needs the whole input); callers use the text path for"ttl". - parse_
reader_ audited parse_readerwith an optionalIriAudit.- parse_
reader_ audited_ surface parse_reader_auditedreading<< … >>in the givenQuotedTripleSurface(Turtle/TriG only — see the enum).- parse_
statements - Parse one text input by format name (
"nt","nq","ttl","trig", or"rdfxml") into quads (triples land in the default graph). - parse_
statements_ audited parse_statementswith an optionalIriAudit. The line-based syntaxes audit as they parse (sostrictfails on the offending line); the others are audited over the parsed quads, which is whereoxttlhas already had its say.- parse_
statements_ audited_ surface parse_statements_auditedreading<< … >>in the givenQuotedTripleSurface. This is the entry pointrete buildandrete validateuse for everything but a streamed line-based input, and the one that turns “RDF 1.2 file, RDF-star reader” into an error that names the flag instead of a bare syntax complaint.- parse_
trig - Parse TriG into canonical quads via oxttl — Turtle plus named-graph blocks
(
<g> { … }), the shape most large RDF dumps ship in. Reads<< s p o >>as an RDF-star quoted triple;parse_trig_surfacechooses. - parse_
trig_ surface parse_trigin the givenQuotedTripleSurface.- parse_
turtle - Parse Turtle into canonical N-Triples-token triples via oxttl, reading
<< s p o >>as an RDF-star quoted triple.parse_turtle_surfacechooses. - parse_
turtle_ surface parse_turtlein the givenQuotedTripleSurface.- stream_
reader - Stream N-Triples (
"nt") / N-Quads ("nq") from a reader, invokingfonce per parsed quad — likeparse_readerbut without collecting into aVec. Each quad’s term Strings are owned byf(and dropped when it returns if it doesn’t retain them), so a caller that only needs to observe every term — e.g. the two-passassemble_dataset_streamingbuilding its dictionary — never materializes the whole quad multiset. The big-graph, low-RAM ingest primitive. Blank/comment lines are skipped; a parse error stops the stream and is returned. - stream_
reader_ audited stream_readerwith an optionalIriAudit.- stream_
reader_ audited_ surface stream_reader_auditedreading<< … >>in the givenQuotedTripleSurface.