Skip to main content

english_core/
noun.rs

1use crate::EnglishCore;
2use crate::grammar::*;
3
4impl EnglishCore {
5    pub fn noun(word: &str, number: &Number) -> String {
6        match number {
7            Number::Singular => return word.to_string(),
8            Number::Plural => return EnglishCore::pluralize_noun(word),
9        }
10    }
11    pub fn add_possessive(word: &str) -> String {
12        if word.ends_with('s') {
13            format!("{word}'") // Regular plural: dogs'
14        } else {
15            format!("{word}'s") // Irregular plural: children’s
16        }
17    }
18
19    pub fn pluralize_noun(word: &str) -> String {
20        if let Some(irr) = EnglishCore::iter_replace_last(word, IRREGULAR_SUFFIXES) {
21            return irr;
22        }
23        format!("{}{}", word, "s")
24    }
25}
26
27//These are most of the irregular suffixes, not counted so far are wolves,potatoes,compound words
28//some are commented out due to not positively affecting performance/size
29const IRREGULAR_SUFFIXES: &[(&str, &str)] = &[
30    //  ("chassis", "chassis"),
31    //  ("sheep", "sheep"),
32    ("mouse", "mice"),
33    // ("louse", "lice"),
34    ("tooth", "teeth"),
35    ("goose", "geese"),
36    ("trix", "trices"),
37    ("fish", "fish"),
38    ("deer", "deer"),
39    // ("itis", "itis"),
40    ("foot", "feet"),
41    ("zoon", "zoa"),
42    ("ese", "ese"),
43    ("man", "men"),
44    //("pox", "pox"),
45    // ("ois", "ois"),
46    //  ("cis", "ces"),
47    ("sis", "ses"),
48    ("xis", "xes"),
49    //("eau", "eaux"),
50    // ("ieu", "ieux"),
51    // ("inx", "inges"),
52    // ("anx", "anges"),
53    //  ("ynx", "ynges"),
54    ("um", "a"),
55    ("ch", "ches"),
56    ("sh", "shes"),
57    ("ay", "ays"),
58    //  ("uy", "uys"),
59    ("oy", "oys"),
60    ("ey", "eys"),
61    ("x", "xes"),
62    //  ("a", "ae"),
63    ("s", "ses"),
64    ("y", "ies"),
65    ("f", "ves"),
66];