Skip to main content

Crate rete_wasm

Crate rete_wasm 

Source
Expand description

Browser bindings: load a .rete file’s bytes (e.g. from fetch) and query it entirely in the browser — the same engine the native CLI uses, compiled to wasm. Results come back as JSON strings.

Structs§

Graph
A .rete opened once and kept resident, so a client (the playground’s cached/in-memory mode) can run many queries on a big file without re-copying the whole buffer into wasm and re-decoding its dictionary on every call. The methods mirror the free functions above but operate on the already-open Rete. The few index-free readers (schema_packed, progressive_query, check_schema) stay free functions — they read small ranges from the buffer and are called rarely (once at load / on demand), so a handle buys little.
QuadCursor
QueryRows
A lazy, resumable cursor over the quads of an open .rete — the engine side of for await (const [s, p, o, g] of graph.dump()) in the JS client.
RemoteGraph
A remote .rete opened once over HTTP range and kept resident in the worker, so repeated queries on the same URL reuse (a) the block cache — any 64 KiB block fetched once is served from memory by BlockCacheReader — and (b) the lazily faulted index tiles + decoded dictionary chunks that live inside the resident Rete. The free sparql_url re-opens the file on every call, so its block cache dies after one query; this handle keeps it. The counting reader stays reachable so the worker can read cumulative bytes/requests and show how little a cache-hit query actually fetched. Worker-only (synchronous range-read XHR).

Constants§

COHERENCE_CONSTRUCT
The fixed, selective coherence subgraph for reason_construct_url (Tier-1). A UNION of constant-predicate branches: each routes to exactly one predicate’s index tiles, so the client faults only rdf:type + the class/ equality T-Box predicates over one warm lazy cache — not the whole graph.
JSON_SCHEMA_VERSION
Version of Rete-owned JSON object envelopes exposed by the browser API.

Functions§

__start
Module init: route Rust panics to console.error with their message and location. In release wasm a panic otherwise aborts as a bare RuntimeError: unreachable with no clue where — this turns that into a rete-wasm panic: panicked at '…', src/…:line line in the devtools console, so an intermittent first-query crash (e.g. a parser tripping on a flaky range read) can actually be diagnosed.
build
Build a complete .rete file image from RDF text, entirely in the browser.
build_bytes
build_with_card_syntax for input held as bytes: any text format (UTF-8, as text would be) or "jelly", the binary Jelly RDF stream format, which has no text form and so cannot go through the &str builders. Same card and quoted-triple rules, same file out. The Jelly reader is the one rete build uses (rete_core::ingest::parse_jelly_bytes); the whole file must be in memory, as every browser build is.
build_with_card
build, but the file carries a Dataset Card written from card_json — the same document rete build --card-file takes, validated by the same rules (rete_core::card::validate_curated_card), so a card authored in the browser is one the CLI would also have accepted.
build_with_card_syntax
build_with_card, reading Turtle/TriG << … >> in the named surface — the browser half of rete build --quoted-triple-syntax, same two values:
build_with_derived_card
build_with_card, but the card also carries the auto-derived profile — the half a browser build used to have to do without (#152).
card
The embedded Dataset Card — the file’s own self-description (title, description, license, provenance, counts, example queries) as the JSON text it was written with, or undefined when the file carries none. Reads the metadata section straight out of the buffer.
card_and_build
card_and_build_url for an image already in memory — no I/O at all.
card_and_build_url
The Dataset Card and the build record of a remote .rete, in the same budget as the card alone: one header read, then one coalesced range covering both sections — the writer lays the kind-7 build-info immediately after the metadata precisely so this holds (rete_core::range::read_card_and_build_info_ranged, pinned by a rete-core test). Reading the two separately would have made the CARD tier cost three requests instead of two, which is why there is one export rather than a second build_info_url.
card_url
The embedded Dataset Card of a remote .rete, in two small range requests: the header, then the metadata section it points at — never the dictionary, index, or pyramid. This is the index-free CARD tier: a client learns what a multi-gigabyte graph is for a few KB. undefined when the file carries no card. Worker-only (synchronous XHR).
check_schema
Index-free schema coherence (Tier-0) over an in-memory .rete: read only the header + pyramid-meta (never the dictionary or the triple index) and report schema-level incoherent points (subClassOf cycles, unsatisfiable classes). Errors if the file ships no schema pyramid.
check_schema_url
Index-free schema coherence (Tier-0) over a remote .rete URL. Reads only TWO ranges — the header and the trailing schema block (the header records its length) — never the dictionary, the community summary, or the triple index. So it’s a flat ~1–8 KB at any graph size (8.1 KB of a 48.8 MB file; see docs/BENCHMARK.md), making it the cheap “is the ontology coherent?” gate. Worker-only (synchronous XHR); a failed range fetch is an error, never a false “coherent”.
communities
Recompute the Louvain community decomposition and report, per community, its member-subject count and triple count. Powers the “split by community” strategy view in the playground. JSON: [{ "community": N, "size": M, "triples": K }, ...], ordered by community id.
file_layout
The file’s byte layout, for the playground’s byte-map view. JSON: { "fileLength": N, "segments": [ { "kind", "label", "offset", "len" } ] } — segments sorted by offset; uncovered bytes are container framing.
file_len_url
The true byte length of a remote .rete, in 1–2 tiny range requests — derived from the file’s own header (the issue-#95 probe: sections are back-to-back and the file ends with the 4-byte RETE footer), never from the transport’s numbers, which may describe a compressed representation (GitHub Pages HEADs a 71 MB file as its 58 MB gzip) or be hidden from cross-origin JS entirely. This is how a UI can say what “download the whole file” actually costs before committing to it. JSON: { "schemaVersion": 1, "fileLength": <bytes> }. Worker-only (synchronous XHR in the sync build).
forget_local_file
Drop a registration made by register_local_file. Releases this wasm instance’s reference to the Blob; any open handle over it stops working.
graph_names
The named-graph IRIs of a dataset, as a JSON array.
header_ranges
Parse the fixed-size header and report the byte ranges a progressive client needs for the overview — the dictionary and the pyramid summary — plus the (large) index range it can skip, and the metadata (Dataset Card) range. JSON: { "dictOffset","dictLen","pyramidOffset","pyramidLen","indexOffset", "indexLen","metadataOffset","metadataLen" }. The browser fetches bytes 0..HEADER_LEN, calls this, then range-fetches only the dict + pyramid — never the index. A host with its own byte reader (Node over a local file, say) can use metadataOffset/metadataLen to read just the card.
heap_bytes
The wasm linear memory’s current size in bytes — the engine’s high-water mark, since wasm memory grows but never shrinks. Exposed so a host can measure the streaming-dump memory claim instead of trusting it: sample it before and after a full QuadCursor drain and the growth stays flat however many quads went by, where materializing them all does not.
info
Header summary as JSON: { "quads": N, "terms": N, "pyramidLevels": N }.
memory_budget_mb
The memory budget files are opened with, in MiB (0 = no cap): see set_memory_budget_mb.
prefix_search
Prefix-search the label index of an embedded .rete image: the subjects whose label starts with prefix (case-insensitive), as [{"label":…,"subject":…}], capped at limit. Answers from the LABEL_INDEX section, else from an older file’s pyramid-meta label block, with no literal scan. Empty array without one.
progressive_query
Answer a conservative subset of SPARQL exactly from the pyramid summary, without opening the triple index. Unsupported query shapes return an error instead of silently falling back to a full scan.
progressive_query_json
Native-testable implementation for progressive_query.
pyramid_tree
The full community pyramid as a tree — the “cluster of clusters” view. Per dendrogram round (index 0 = finest, last = coarsest), every community with its member-node count, triple count (triples whose subject belongs to it), and its parent community at the next-coarser round (null at the top). JSON: { "rounds": N, "levels": [ [ { "id", "nodes", "triples", "parent" } ] ] }.
query
Run any SPARQL form (SELECT / ASK / CONSTRUCT / DESCRIBE) and serialize the result for the playground. Returns a JSON string the page parses; a "kind" field ("select"|"ask"|"construct") tells the UI how to render it.
query_communities
Evaluate a SELECT with the community-split strategy: every basic graph pattern is decomposed into subject stars, each star is evaluated per pyramid community (the members pushed in as a VALUES binding), and the stars are recombined with global hash joins — so multi-hop joins work and cross-community solutions survive. FILTER / UNION / OPTIONAL / MINUS recurse; paths and GRAPH blocks evaluate globally inside the split; GROUP BY / ORDER BY / LIMIT / DISTINCT run once on the merged rows. Answers are identical to query’s. Refused only when nothing in the query can split (no BGP with a variable subject) or for FROM / FROM NAMED. JSON: the SELECT envelope plus "communities": [{ "community", "subjects", "rows" }, …] (rows contributed per community across all split stars).
query_sparql
Run a SPARQL SELECT; returns a JSON array of solution objects ({ "var": "value", ... }).
query_triples
Evaluate a triple pattern; null/undefined positions are wildcards. Returns a JSON array of [subject, predicate, object] triples.
reach
Multi-source transitive reachability over one relation, run serially (the browser engine is single-threaded — the native CLI’s rete reach --parallel fans one task per seed). For each seed, the set of nodes it transitively reaches; with reverse, the set that reaches it (impact analysis).
reach_url
Multi-source reachability over a remote .rete URL (lazy HTTP range reads): builds adjacency for predicate by faulting only that predicate’s tiles, then BFS from each seed. Worker-only (synchronous XHR).
reason
Run the OWL RL / RDFS reasoner over an in-memory .rete and report the inferred-triple count plus any incoherent points (logical contradictions). graph selects a named graph; the default graph is used when omitted. This is the complete (Tier-2) check — it materializes the whole graph. Returns the reasoning_json envelope (no remote block).
reason_construct_url
Selective (Tier-1) coherence check over a remote .rete: evaluate a CONSTRUCT (touching only the tiles its constant-predicate patterns need), then reason over just that subgraph. Pass COHERENCE_CONSTRUCT for the standard class/equality coherence slice, or a custom CONSTRUCT to scope the check further. Unlike reason_url (which materializes the whole graph), this fetches only the slice the CONSTRUCT selects. Worker-only (synchronous XHR).
reason_url
Run the reasoner over a remote .rete URL — the complete (Tier-2) check. It materializes the whole graph, so this faults in the dataset’s chunks/tiles as it reads (≈ the whole file); use reason_construct_url for the cheaper selective check. Worker-only (synchronous XHR). A failed range fetch mid-read is an error, never a silently-incomplete (and thus possibly false “coherent”) result. JSON adds "remote": { fileLength, bytes, requests }.
register_local_file
Register a local File/Blob under a rete-local:… URL, so every *_url entry point can range-read it.
schema
The ontology profile (the semantic coarse graph), as JSON: { "classes": [["<iri>", count], ...], "relations": [["sClass","pred","oClass", count], ...] }. The “overview first” payload — render it before fetching any detail.
schema_packed
Read the baked schema pyramid (classes + class-level relations) straight from the file’s schema block via a slice reader — no triple scan. The in-memory twin of schema_url: a cached big graph gets its schema from a few KB of the buffer instead of dumping every triple (seconds on a 150 MB file). Errors when the file carries no schema pyramid, so callers fall back to the scanning schema.
schema_url
The schema summary (classes + relations) read from the schema pyramid over HTTP range — a Schema view of a remote graph without downloading it. Worker-only (synchronous XHR). JSON: { "kind":"schema", "classes":[[iri,count]], "relations":[[s,p,o,count]], "remote":{…} }.
set_memory_budget_mb
Set the memory budget of every remote (lazily read) file opened from now on, in MiB. It caps the caches of decoded dictionary chunks, decoded index tiles and raw file blocks; what is evicted is read again when a query touches it, so the budget trades speed for memory and never changes an answer. 0 removes the cap. The default is 1024.
shacl
Validate a .rete graph against SHACL Core shapes written in Turtle.
shacl_construct_url
Chain a SPARQL subset, then SHACL over it. Evaluates a CONSTRUCT over the remote .rete (touching only the tiles its patterns need), then validates the resulting subgraph against the Turtle shapes. Where shacl_url selects by shape target (validate every Person…), this selects by an explicit CONSTRUCT — “validate just the slice this query carves out, in place”. Worker-only (synchronous XHR).
shacl_url
Validate a remote .rete graph (lazy HTTP range reads) against SHACL Core shapes written in Turtle. Validating the default graph routes every lookup as a range read (ReteGraph), so a targeted shape faults only the tiles holding its targets — not the whole graph. A named graph (graph) still materializes (the routed view is default-graph only). Worker-only (sync XHR).
sparql_url
summary_overview
Build the coarse-graph overview from a buffer in which only the header, dictionary, and pyramid-summary ranges are populated — the index region may be absent (zero-filled), because the summary path provably never reads it (see the ranged test in rete-core). Returns JSON: { "round", "communities", "predicateTotals": [["<iri>", count], ...] }. This is the “overview first, drill down later” payload, fetched in ~3 ranges.
text_search
Full-text (word/CONTAINS) search over an embedded .rete image: the subjects whose literals contain every word in words (whole-word, case-insensitive — AND), optionally also a word starting with contains_prefix, as [{"subject":…}], capped at limit. Answers from the TEXT_INDEX section. Empty array when the file has none (build --text-index).
validate_card
Check a curated card document without building anything — so an editor can report the exact error rete build --card-file would report, while the author is still typing. Returns the empty string when the document is valid, otherwise the error message.
why_triples
Explain why each triple-pattern match is present in the .rete file.
why_triples_json
Native-testable implementation for why_triples.
why_url
Triple-pattern provenance over a remote .rete URL (lazy range reads): which permutation/section/byte-ranges answer the pattern. Worker-only.