Struct stemmer::Stemmer
[−]
[src]
pub struct Stemmer { /* fields omitted */ }
Methods
impl Stemmer
[src]
fn list() -> Vec<&'static str>
Lists all existing algorithms, returning a vector of valid algorithms
that can be used as argument for Stemmer::new
fn new(algorithm: &str) -> Option<Stemmer>
Creates a new stemmer, provided algorithm
is a valid one.
Arguments
algorithm
: the name of a stemming algorithm. A list of supported algorithms can be obtained withStemmer::list()
Returns
Some(Stemmer)
ifalgorithm
exists;None
otherwise.
Examples
use stemmer::Stemmer; let stemmer = Stemmer::new("english"); assert!(stemmer.is_some());
use stemmer::Stemmer; let stemmer = Stemmer::new("foobar"); assert!(stemmer.is_none());
fn stem(&mut self, word: &str) -> String
Stems the word
.
Returns an owned string containing the stemmed version of the word.
Example
use stemmer::Stemmer; let mut stemmer = Stemmer::new("french").unwrap(); assert_eq!("éternu", &stemmer.stem("éternuerai"));
fn stem_str(&mut self, word: &str) -> &str
Stems the word and returns a str
The str
reference it returns is only valid as long as you don't
call stem
or stem_str` again; thus, Rust's borrowchecker won't let
call one of them function if you have such a reference in scope.
Example
use stemmer::Stemmer; let mut stemmer = Stemmer::new("english").unwrap(); println!("{}", stemmer.stem_str("foo")); println!("{}", stemmer.stem_str("bar")); // ok println!("{}", stemmer.stem("baz")); // ok too let foo: &str = stemmer.stem_str("foo"); // stemmer.stem("bar"); -> Compiler error because `stemmer` is already borrowed by `foo`