示例#1
0
        private static string Pigify(string sentence)
        {
            // these are vowels, we need these
            const string Vowels = "AEIOUaeiou";
            // a dynamic list of string to add our words to
            List <string> pigWords = new List <string>();

            // loop through each word in the sentence
            foreach (string word in sentence.Split(' '))
            {
                // take the first letter of our current word
                string firstLetter = word.Substring(0, 1);
                // take the late letter of our current word
                string restOfWord = word.Substring(1, word.Length - 1);
                // if the current letter a vowel
                int currentLetter = Vowels.IndexOf(firstLetter);

                // if it is
                if (currentLetter == -1)
                {
                    // create a new pigword with the first letter at the end of the word, adding "ay"
                    pigWords.Add(restOfWord + firstLetter + "ay");
                }
                // if it isnt
                else
                {
                    // create a new pigword with the entire word, adding "way"
                    pigWords.Add(word + "way");
                }
            }

            // join all the pigwords, spacing after each one, and output the result
            return(string.Join(" ", pigWords));
        }
        public SyllableTimeGameVm()
        {
            OkCommand    = new RelayCommand(Ok);
            ResetCommand = new RelayCommand(ResetGame);
            StartCommand = new RelayCommand(StartGame);
            SwitchAllConsonantsCommand = new RelayCommand(SwitchAllConsonants);
            SwitchAllVowelsCommand     = new RelayCommand(SwitchAllVowels);
            char[] consonants = { 'Ц', 'К', 'Н', 'Г', 'Ш', 'Щ', 'З', 'Х',
                                  'Ф', 'В', 'П', 'Р', 'Л', 'Д', 'Ж',
                                  'Ч', 'С', 'М', 'Т', 'Б' };
            foreach (var consonant in consonants)
            {
                Consonants.Add(new LetterVm
                {
                    Value     = consonant.ToString(),
                    IsEnabled = true
                });
            }

            char[] vowels = { 'У', 'Е', 'Ы', 'А', 'О', 'Э', 'Я', 'И', 'Ю' };
            foreach (var vowel in vowels)
            {
                Vowels.Add(new LetterVm
                {
                    Value     = vowel.ToString(),
                    IsEnabled = true
                });
            }

            ResetGame();
        }
示例#3
0
        /// <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();*/ } {
示例#4
0
        public static bool IsVowel(string character)
        {
            if (character.Length != 1)
            {
                throw new GrammarException($"The provided vowel {character} must be a single character in length.");
            }

            return(Vowels.Any(v => v.Character.ToString() == character.ToLower()));
        }
 public SyllableMask(Vowels vowels, SyllableCoda codas, SyllableOnset onsets, SyllableDisposition disposition)
 {
     AllowedVowels = vowels;
     AllowedCodas  = codas;
     AllowedOnsets = onsets;
     Disposition   = disposition;
     StartsWith    = "";
     EndsWith      = "";
 }
        /// <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);
        }
示例#7
0
 internal bool Check(string value)
 {
     if (String.IsNullOrEmpty(value))
     {
         return(false);
     }
     return
         ((AllowWords.Any(word => String.Equals(word, value, StringComparison.InvariantCultureIgnoreCase)) ||
           AllowPrefixes.Any(pfx => value.StartsWith(pfx, StringComparison.InvariantCultureIgnoreCase))) ||
          (Vowels.Any(v => Char.ToUpperInvariant(v) == Char.ToUpperInvariant(value[0])) &&
           !IgnorePrefixes.Any(pfx => value.StartsWith(pfx, StringComparison.InvariantCultureIgnoreCase)) &&
           !IgnoreWords.Any(word => String.Equals(word, value, StringComparison.InvariantCultureIgnoreCase))));
 }
示例#8
0
 private void Split(string str)
 {
     foreach (var letter in str)
     {
         if (CommonDataStructures.Vowels.Contains(letter))
         {
             Vowels.Add(letter);
         }
         else
         {
             Consonants.Add(letter);
         }
     }
 }
        static object EnumParseFlags(Type enumType, string value)
        {
            if (value.IndexOf("|") < 0)
            {
                return(Enum.Parse(enumType, value));
            }
            switch (enumType.Name)
            {
            case "Vowels":
                Vowels result1 = (Vowels)0;
                foreach (string s in value.Split('|'))
                {
                    result1 |= (Vowels)Enum.Parse(enumType, s);
                }
                return(result1);

            case "SyllableCoda":
                SyllableCoda result2 = (SyllableCoda)0;
                foreach (string s in value.Split('|'))
                {
                    result2 |= (SyllableCoda)Enum.Parse(enumType, s);
                }
                return(result2);

            case "SyllableOnset":
                SyllableOnset result3 = (SyllableOnset)0;
                foreach (string s in value.Split('|'))
                {
                    result3 |= (SyllableOnset)Enum.Parse(enumType, s);
                }
                return(result3);

            case "SyllableDisposition":
                SyllableDisposition result4 = (SyllableDisposition)0;
                foreach (string s in value.Split('|'))
                {
                    result4 |= (SyllableDisposition)Enum.Parse(enumType, s);
                }
                return(result4);

            case "SyllablePatternAnchor":
                SyllablePatternAnchor result5 = (SyllablePatternAnchor)0;
                foreach (string s in value.Split('|'))
                {
                    result5 |= (SyllablePatternAnchor)Enum.Parse(enumType, s);
                }
                return(result5);
            }
            return(null);
        }
        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);
        }
示例#11
0
        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);
        }
示例#12
0
 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));
 }
示例#13
0
        private void BuildPatterns()
        {
            /// Phonemes must be ordered by string length, else there will be false
            /// positive results which ends as wrong recognition

            var vowels_for_pattern     = Vowels.OrderByDescending(n => n.Length).ToList();
            var consonants_for_pattern = Consonants.OrderByDescending(n => n.Length).ToList();
            var rests_for_pattern      = Rests.OrderByDescending(n => n.Length).ToList();


            VowelPattern     = $"{String.Join("|", vowels_for_pattern)}";
            ConsonantPattern = $"{String.Join("|", consonants_for_pattern)}";
            RestPattern      = $"{String.Join("|", rests_for_pattern)}";
            foreach (var shit in ". ? ( ) [ ] * \\".Split(' '))
            {
                VowelPattern     = VowelPattern.Replace(shit, "\\" + shit);
                ConsonantPattern = ConsonantPattern.Replace(shit, "\\" + shit);
                RestPattern      = RestPattern.Replace(shit, "\\" + shit);
            }
            VowelPattern     = $"({VowelPattern})";
            ConsonantPattern = $"({ConsonantPattern})";
            RestPattern      = $"({RestPattern})";
        }
示例#14
0
 /// <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");
 }
示例#15
0
 private bool IsConsonant(char c)
 {
     return(!Vowels.Contains(c));
 }
示例#16
0
 public static bool IsVowel(Symbol symbol)
 {
     return(symbol.Value != null && symbol.Length == 1 && Vowels.Contains(char.ToUpper(symbol.Value[0])));
 }
示例#17
0
 private bool IsVowel(char c)
 {
     return(Vowels.Contains(c));
 }
示例#18
0
 public void TestVowels_Brenden()
 {
     Assert.AreEqual(2, Vowels.HowManyVowels("Brenden"));
 }
        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.IndexOf(local[n + 1]) >= 0))
                        {
                            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.IndexOf(local[n + 1]) >= 0))
                        {
                            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.IndexOf(local[2]) < 0))
                            {
                                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.IndexOf(local[n + 2]) >= 0))
                        {
                            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.IndexOf(local[n + 2]) < 0))
                        {
                            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.IndexOf(local[n + 1]) >= 0) /*&& !hard*/)
                        {
                            code.Append('J');
                        }
                        else
                        {
                            code.Append('K');
                        }

                        mtsz++;
                        break;

                    case 'H':
                        if (n + 1 == wdsz)
                        {
                            break;     // terminal H
                        }
                        if (n > 0 && Varson.IndexOf(local[n - 1]) >= 0)
                        {
                            break;
                        }

                        if (Vowels.IndexOf(local[n + 1]) >= 0)
                        {
                            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.IndexOf(local[n + 1]) >= 0))
                        {
                            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());
        }
示例#20
0
 public void TestVowels_SpecialCharacters()
 {
     Assert.AreEqual(4, Vowels.HowManyVowels("#$%^&%aeinmhdf&*(i"));
 }
示例#21
0
 public void TestVowels_EmptyString()
 {
     Assert.AreEqual(0, Vowels.HowManyVowels(" "));
 }
示例#22
0
 public void TestVowels_sentence()
 {
     Assert.AreEqual(5, Vowels.HowManyVowels("The brown dog eats"));
 }
示例#23
0
 public void TestVowels_UPERCASE()
 {
     Assert.AreEqual(3, Vowels.HowManyVowels("EMANI"));
 }
 public SyllableMask(Vowels vowels, SyllableCoda codas) : this(vowels, codas, SyllableOnset.Any)
 {
 }
 public SyllableMask(Vowels vowels, SyllableOnset onsets) : this(vowels, SyllableCoda.Any, onsets)
 {
 }
 public SyllableMask(Vowels vowels, SyllableCoda codas, SyllableOnset onsets) : this(vowels, codas, onsets, SyllableDisposition.Required)
 {
 }
示例#27
0
 public BaybayinLetter(String letter, int x, int y, int w, int h, Vowels v)
 {
     this.letter  = letter;
     this.postion = new Rectangle(x, y, w, h);
     this.vowel   = v;
 }
示例#28
0
 private static int CountVowels(string input)
 {
     return(input.Count(c => Vowels.Contains(c)));
 }
示例#29
0
        private Vowel(char character)
        {
            this.Character = character;

            Vowels.Add(this);
        }
示例#30
0
 public static bool IsVowel(char character)
 {
     return(Vowels.Any(v => v.Character == character));
 }