poetrie 3.0.1

Poetic trie crafted with intention to ease searching of rhymes for poems.
Documentation

POETRIE

Poetrie means poetic trie. Poetrie is designated for searching common suffixes of words.

Usage

Note configuration to match behavior communicated via MatchConduct structure.

let mut poetrie = Poetrie::nw();
let words = [
    "analytics",
    "metrics",
    "ethics",
    "Acoustics",
    "antics",
    "topics",
    "anticruelty",
]
.map(Key::new_from_str)
.map(Option::unwrap);

for w in words {
    poetrie.it(&w);
}

let mc = MatchConductShaper::init()
    .max_n(usize::MAX) // unlimited matches count
    .max_sl(3) // only 'ics' or less but not '…rics'
    .max_ml(8) // only 8 or less length matches
    .form()
    .unwrap();

let probe = Key::new_from_str("lyrics").unwrap();
let matchee = poetrie.sx(&probe, &mc);

let confirmation: HashSet<String> =
    ["ethics", "antics", "topics"].map(String::from).into();

let matchee = matchee.unwrap_or_default();
for m in matchee.iter() {
    assert!(confirmation.contains(m));
}
assert_eq!(confirmation.len(), matchee.len());

let mc = MatchConduct::default();

let probe = Key::new_from_str("anticruelty").unwrap();
assert_eq!(Err(FindErr::OnlyKeyMatches), poetrie.sx(&probe, &mc));

let probe = Key::new_from_str("solemn").unwrap();
assert_eq!(Err(FindErr::NoJointSuffix), poetrie.sx(&probe, &mc));

Thinking about what could be good rhyming with word of choice, simple try search for that suffix directly. Let say, having "lyrics" as word without match, thinking it should rhyme with something ending with "ynx".

let mut poetrie = Poetrie::nw();
let words = ["lynx", "index"].map(Key::new_from_str).map(Option::unwrap);

for w in words {
    poetrie.it(&w);
}

let probe = Key::new_from_str("ynx").unwrap();
let mc = MatchConduct::default();
let matchee = poetrie.sx(&probe, &mc);

assert_eq!(Ok(vec![String::from("lynx")]), matchee);

Now, one goes: "As the paws in a snow, laid down by lightening lynx, my word goes there and forth, composing the aerial lyrics.".

Note on Letter Case

Poetrie is and ever will be case sensitive. That means that 'MacArthur' and 'macarthur' are different tree entries. Same would apply to 'DeLuca', 'DiCarlo', 'LaRoche', 'O’Brien' or 'De la Cruz' and same surnames with different letter case.

Letter case is taken from search key and for that reason it could be needed to experiment with capitalization. This is user responsibility.