pub struct DictionaryBuilder { /* private fields */ }Expand description
Builds a Dictionary from observed (subject, predicate, object) terms.
Terms are deduped with HashSet during ingest (O(1) average insert, no tree
rebalancing) and sorted once in Self::build. This replaces a trio of
BTreeSet<String> whose per-insert O(log n) cost + a String allocation
for every observed term (most of them duplicates) dominated the build on
large graphs.
Implementations§
Source§impl DictionaryBuilder
impl DictionaryBuilder
Sourcepub fn new() -> DictionaryBuilder
pub fn new() -> DictionaryBuilder
A builder with the process-wide writer settings
(crate::write_opts::frequent_objects).
Sourcepub fn with_frequent_objects(self, n: usize) -> DictionaryBuilder
pub fn with_frequent_objects(self, n: usize) -> DictionaryBuilder
Promote the n most frequent object-only terms (by the number of
statements that carry them as object; ties by term order) into the
shared section (0 = off, the default).
The shared section is numbered first and in term order, so a promoted vocabulary term (a class, a scheme individual, a status literal) gets a small object id wherever it sorts ahead of the shared entities — the effect declaring the vocabulary in a TBox has, without the TBox. A promoted term keeps its object id role; the subject id it also gets is simply never used by any statement. Readers need nothing new: the shared section has always been looked up first for both roles.
Set it before the first Self::observe: promotion counts objects as
they are observed.
Sourcepub fn observe(&mut self, subject: &str, predicate: &str, object: &str)
pub fn observe(&mut self, subject: &str, predicate: &str, object: &str)
Record one triple’s terms (IDs are assigned later, in Self::build).
We probe with the borrowed &str first and only allocate a String for
a genuinely new term — so a graph of N triples does far fewer than 3N
allocations (each subject/predicate recurs across many triples).
Sourcepub fn observe_graph(&mut self, graph: &str)
pub fn observe_graph(&mut self, graph: &str)
Record a graph name as a term in the subject role — how the quad index (SPEC.md §6.5) makes graph names dictionary ids. It lands in the shared section when the name is also an object, else in the subject-only section.