pub struct MyStem {
pub process: Popen,
}Expand description
A Mystem process representation
Fields§
§process: PopenImplementations§
Source§impl MyStem
impl MyStem
Sourcepub fn new() -> Result<Self, AppError>
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}Sourcepub fn terminate(&mut self) -> Result<(), Error>
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}Sourcepub fn stemming(&mut self, text: String) -> Result<Vec<Stemming>, AppError>
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§
Auto Trait Implementations§
impl Freeze for MyStem
impl RefUnwindSafe for MyStem
impl Send for MyStem
impl Sync for MyStem
impl Unpin for MyStem
impl UnsafeUnpin for MyStem
impl UnwindSafe for MyStem
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