Elamur Groupants⌕
☰

wordgraph-graph

The groupant beside wordgraph/src/graph.rs in the Mova repository: what the code computes, what it never does, how to go back from its outputs, its invariants, cost and checks.

Facts

Implementation material. A Mova code model describes this code at one source revision: partial models, finite checks and their stated scope. It is not a reviewed general exposition, and its labels are shown as written, never raised.

Components

componentlabelwhere
ApproximantpartialApproximant
Astpartialsyntax.json
CompositionpartialComposition
CostpartialCost
DescriptantpresentDescriptant
InvariantpartialInvariant
Testsexecuted bounded checksTests

Obernants

The typed relations around the forward model: the behaviour complement (what the code never does), the reverse reconstruction (every input compatible with an output) and specialised views.

relationtypelabelwhere
Behavior complementbehavior complementpartial source derived modelBehavior complement
Reverse reconstructionreverse reconstructionpartial source derived modelReverse reconstruction

Model text

Descriptant

The graph file format (21 little-endian, 8-aligned sections: nodes, relation codes, forward and reverse CSR, OOV strings, provenance) with its Writer, and the zero-copy reader Graph (an Arc over a memory map or a byte buffer; Clone + Send + Sync) with the queries: node lookup, ranked neighbours, edge, plausibility, plausibility with the isa back-off, and the writer's hint rank. Designed to be shared by threads of one process (the Owls, later).

Approximant

open: validate magic, section table bounds, presence of all 21 sections, length agreement, monotone CSR offsets with correct ends, edge targets < N and group relations < R. edges(n, r, d) = the group of n with code r, in stored order. edge(h, r, d) = forward lookup in h, else reverse lookup in d. plausibility = PMI of that edge or 0. plausibility_isa = direct PMI, else max over the first 8 isa parents p of d of 0.5·plausibility(h, r, p). rank sorts candidates by (score desc, freq desc, node asc).

Invariant

Every accessor reads in bounds after a successful open (offsets checked once). Quantization: PMI q = round(16·pmi) clamped to 1..255 (monotone, error ≤ 1/32 bit within range); count q = round(8·log2 c), back-transform within 5 %. Nodes sorted by (word, UPOS), so a word's nodes are a contiguous range. The file is never written in place.

Cost

open O(N + G + E) checks (50 k graph: 38 MB, a CLI query 7 ms wall, 2026-11-06); node lookup O(log N) + one dictionary probe; edges O(groups of n + bound); edge O(bound) each way; rank O(|cands|·8·bound).

Composition

Written by compile; read by eval, the CLI, and future in-process users. Uses rel for codes and extract::OOV_TAG.

Tests

graph_is_shareable (compile-time Send + Sync + Clone), quantization_is_monotone_and_bounded, corrupt_files_are_rejected (bad magic, edge target out of range, truncation: red side).

Behavior complement

Does not mutate, append to, or lock the file; does not verify the provenance JSON or the dictionary fingerprint against the running binary; does not handle a file truncated after open (mmap: SIGBUS); does not disambiguate senses beyond UPOS; returns 0 plausibility for absent pairs (no negative evidence).

Reverse reconstruction

From query answers one recovers the stored edges, quantized PMI and approximate counts; from a 0 plausibility, nothing (any of the absences listed in compile's model). The section layout is invertible: Writer::finish and Graph::new are mutually consistent on all arrays (checked by the hand-built file test).

Provenance

This page in Markdown → https://md.groupants.elamur.ai/free/en/mova/wordgraph/src/graph.rs.groupant/