use aoko::no_std::{functions::ext::{Utf8Ext, AnyExt1}, pipelines::pipe::Pipe};
use itertools::Itertools;
use std::fs;
const PP: [char; 6] = ['"', '\'', '(', '[', '{', '<'];
const SP: [char; 12] = [',', '.', '!', '"', '\'', ':', ';', ')', ']', '}', '>', '-'];
pub fn batch_en(dict: String, r#in: String, out: String) {
fs::read(r#in).unwrap()
.to_ascii_lowercase()
.to_str().unwrap()
.pipe(|s| if let None = dict.chars().next() {
s.split_whitespace()
.filter_map(|s| s
.trim_start_matches(|c| PP.contains(&c))
.trim_end_matches(|c| SP.contains(&c))
.if_not_then(|s| s.chars().next().is_none(), |s| (s, 1)))
.into_grouping_map_by(|t| t.0) .fold(0, |acc, _, (_, count)| acc + count) .into_iter()
.sorted_by_key(|t| t.1)
} else {
fs::read(dict).unwrap()
.to_ascii_lowercase()
.to_str().unwrap()
.lines()
.flat_map(|phrase| s.matches(phrase).counts())
.sorted_by_key(|t| t.1)
})
.rev()
.map(|t| format!("{:?}", t))
.join("\n")
.pipe(|byt| fs::write(out, byt).unwrap())
}