[][src]Struct flashtext::KeywordProcessor

pub struct KeywordProcessor { /* fields omitted */ }

Struct which represents the state

Methods

impl KeywordProcessor[src]

pub fn new(case_sensitive: bool) -> KeywordProcessor[src]

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

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

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

pub fn add_keywords(&mut self, word: &str, clean_name: &str)[src]

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

pub fn find_keywords(&self, input: &str) -> HashSet<String>[src]

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

pub fn replace_keywords(&mut self, input: &str) -> String[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.