pub struct KeywordProcessor { /* private fields */ }
Expand description
Struct which represents the state
Implementations§
Source§impl KeywordProcessor
impl KeywordProcessor
Sourcepub fn new(case_sensitive: bool) -> KeywordProcessor
pub fn new(case_sensitive: bool) -> KeywordProcessor
Sourcepub fn add_keyword(&mut self, word: &str)
pub fn add_keyword(&mut self, word: &str)
Sourcepub fn add_keywords(&mut self, word: &str, clean_name: &str)
pub fn add_keywords(&mut self, word: &str, clean_name: &str)
Takes a keyword/sentence to replace another keyword/sentence
§Arguments
word
- The keyword/sentence to replaceclean_name
- The keyword/sentence to replace with
§Example
use flashtext::KeywordProcessor;
let mut keywordprocessor = KeywordProcessor::new(false);
keywordprocessor.add_keywords("keyword", "new_keyword");
Sourcepub fn find_keywords(&self, input: &str) -> HashSet<String>
pub fn find_keywords(&self, input: &str) -> HashSet<String>
Returns a HashSet
of String if a given keyword/sentence exists in the input string
§Arguments
input
- A string slice which holds the input string in which keyword are to be searched or replaced
§Example
use flashtext::KeywordProcessor;
use std::collections::HashSet;
let mut keywordprocessor = KeywordProcessor::new(false);
keywordprocessor.add_keyword("programming");
let result = keywordprocessor.find_keywords("Rust is a systems programming language");
let mut expected = HashSet::new();
expected.insert("programming".to_string());
assert_eq!(result, expected);
Sourcepub fn replace_keywords(&mut self, input: &str) -> String
pub fn replace_keywords(&mut self, input: &str) -> String
Returns a String after replacing keywords in input specified by add_keywords
§Arguments
input_str
- A string slice which holds input string in which keywords are needed to be replaced
§Example
use flashtext::KeywordProcessor;
let mut keywordprocessor = KeywordProcessor::new(false);
keywordprocessor.add_keywords("Alice", "Bob");
let result = keywordprocessor.replace_keywords("Alice likes to read a book");
let expected = String::from("Bob likes to read a book");
assert_eq!(result, expected);
Auto Trait Implementations§
impl Freeze for KeywordProcessor
impl RefUnwindSafe for KeywordProcessor
impl Send for KeywordProcessor
impl Sync for KeywordProcessor
impl Unpin for KeywordProcessor
impl UnwindSafe for KeywordProcessor
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
Mutably borrows from an owned value. Read more