Fix mystem stdin feed.

This commit is contained in:
AB
2021-01-10 21:16:49 +03:00
parent 82c8e51c94
commit 30ff6a9c46
4 changed files with 14 additions and 8 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "mystem"
version = "0.2.1"
version = "0.2.2"
authors = ["AB <ab@hexor.ru>"]
license = "WTFPL"
edition = "2018"

View File

@ -23,11 +23,10 @@ fn main() -> Result<(), mystem::AppError> {
}
},
{
match stem.lex.len()
{
match stem.lex.len() {
0 | 1 => "".to_string(),
x if x > 1 => format!(" Also has {} found lexems.", x),
_ => unreachable!()
_ => unreachable!(),
}
}
)

View File

@ -10,10 +10,10 @@ use crate::Other::{
Parenthesis, Patronymic, Predicative, ProperNoun, Rare,
};
use crate::PerfectiveAspect::{Imperfective, Perfective};
use crate::Person::{First, Second, Third};
use crate::Plurality::{Plural, Singular};
use crate::Tense::{Inpresent, Past, Present};
use crate::Transitivity::{Intransitive, Transitive};
use crate::Person::{First, Second, Third};
use crate::Voice::{Active, Passive};
use std::fmt;
use std::str::FromStr;

View File

@ -108,14 +108,21 @@ impl MyStem {
);
self.process = MyStem::open_process()?;
}
let clean_text = format!("{}{}", text.trim(), "\n");
let mut clean_text = text.trim().to_string();
for c in clean_text.clone().chars() {
if !char::is_alphabetic(c) && c != ' ' {
clean_text = clean_text.replace(c, "");
}
}
self.process
.stdin
.as_ref()
.unwrap()
.write(clean_text.as_bytes());
self.process.stdin.as_ref().unwrap().write("\n".as_bytes());
let mut contents = String::new();
let mut buf_reader = BufReader::new(self.process.stdout.as_ref().unwrap());
let mut buf_reader =
BufReader::with_capacity(512 * 1024, self.process.stdout.as_ref().unwrap());
buf_reader.read_line(&mut contents);
let mut stemmings: Vec<Stemming> = Vec::new();