Skip to main content

MyStem

Struct MyStem 

Source
pub struct MyStem {
    pub process: Popen,
}
Expand description

A Mystem process representation

Fields§

§process: Popen

Implementations§

Source§

impl MyStem

Source

pub fn new() -> Result<Self, AppError>

Returns a MyStem instance with running process of mystem binary. It keeps mystem running all the time and reuse it.

Examples found in repository?
examples/test.rs (line 7)
6fn main() -> Result<(), mystem::AppError> {
7    let mut instance = mystem::MyStem::new()?;
8    for stem in instance.stemming("Связался с лучшим - подохни как все, Говноед.".into())?
9    {
10        println!(
11            "'{}' most likely is a '{}' and lexeme is '{}'.{}{}",
12            stem.text,
13            stem.lex[0].grammem.part_of_speech,
14            stem.lex[0].lex,
15            {
16                match stem.lex[0]
17                    .grammem
18                    .facts
19                    .contains(&mystem::Fact::Other(Obscene))
20                {
21                    true => " Obscene lexis.",
22                    false => "",
23                }
24            },
25            {
26                match stem.lex.len() {
27                    0 | 1 => "".to_string(),
28                    x if x > 1 => format!(" Also has {} found lexems.", x),
29                    _ => unreachable!(),
30                }
31            }
32        )
33    }
34    instance.terminate();
35    Ok(())
36}
Source

pub fn terminate(&mut self) -> Result<(), Error>

Terminate mystem instance.

Examples found in repository?
examples/test.rs (line 34)
6fn main() -> Result<(), mystem::AppError> {
7    let mut instance = mystem::MyStem::new()?;
8    for stem in instance.stemming("Связался с лучшим - подохни как все, Говноед.".into())?
9    {
10        println!(
11            "'{}' most likely is a '{}' and lexeme is '{}'.{}{}",
12            stem.text,
13            stem.lex[0].grammem.part_of_speech,
14            stem.lex[0].lex,
15            {
16                match stem.lex[0]
17                    .grammem
18                    .facts
19                    .contains(&mystem::Fact::Other(Obscene))
20                {
21                    true => " Obscene lexis.",
22                    false => "",
23                }
24            },
25            {
26                match stem.lex.len() {
27                    0 | 1 => "".to_string(),
28                    x if x > 1 => format!(" Also has {} found lexems.", x),
29                    _ => unreachable!(),
30                }
31            }
32        )
33    }
34    instance.terminate();
35    Ok(())
36}
Source

pub fn stemming(&mut self, text: String) -> Result<Vec<Stemming>, AppError>

Returns Vec with mystem::Stemming for each word in text

§Examples
    let mut instance = mystem::MyStem::new()?;
    for stem in instance.stemming("Связался с лучшим - подохни как все.".into())? {
        println!("{} is a lexeme of {}", stem.lex, stem.text)
    }
    // связываться is a lexeme of Связался
    // с is a lexeme of с
    // хороший is a lexeme of лучшим
    // подыхать is a lexeme of подохни
    // как is a lexeme of как
    // все is a lexeme of все
Examples found in repository?
examples/test.rs (line 8)
6fn main() -> Result<(), mystem::AppError> {
7    let mut instance = mystem::MyStem::new()?;
8    for stem in instance.stemming("Связался с лучшим - подохни как все, Говноед.".into())?
9    {
10        println!(
11            "'{}' most likely is a '{}' and lexeme is '{}'.{}{}",
12            stem.text,
13            stem.lex[0].grammem.part_of_speech,
14            stem.lex[0].lex,
15            {
16                match stem.lex[0]
17                    .grammem
18                    .facts
19                    .contains(&mystem::Fact::Other(Obscene))
20                {
21                    true => " Obscene lexis.",
22                    false => "",
23                }
24            },
25            {
26                match stem.lex.len() {
27                    0 | 1 => "".to_string(),
28                    x if x > 1 => format!(" Also has {} found lexems.", x),
29                    _ => unreachable!(),
30                }
31            }
32        )
33    }
34    instance.terminate();
35    Ok(())
36}

Trait Implementations§

Source§

impl Debug for MyStem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.