#![allow(missing_docs)]
use std::{
fs::File,
io::{BufRead, BufReader},
iter,
path::PathBuf,
};
pub struct Verb {
pub past_light_verb: String,
pub present_light_verb: String,
pub prefix: String,
pub nonverbal_element: String,
pub preposition: String,
pub valency: String,
}
pub struct VerbValencyReader {
path: PathBuf,
}
impl VerbValencyReader {
pub fn new(path: impl Into<PathBuf>) -> Self {
Self { path: path.into() }
}
pub fn verbs(&self) -> Box<dyn Iterator<Item = Verb> + '_> {
let file = match File::open(&self.path) {
Ok(f) => f,
Err(e) => {
eprintln!("VerbValencyReader: cannot open {:?}: {}", self.path, e);
return Box::new(iter::empty());
}
};
let lines: Vec<String> = BufReader::new(file)
.lines()
.filter_map(|l| l.ok())
.collect();
let mut verbs: Vec<Verb> = Vec::new();
for (i, line) in lines.iter().enumerate() {
if line.contains("بن ماضی") {
continue;
}
let processed = line.replace("-\t", "\t");
let cols: Vec<&str> = processed.split('\t').collect();
if cols.len() < 6 {
if i > 0 {
let trimmed = line.trim();
if !trimmed.is_empty() {
}
}
continue;
}
verbs.push(Verb {
past_light_verb: cols[0].to_string(),
present_light_verb: cols[1].to_string(),
prefix: cols[2].to_string(),
nonverbal_element: cols[3].to_string(),
preposition: cols[4].to_string(),
valency: cols[5].to_string(),
});
}
Box::new(verbs.into_iter())
}
}