private bool IsUninflective(string word) { //EDesignUtil.CheckArgumentNull<string>(word, "word"); if (PluralizationServiceUtil.DoesWordContainSuffix(word, _uninflectiveSuffixList, this.Culture) || (!word.ToLower(this.Culture).Equals(word) && word.EndsWith("ese", false, this.Culture)) || this._uninflectiveWordList.Contains(word.ToLowerInvariant())) { return(true); } else { return(false); } }
private string InternalSingularize(string word) { // words that we know of if (this._userDictionary.ExistsInSecond(word)) { return(this._userDictionary.GetFirstValue(word)); } if (IsNoOpWord(word)) { return(word); } string suffixWord = GetSuffixWord(word, out string prefixWord); if (IsNoOpWord(suffixWord)) { return(prefixWord + suffixWord); } // handle the word that is the same as the plural form if (this.IsUninflective(suffixWord)) { return(prefixWord + suffixWord); } // if word is one of the known singular words, then just return if (this._knownSingluarWords.Contains(suffixWord.ToLowerInvariant())) { return(prefixWord + suffixWord); } // handle simple irregular verbs, e.g. was -> were if (this._irregularVerbPluralizationService.ExistsInSecond(suffixWord)) { return(prefixWord + this._irregularVerbPluralizationService.GetFirstValue(suffixWord)); } // handle irregular plurals, e.g. "ox" -> "oxen" if (this._irregularPluralsPluralizationService.ExistsInSecond(suffixWord)) { return(prefixWord + this._irregularPluralsPluralizationService.GetFirstValue(suffixWord)); } // handle singluarization for words ending with sis and pluralized to ses, // e.g. "ses" -> "sis" if (this._wordsEndingWithSisPluralizationService.ExistsInSecond(suffixWord)) { return(prefixWord + this._wordsEndingWithSisPluralizationService.GetFirstValue(suffixWord)); } // handle words ending with se, e.g. "ses" -> "se" if (this._wordsEndingWithSePluralizationService.ExistsInSecond(suffixWord)) { return(prefixWord + this._wordsEndingWithSePluralizationService.GetFirstValue(suffixWord)); } // handle words ending with sus, e.g. "suses" -> "sus" if (this._wordsEndingWithSusPluralizationService.ExistsInSecond(suffixWord)) { return(prefixWord + this._wordsEndingWithSusPluralizationService.GetFirstValue(suffixWord)); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "men" }, (s) => s.Remove(s.Length - 2, 2) + "an", this.Culture, out string newSuffixWord)) { return(prefixWord + newSuffixWord); } // handle irregular inflections for common suffixes, e.g. "mouse" -> "mice" if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "lice", "mice" }, (s) => s.Remove(s.Length - 3, 3) + "ouse", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "teeth" }, (s) => s.Remove(s.Length - 4, 4) + "ooth", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "geese" }, (s) => s.Remove(s.Length - 4, 4) + "oose", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "feet" }, (s) => s.Remove(s.Length - 3, 3) + "oot", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "zoa" }, (s) => s.Remove(s.Length - 2, 2) + "oon", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } // [cs]h and ss that take es as plural form, this is being moved up since the sses will be override by the ses if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "ches", "shes", "sses" }, (s) => s.Remove(s.Length - 2, 2), this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } // handle assimilated classical inflections, e.g. vertebra -> vertebrae if (this._assimilatedClassicalInflectionPluralizationService.ExistsInSecond(suffixWord)) { return(prefixWord + this._assimilatedClassicalInflectionPluralizationService.GetFirstValue(suffixWord)); } // Handle the classical variants of modern inflections // if (this._classicalInflectionPluralizationService.ExistsInSecond(suffixWord)) { return(prefixWord + this._classicalInflectionPluralizationService.GetFirstValue(suffixWord)); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "trices" }, (s) => s.Remove(s.Length - 3, 3) + "x", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "eaux", "ieux" }, (s) => s.Remove(s.Length - 1, 1), this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (this._wordsEndingWithInxAnxYnxPluralizationService.ExistsInSecond(suffixWord)) { return(prefixWord + this._wordsEndingWithInxAnxYnxPluralizationService.GetFirstValue(suffixWord)); } // f, fe that take ves as plural form if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "alves", "elves", "olves", "eaves", "arves" }, (s) => s.Remove(s.Length - 3, 3) + "f", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "nives", "lives", "wives" }, (s) => s.Remove(s.Length - 3, 3) + "fe", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } // y takes ys as plural form if preceded by a vowel, but ies if preceded by a consonant, e.g. stays, skies if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "ays", "eys", "iys", "oys", "uys" }, (s) => s.Remove(s.Length - 1, 1), this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } // if (suffixWord.EndsWith("ies", true, this.Culture)) { return(prefixWord + suffixWord.Remove(suffixWord.Length - 3, 3) + "y"); } // handle some of the words o -> os, and [vowel]o -> os, and the rest are o->oes if (this._oSuffixPluralizationService.ExistsInSecond(suffixWord)) { return(prefixWord + this._oSuffixPluralizationService.GetFirstValue(suffixWord)); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "aos", "eos", "ios", "oos", "uos" }, (s) => suffixWord.Remove(suffixWord.Length - 1, 1), this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } // if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "ces" }, (s) => s.Remove(s.Length - 1, 1), this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "ces", "ses", "xes" }, (s) => s.Remove(s.Length - 2, 2), this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (suffixWord.EndsWith("oes", true, this.Culture)) { return(prefixWord + suffixWord.Remove(suffixWord.Length - 2, 2)); } if (suffixWord.EndsWith("ss", true, this.Culture)) { return(prefixWord + suffixWord); } if (suffixWord.EndsWith("s", true, this.Culture)) { return(prefixWord + suffixWord.Remove(suffixWord.Length - 1, 1)); } // word is a singlar return(prefixWord + suffixWord); }
private string InternalPluralize(string word) { // words that we know of if (this._userDictionary.ExistsInFirst(word)) { return(this._userDictionary.GetSecondValue(word)); } if (IsNoOpWord(word)) { return(word); } string suffixWord = GetSuffixWord(word, out string prefixWord); // by me -> by me if (IsNoOpWord(suffixWord)) { return(prefixWord + suffixWord); } // handle the word that do not inflect in the plural form if (this.IsUninflective(suffixWord)) { return(prefixWord + suffixWord); } // if word is one of the known plural forms, then just return if (this._knownPluralWords.Contains(suffixWord.ToLowerInvariant()) || this.IsPlural(suffixWord)) { return(prefixWord + suffixWord); } // handle irregular plurals, e.g. "ox" -> "oxen" if (this._irregularPluralsPluralizationService.ExistsInFirst(suffixWord)) { return(prefixWord + this._irregularPluralsPluralizationService.GetSecondValue(suffixWord)); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "man" }, (s) => s.Remove(s.Length - 2, 2) + "en", this.Culture, out string newSuffixWord)) { return(prefixWord + newSuffixWord); } // handle irregular inflections for common suffixes, e.g. "mouse" -> "mice" if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "louse", "mouse" }, (s) => s.Remove(s.Length - 4, 4) + "ice", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "tooth" }, (s) => s.Remove(s.Length - 4, 4) + "eeth", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "goose" }, (s) => s.Remove(s.Length - 4, 4) + "eese", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "foot" }, (s) => s.Remove(s.Length - 3, 3) + "eet", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "zoon" }, (s) => s.Remove(s.Length - 3, 3) + "oa", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "cis", "sis", "xis" }, (s) => s.Remove(s.Length - 2, 2) + "es", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } // handle assimilated classical inflections, e.g. vertebra -> vertebrae if (this._assimilatedClassicalInflectionPluralizationService.ExistsInFirst(suffixWord)) { return(prefixWord + this._assimilatedClassicalInflectionPluralizationService.GetSecondValue(suffixWord)); } // Handle the classical variants of modern inflections // if (this._classicalInflectionPluralizationService.ExistsInFirst(suffixWord)) { return(prefixWord + this._classicalInflectionPluralizationService.GetSecondValue(suffixWord)); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "trix" }, (s) => s.Remove(s.Length - 1, 1) + "ces", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "eau", "ieu" }, (s) => s + "x", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (this._wordsEndingWithInxAnxYnxPluralizationService.ExistsInFirst(suffixWord)) { return(prefixWord + this._wordsEndingWithInxAnxYnxPluralizationService.GetSecondValue(suffixWord)); } // [cs]h and ss that take es as plural form if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "ch", "sh", "ss" }, (s) => s + "es", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } // f, fe that take ves as plural form if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "alf", "elf", "olf", "eaf", "arf" }, (s) => s.EndsWith("deaf", true, this.Culture) ? s : s.Remove(s.Length - 1, 1) + "ves", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "nife", "life", "wife" }, (s) => s.Remove(s.Length - 2, 2) + "ves", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } // y takes ys as plural form if preceded by a vowel, but ies if preceded by a consonant, e.g. stays, skies if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "ay", "ey", "iy", "oy", "uy" }, (s) => s + "s", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } // if (suffixWord.EndsWith("y", true, this.Culture)) { return(prefixWord + suffixWord.Remove(suffixWord.Length - 1, 1) + "ies"); } // handle some of the words o -> os, and [vowel]o -> os, and the rest are o->oes if (this._oSuffixPluralizationService.ExistsInFirst(suffixWord)) { return(prefixWord + this._oSuffixPluralizationService.GetSecondValue(suffixWord)); } if (PluralizationServiceUtil.TryInflectOnSuffixInWord(suffixWord, new List <string>() { "ao", "eo", "io", "oo", "uo" }, (s) => s + "s", this.Culture, out newSuffixWord)) { return(prefixWord + newSuffixWord); } if (suffixWord.EndsWith("o", true, this.Culture) || suffixWord.EndsWith("s", true, this.Culture)) { return(prefixWord + suffixWord + "es"); } if (suffixWord.EndsWith("x", true, this.Culture)) { return(prefixWord + suffixWord + "es"); } // cats, bags, hats, speakers return(prefixWord + suffixWord + "s"); }