Struct KeywordProcessor

Source
pub struct KeywordProcessor { /* private fields */ }
Expand description

Struct which represents the state

Implementations§

Source§

impl KeywordProcessor

Source

pub fn new(case_sensitive: bool) -> KeywordProcessor

Takes a bool for case sensitivity and returns instance of a KeywordProcessor

§Arguments
  • case_sensitive - A bool which indicates case sensitivity
§Example
 use flashtext::KeywordProcessor;
 let mut keywordprocessor = KeywordProcessor::new(false);
Source

pub fn add_keyword(&mut self, word: &str)

Takes a keyword/sentence to search

§Arguments
  • word - A string slice that holds a keyword/sentence
§Example
use flashtext::KeywordProcessor;
let mut keywordprocessor = KeywordProcessor::new(false);
keywordprocessor.add_keyword("keyword");
Source

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 replace
  • clean_name - The keyword/sentence to replace with
§Example
use flashtext::KeywordProcessor;
let mut keywordprocessor = KeywordProcessor::new(false);
keywordprocessor.add_keywords("keyword", "new_keyword");
Source

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);
Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.