pub struct Lexicon { /* private fields */ }Expand description
Small, controlled, SFW lexicon by POS. IMPORTANT: ensure cover lexicon does NOT contain any payload (BIP39) words, so decoding (filtering BIP39 words) is trivial and unambiguous.
Implementations§
Source§impl Lexicon
impl Lexicon
pub fn new(payload_set: HashSet<String>, wordlist_set: HashSet<String>) -> Self
Sourcepub fn with_semantics(self, model: Arc<SemanticModel>) -> Self
pub fn with_semantics(self, model: Arc<SemanticModel>) -> Self
Attach a semantic model for coherence-biased sentence planning.
Sourcepub fn semantics(&self) -> Option<&SemanticModel>
pub fn semantics(&self) -> Option<&SemanticModel>
The attached semantic model, if any.
pub fn with_words(self, pos: Pos, words: &[&str]) -> Self
Sourcepub fn with_refined_cover(
self,
refined_cover: HashMap<(Pos, String), Vec<String>>,
) -> Self
pub fn with_refined_cover( self, refined_cover: HashMap<(Pos, String), Vec<String>>, ) -> Self
Set the refined cover word map (populated from cover.yaml refinement tags).
Sourcepub fn with_refined_payload(
self,
refined_payload: HashMap<String, HashSet<String>>,
) -> Self
pub fn with_refined_payload( self, refined_payload: HashMap<String, HashSet<String>>, ) -> Self
Set the refined payload word map for type-level validation.
Sourcepub fn payload_valid_for_refinement(
&self,
word: &str,
refinement: Option<&str>,
) -> bool
pub fn payload_valid_for_refinement( &self, word: &str, refinement: Option<&str>, ) -> bool
Check if a payload word is valid for a given refinement tag. Returns true if:
- No refinement tag is specified (no constraint)
- No refined_payload entry exists for the tag (no constraint data available)
- The word is in the refined_payload set for the tag
pub fn pick_cover<R: Rng>( &self, rng: &mut R, pos: Pos, recent_words: &[&str], ) -> String
Sourcepub fn pick_cover_filtered<R: Rng, F: Fn(&str) -> bool>(
&self,
rng: &mut R,
pos: Pos,
recent_words: &[&str],
predicate: F,
) -> Option<String>
pub fn pick_cover_filtered<R: Rng, F: Fn(&str) -> bool>( &self, rng: &mut R, pos: Pos, recent_words: &[&str], predicate: F, ) -> Option<String>
Like pick_cover, but allows an additional predicate to enforce lightweight grammar constraints
(e.g., “bare verb after Modal”, “transitive verb before NP”).
Returns None if no word satisfies the predicate (caller should fall back to pick_cover).
Sourcepub fn pick_cover_with_prime_constraint<R: Rng>(
&self,
rng: &mut R,
pos: Pos,
recent_words: &[&str],
left_word: Option<&str>,
right_word: Option<&str>,
) -> Option<String>
pub fn pick_cover_with_prime_constraint<R: Rng>( &self, rng: &mut R, pos: Pos, recent_words: &[&str], left_word: Option<&str>, right_word: Option<&str>, ) -> Option<String>
Pick cover word with prime ordering constraint for math/primes language. Cover word must be: left_prime < cover_word < right_prime Cover word must be a non-prime integer.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Lexicon
impl RefUnwindSafe for Lexicon
impl Send for Lexicon
impl Sync for Lexicon
impl Unpin for Lexicon
impl UnsafeUnpin for Lexicon
impl UnwindSafe for Lexicon
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more