use english_core::EnglishCore;
pub use english_core::grammar::*;
mod noun_array;
use noun_array::*;
mod verb_array;
use verb_array::*;
mod adj_array;
use adj_array::*;
mod noun;
pub use noun::*;
mod verb;
pub use verb::*;
mod adj;
pub use adj::*;
fn strip_trailing_number(word: &str) -> String {
if let Some(last_char) = word.chars().last() {
if last_char.is_ascii_digit() {
return word[..word.len() - 1].to_string();
}
}
word.to_string()
}
pub struct English {}
impl English {
pub fn noun<T: Into<Noun>>(word: T, number: &Number) -> String {
let noun: Noun = word.into();
let base_word = strip_trailing_number(&noun.head);
let head_inflected = match number {
Number::Singular => base_word,
Number::Plural => {
if let Some(x) = get_plural(&noun.head) {
x.to_owned()
} else {
EnglishCore::noun(&base_word, number)
}
}
};
let mut result = String::new();
if let Some(modifier) = &noun.modifier {
result.push_str(modifier);
result.push(' ');
}
result.push_str(&head_inflected);
if let Some(complement) = &noun.complement {
result.push(' ');
result.push_str(complement);
}
result
}
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<T: Into<Verb>>(
wordish: T,
person: &Person,
number: &Number,
tense: &Tense,
form: &Form,
) -> String {
let verb: Verb = wordish.into();
let base_word = strip_trailing_number(&verb.head);
let conjugated_head = match get_verb_forms(&verb.head) {
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),
};
if let Some(particle) = verb.particle {
let mut result = String::with_capacity(conjugated_head.len() + 1 + particle.len());
result.push_str(&conjugated_head);
result.push(' ');
result.push_str(&particle);
result
} else {
conjugated_head
}
}
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(),
}
}
}