use english_core::EnglishCore;
pub use english_core::grammar::*;
mod noun_phf {
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/generated/noun_phf.rs"
));
}
use noun_phf::*;
mod adj_phf {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/generated/adj_phf.rs"));
}
use adj_phf::*;
mod verb_phf {
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/generated/verb_phf.rs"
));
}
use verb_phf::*;
fn strip_trailing_number(word: &str) -> &str {
match word.as_bytes().last() {
Some(b'0'..=b'9') => &word[..word.len() - 1],
_ => word,
}
}
pub struct English;
impl English {
pub fn noun(word: &str, number: &Number) -> String {
let base_word = strip_trailing_number(word);
match number {
Number::Singular => base_word.to_string(),
Number::Plural => {
if let Some(x) = get_plural(word) {
x.to_owned()
} else {
EnglishCore::noun(base_word, number)
}
}
}
}
pub fn adj(word: &str, degree: &Degree) -> String {
let base_word = strip_trailing_number(word);
match degree {
Degree::Positive => base_word.to_owned(),
Degree::Comparative => {
if let Some((comp, _)) = get_adjective_forms(word) {
comp.to_owned()
} else {
EnglishCore::comparative(base_word)
}
}
Degree::Superlative => {
if let Some((_, sup)) = get_adjective_forms(word) {
sup.to_owned()
} else {
EnglishCore::superlative(base_word)
}
}
}
}
pub fn verb(
word: &str,
person: &Person,
number: &Number,
tense: &Tense,
form: &Form,
) -> String {
let base_word = strip_trailing_number(word);
match get_verb_forms(word) {
Some(wordik) => match (person, number, tense, form) {
(_, _, _, Form::Infinitive) => base_word.to_owned(),
(Person::Third, Number::Singular, Tense::Present, Form::Finite) => {
wordik.0.to_string()
}
(_, _, Tense::Present, Form::Finite) => base_word.to_owned(),
(_, _, Tense::Present, Form::Participle) => wordik.2.to_owned(),
(_, _, Tense::Past, Form::Participle) => wordik.3.to_owned(),
(_, _, Tense::Past, Form::Finite) => wordik.1.to_owned(),
},
None => EnglishCore::verb(base_word, person, number, tense, form),
}
}
pub fn pronoun(person: &Person, number: &Number, gender: &Gender, case: &Case) -> &'static str {
EnglishCore::pronoun(person, number, gender, case)
}
pub fn add_possessive(word: &str) -> String {
EnglishCore::add_possessive(word)
}
pub fn capitalize_first(s: &str) -> String {
let mut c = s.chars();
match c.next() {
None => String::new(),
Some(first) => first.to_uppercase().collect::<String>() + c.as_str(),
}
}
}
pub fn count(noun: &str, count: u32) -> String {
if count == 1 {
English::noun(noun, &Number::Singular)
} else {
English::noun(noun, &Number::Plural)
}
}
pub fn count_with_number(noun: &str, amount: u32) -> String {
format!("{} {}", amount, count(noun, amount))
}