/// <summary> /// Converts givent string to Pig Greek. /// </summary> /// <param name="Word">string</param> /// <returns>translated string</returns> public string ConvertTo(string Word) { var Index = 1; var Length = Word.Length; var First = Word[0]; var FirstPart = ""; var LastPart = ""; if (Vowels.Contains(First.ToString())) { if (IsAllUpper(Word)) { return(Word + "OI"); } else { return(Word + "oi"); } } if (!IsAllUpper(Word)) { Word = Word.ToLower(); } else /*doNothing();*/ } {
/// <summary> /// A method that pluralizes an word without using a custom pluralization dictionary. /// </summary> /// <param name="noun">The word to pluralize</param> /// <param name="capitalize">Whether to capitalize the word.</param> /// <returns></returns> public string ApplyStandardPluralizationRules(string noun, bool capitalize = false) { string s = "s", es = "es", ies = "ies"; if (capitalize) { s = "S"; es = "ES"; ies = "IES"; } if (string.IsNullOrWhiteSpace(noun)) { return(noun); } // Pluralization of letters and number character names themselves: As, Bs, Cs, Ds, a's, b's, c's, d's, 1s, 2s, 3s. if (noun.Length == 1) { return((char.IsUpper(noun, 0) || char.IsDigit(noun, 0)) ? noun + s : noun + "'" + s); } // Pluralization of diagraphs themselves: CHs, CKs, Ch's, ch's if (noun.Length == 2 && Diagraphs.Contains(noun, StringComparer.OrdinalIgnoreCase)) { return(noun + (char.IsLower(noun, 1) ? "'" + s : s)); } // Ends with y and character before y is not a vowel. if (noun.EndsWith("y", StringComparison.OrdinalIgnoreCase)) { // Second to last letter is not a vowel. Example: fries. if ((noun.Length > 1 && !Vowels.Contains(noun[noun.Length - 2].ToString(), StringComparer.OrdinalIgnoreCase)) // or ends in -quy. Example: soliloquies || (noun.EndsWith("quy", StringComparison.OrdinalIgnoreCase))) { return(noun.Substring(0, noun.Length - 1) + ies); // flies, ties, treaties } return(noun + s); // Example: bays, boys, days, toys, joys, guys, guys. } // Nouns that end with consonant followed by o should usually end with -es. If not, put them in the dictionary. if (noun.EndsWith("o", StringComparison.OrdinalIgnoreCase) && !Vowels.Contains(noun[noun.Length - 2].ToString(), StringComparer.OrdinalIgnoreCase)) { return(noun + es); } // Nouns that end with a character or diagraphs that requires pluralization with -es if (EndingsThatPuralizeWithEs.Any(e => noun.EndsWith(e, StringComparison.OrdinalIgnoreCase))) { return(noun + es); } // The default, just add an s. return(noun + s); }
private bool IsNice(string value) { if (_naughtyPatterns.Any(value.Contains)) { return(false); } if (!_nicePatterns.Any(value.Contains)) { return(false); } return(value.Count(x => Vowels.Contains(x)) >= 3); }
public override double ComputeFactor(Article article) { int countOfVowels = 0; List <string> articleWords = Utils.ExtractMeaningfulWords(article); foreach (string word in articleWords) { foreach (char c in word) { if (Vowels.Contains(c)) { countOfVowels++; } } } return(countOfVowels); }
private string MarkYsAsConsonants(string word) { char[] chars = word.ToCharArray(); for (int i = 0; i < chars.Length; i++) { if (i == 0) { if (chars[i] == 'y') { chars[i] = 'Y'; } } else if (Vowels.Contains(chars[i - 1]) && chars[i] == 'y') { chars[i] = 'Y'; } } return(new string(chars)); }
/// <summary> /// ''' Get the gerund value of a verb. /// ''' </summary> /// ''' <param name="str">present tense verb to make gerund.</param> /// ''' <returns>String value of the gerund form of a verb.</returns> /// ''' <remarks></remarks> public static string getGerund(string str) { // str = str.ToLower if (str.ToLower().Substring(str.Length - 1, 1) == "e") { str = str.Substring(0, str.Length - 1); } else if (str.Length > 2) { string e1, e2; // get last letter e1 = str.ToLower().Substring(str.Length - 1, 1); // get second to last letter e2 = str.ToLower().Substring(str.Length - 2, 1); // if last letter is a consonant and the second to last is a vowel if (Vowels.Contains(e2) && Consonants.Contains(e1)) { // double last letter str += e1; } } return(str + "ing"); }
private bool IsConsonant(char c) { return(!Vowels.Contains(c)); }
private bool IsVowel(char c) { return(Vowels.Contains(c)); }
public static bool IsVowel(Symbol symbol) { return(symbol.Value != null && symbol.Length == 1 && Vowels.Contains(char.ToUpper(symbol.Value[0]))); }
private static int CountVowels(string input) { return(input.Count(c => Vowels.Contains(c))); }
public static string Metaphone(string s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } const string Vowels = "AEIOU"; const string Frontv = "EIY"; const string Varson = "CSPTG"; const int MaxCodeLen = 4; if (s.Length == 0) { return(string.Empty); } if (s.Length == 1) { return(s.ToUpperInvariant()); } var inwd = s.ToUpperInvariant().ToCharArray(); var local = new StringBuilder(40); // manipulate var code = new StringBuilder(10); // output // handle initial 2 characters exceptions switch (inwd[0]) { case 'K': case 'G': case 'P': /* looking for KN, etc*/ if (inwd[1] == 'N') { local.Append(inwd, 1, inwd.Length - 1); } else { local.Append(inwd); } break; case 'A': /* looking for AE */ if (inwd[1] == 'E') { local.Append(inwd, 1, inwd.Length - 1); } else { local.Append(inwd); } break; case 'W': /* looking for WR or WH */ if (inwd[1] == 'R') { // WR -> R local.Append(inwd, 1, inwd.Length - 1); break; } if (inwd[1] == 'H') { local.Append(inwd, 1, inwd.Length - 1); local[0] = 'W'; // WH -> W } else { local.Append(inwd); } break; case 'X': /* initial X becomes S */ inwd[0] = 'S'; local.Append(inwd); break; default: local.Append(inwd); break; } // now local has working string with initials fixed var wdsz = local.Length; var mtsz = 0; var n = 0; while ((mtsz < MaxCodeLen) && // max code size of 4 works well (n < wdsz)) { var symb = local[n]; // remove duplicate letters except C if ((symb != 'C') && (n > 0) && (local[n - 1] == symb)) { n++; } else { // not dup string tmpS; switch (symb) { case 'A': case 'E': case 'I': case 'O': case 'U': if (n == 0) { code.Append(symb); mtsz++; } break; // only use vowel if leading char case 'B': if ((n > 0) && n == wdsz - 1 && (local[n - 1] == 'M')) { break; } code.Append(symb); mtsz++; break; case 'C': // lots of C special cases /* discard if SCI, SCE or SCY */ if ((n > 0) && (local[n - 1] == 'S') && (n + 1 < wdsz) && (Frontv.Contains(local[n + 1], StringComparison.Ordinal))) { break; } tmpS = local.ToString(); Contract.Assume(local.Length == tmpS.Length); if (tmpS.IndexOf("CIA", n, StringComparison.Ordinal) == n) { // "CIA" -> X code.Append('X'); mtsz++; break; } if ((n + 1 < wdsz) && (Frontv.Contains(local[n + 1], StringComparison.Ordinal))) { code.Append('S'); mtsz++; break; // CI,CE,CY -> S } if ((n > 0) && (tmpS.IndexOf("SCH", n - 1, StringComparison.Ordinal) == n - 1)) { // SCH->sk code.Append('K'); mtsz++; break; } if (tmpS.IndexOf("CH", n, StringComparison.Ordinal) == n) { // detect CH if ((n == 0) && (wdsz >= 3) && // CH consonant -> K consonant !Vowels.Contains(local[2], StringComparison.Ordinal)) { code.Append('K'); } else { code.Append('X'); // CHvowel -> X } mtsz++; } else { code.Append('K'); mtsz++; } break; case 'D': if ((n + 2 < wdsz) && // DGE DGI DGY -> J (local[n + 1] == 'G') && (Frontv.Contains(local[n + 2], StringComparison.Ordinal))) { code.Append('J'); n += 2; } else { code.Append('T'); } mtsz++; break; case 'G': // GH silent at end or before consonant if ((n + 2 == wdsz) && (local[n + 1] == 'H')) { break; } if ((n + 2 < wdsz) && (local[n + 1] == 'H') && !Vowels.Contains(local[n + 2], StringComparison.Ordinal)) { break; } tmpS = local.ToString(); if (n > 0 && (tmpS.IndexOf("GN", n, StringComparison.Ordinal) == n || tmpS.IndexOf("GNED", n, StringComparison.Ordinal) == n)) { break; // silent G } // bool hard = false; // if ((n > 0) && // (local[n - 1] == 'G')) hard = true;//totest // else hard = false; if ((n + 1 < wdsz) && Frontv.Contains(local[n + 1], StringComparison.Ordinal) /*&& !hard*/) { code.Append('J'); } else { code.Append('K'); } mtsz++; break; case 'H': if (n + 1 == wdsz) { break; // terminal H } if (n > 0 && Varson.Contains(local[n - 1], StringComparison.Ordinal)) { break; } if (Vowels.Contains(local[n + 1], StringComparison.Ordinal)) { code.Append('H'); mtsz++; // Hvowel } break; case 'F': case 'J': case 'L': case 'M': case 'N': case 'R': code.Append(symb); mtsz++; break; case 'K': if (n > 0) { // not initial if (local[n - 1] != 'C') { code.Append(symb); } } else { code.Append(symb); // initial K } mtsz++; break; case 'P': // PH -> F if ((n + 1 < wdsz) && (local[n + 1] == 'H')) { code.Append('F'); } else { code.Append(symb); } mtsz++; break; case 'Q': code.Append('K'); mtsz++; break; case 'S': tmpS = local.ToString(); Contract.Assume(tmpS.Length == local.Length); if ((tmpS.IndexOf("SH", n, StringComparison.Ordinal) == n) || (tmpS.IndexOf("SIO", n, StringComparison.Ordinal) == n) || (tmpS.IndexOf("SIA", n, StringComparison.Ordinal) == n)) { code.Append('X'); } else { code.Append('S'); } mtsz++; break; case 'T': tmpS = local.ToString(); // TIA TIO -> X Contract.Assume(tmpS.Length == local.Length); if ((tmpS.IndexOf("TIA", n, StringComparison.Ordinal) == n) || (tmpS.IndexOf("TIO", n, StringComparison.Ordinal) == n)) { code.Append('X'); mtsz++; break; } if (tmpS.IndexOf("TCH", n, StringComparison.Ordinal) == n) { break; } // substitute numeral 0 for TH (resembles theta after all) code.Append(tmpS.IndexOf("TH", n, StringComparison.Ordinal) == n ? '0' : 'T'); mtsz++; break; case 'V': code.Append('F'); mtsz++; break; case 'W': case 'Y': // silent if not followed by vowel if ((n + 1 < wdsz) && Vowels.Contains(local[n + 1], StringComparison.Ordinal)) { code.Append(symb); mtsz++; } break; case 'X': code.Append('K'); code.Append('S'); mtsz += 2; break; case 'Z': code.Append('S'); mtsz++; break; } // end switch n++; } // end else from symb != 'C' if (mtsz > 4) { code.Length = 4; } } return(code.ToString()); }
/// <summary> /// Does string contain specified number of vowels? /// </summary> /// <param name="s">string to process</param> /// <param name="num"></param> /// <returns></returns> private static bool ContainsVowels(string s, int num) { return(s.Count(c => Vowels.Contains(c)) >= num); }