Struct auto_correct_n_suggest::Dictionary [−][src]
pub struct Dictionary { /* fields omitted */ }
Expand description
This dictionary will hold all the words/keywords you want to use within your program.
Implementations
impl Dictionary
[src]
impl Dictionary
[src]pub fn new() -> Dictionary
[src]
pub fn new() -> Dictionary
[src]Returns a new dictionary just like the default
method
The dictionary will always be empty at first, but you can add
words to it using the insert
method
Examples
use auto_correct_n_suggest; let mut dictionary = auto_correct_n_suggest::Dictionary::new();
pub fn insert(&mut self, word: String)
[src]
pub fn insert(&mut self, word: String)
[src]Adds a new word to the dictionary
Provide a Word String
to an existing dictionary to add it the dictionary
Arguments
word
- The string to be inserted to the dictionary
Examples
use auto_correct_n_suggest; let mut dictionary = auto_correct_n_suggest::Dictionary::new(); let new_coin = format!("{}", "Dogecoin"); dictionary.insert(new_coin);
pub fn find_words_based_on_prefix(
&mut self,
prefix: String
) -> Option<Vec<String>>
[src]
pub fn find_words_based_on_prefix(
&mut self,
prefix: String
) -> Option<Vec<String>>
[src]This method helps you get the complete words available based on the prefix provided
Arguments
prefix
- A string which represents the prefix of words in the dictionary
It returns None
if there are no suffixes of the prefix provided
Examples
use auto_correct_n_suggest; let mut dictionary = auto_correct_n_suggest::Dictionary::new(); let word1 = "Dog".to_string(); dictionary.insert(word1); let words_available = dictionary .find_words_based_on_prefix("Dog".to_string()) .expect("Words should be present"); assert!(words_available.contains(&"Dog".to_string()));
pub fn auto_suggest_alternative_words(
&mut self,
typo: String
) -> Option<Vec<String>>
[src]
pub fn auto_suggest_alternative_words(
&mut self,
typo: String
) -> Option<Vec<String>>
[src]This method helps you get alternative words based in your dictionary that are similar to the provided word
Arguments
typo
- The mistyped word
It returns None
if no word in the dictionary matches any sequence of characters of the word given.
Examples
use auto_correct_n_suggest; let mut dictionary = auto_correct_n_suggest::Dictionary::new(); let word1 = "Dog".to_string(); let word2 = "Dogecoin".to_string(); dictionary.insert(word1); dictionary.insert(word2); let words_available = dictionary .auto_suggest_alternative_words("Dogecoins".to_string()) .expect("Suggestions should be available"); assert_eq!(vec!["Dogecoin".to_string()], words_available); // In this dictionary there's Cats so there isnt any alternative word for Cat let words_available = dictionary.auto_suggest_alternative_words("Cat".to_string()); assert_eq!(words_available, None);