Esempio n. 1
0
        private static Verb ComputeNewVerb(string word)
        {
            string pastTense = null;
            string pastPart  = null;
            string presPart  = EnglishUtils.GetPresentParticiple(word);
            string thirdPers = GetThirdPerson(word);

            foreach (KeyValuePair <string, string[]> irregular in _irregularVerbs)
            {
                if (StringUtils.PartOf(word, irregular.Key, '-'))
                {
                    string[] pasts = irregular.Value;
                    if (pasts[1].Length > 0)
                    {
                        string prefix = word.Substring(0, word.LastIndexOf(irregular.Key, StringComparison.Ordinal));
                        pastTense = prefix + pasts[0];
                        pastPart  = prefix + pasts[1];
                        break;
                    }
                }
            }

            if (pastTense == null)
            {
                pastTense = EnglishUtils.GetRegularPast(word);
                pastPart  = EnglishUtils.GetRegularPast(word);
            }

            return(new Verb(word, pastTense, pastPart, presPart, thirdPers));
        }
Esempio n. 2
0
        public void ShouldConjugateToThirdPersonSingular(string verb, string expectedVerb)
        {
            // Act
            var conjugatedVerb = EnglishUtils.ConjugateToThirdPersonSingular(verb);

            // Assert
            conjugatedVerb.ShouldBe(expectedVerb);
        }
Esempio n. 3
0
 private static string GetThirdPerson(string verb)
 {
     if (_irregularThirdPersons.ContainsKey(verb))
     {
         return(_irregularThirdPersons[verb]);
     }
     return(EnglishUtils.GetThirdPerson(verb));
 }
Esempio n. 4
0
        private static string GetAdverb(string adj)
        {
            foreach (KeyValuePair <string, string> irregular in _irregularAdverbs)
            {
                if (StringUtils.PartOf(adj, irregular.Key, 4))
                {
                    string prefix = adj.Substring(0, adj.LastIndexOf(irregular.Key, StringComparison.Ordinal));
                    return(prefix + irregular.Value);
                }
            }

            return(EnglishUtils.GetAdverb(adj));
        }
Esempio n. 5
0
        private static string GetNounPlural(string noun)
        {
            foreach (KeyValuePair <string, string> irregular in _irregularPlurals)
            {
                if (StringUtils.PartOf(noun, irregular.Key, 4, "man"))
                {
                    string prefix = noun.Substring(0, noun.LastIndexOf(irregular.Key, StringComparison.Ordinal));
                    return(prefix + irregular.Value);
                }
            }

            return(EnglishUtils.GetNounPlural(noun));
        }
Esempio n. 6
0
        public void GetVerbForms()
        {
            //long vowel or diphthong followed by a consonant or ending in a consonant cluster
            foreach (string root in new[] { "paint", "claim", "devour", "play", "delight", "clamp", "lacquer" })
            {
                Assert.AreEqual(root + "ed", EnglishUtils.GetRegularPast(root));
                Assert.AreEqual(root + "ing", EnglishUtils.GetPresentParticiple(root));
                Assert.AreEqual(root + "s", EnglishUtils.GetThirdPerson(root));
            }

            //short vowel
            foreach (string root in new[] { "chat", "chop", "compel", "quiz", "squat", "quit", "equal", "whiz" })
            {
                char lastChar = root[root.Length - 1];
                Assert.AreEqual(root + lastChar + "ed", EnglishUtils.GetRegularPast(root));
                Assert.AreEqual(root + lastChar + "ing", EnglishUtils.GetPresentParticiple(root));
                if (!root.Equals("quiz") && !root.Equals("whiz")) //irregular third person
                {
                    Assert.AreEqual(root + "s", EnglishUtils.GetThirdPerson(root));
                }
            }

            //consonant followed by e
            foreach (string root in new[] { "dance", "save", "devote", "evolve", "quote" })
            {
                Assert.AreEqual(root + "d", EnglishUtils.GetRegularPast(root));
                Assert.AreEqual(root.Substring(0, root.Length - 1) + "ing", EnglishUtils.GetPresentParticiple(root));
                Assert.AreEqual(root + "s", EnglishUtils.GetThirdPerson(root));
            }

            //sibilants
            foreach (string root in new[] { "kiss", "bless", "box", "polish", "preach", "bias", "box" })
            {
                Assert.AreEqual(root + "ed", EnglishUtils.GetRegularPast(root));
                Assert.AreEqual(root + "ing", EnglishUtils.GetPresentParticiple(root));
                Assert.AreEqual(root + "es", EnglishUtils.GetThirdPerson(root));
            }

            //consonant followed by y
            foreach (string root in new[] { "comply", "copy", "magnify" })
            {
                Assert.AreEqual(root.Substring(0, root.Length - 1) + "ied", EnglishUtils.GetRegularPast(root));
                Assert.AreEqual(root + "ing", EnglishUtils.GetPresentParticiple(root));
                Assert.AreEqual(root.Substring(0, root.Length - 1) + "ies", EnglishUtils.GetThirdPerson(root));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 获取英语单词
        /// </summary>
        /// <returns></returns>
        public List <EnglishWordModel> GetEnglishWordModels()
        {
            DbSet <english> englishes = _myContext.Englishes;

            List <EnglishWordModel> englishWords = new List <EnglishWordModel>();

            foreach (var english in englishes)
            {
                EnglishWordModel englishWordModel = EnglishUtils.TranslateEnglish(english);

                if (englishWordModel != null)
                {
                    englishWords.Add(englishWordModel);
                }
            }

            return(englishWords);
        }
Esempio n. 8
0
 public void GetNounPlural()
 {
     foreach (string root in new[]
     {
         "file", "centre", "girl", "book", "computer", "ambition", "chief", "spoof", "cliff", "journey", "boy",
         "radio", "stereo", "video"
     })
     {
         Assert.AreEqual(root + "s", EnglishUtils.GetNounPlural(root));
     }
     foreach (string root in new[] { "wash", "box", "match", "glass", "bus", "business", "coach", "peach" })
     {
         Assert.AreEqual(root + "es", EnglishUtils.GetNounPlural(root));
     }
     foreach (string root in new[] { "country", "baby", "body", "memory" })
     {
         Assert.AreEqual(root.Substring(0, root.Length - 1) + "ies", EnglishUtils.GetNounPlural(root));
     }
 }
Esempio n. 9
0
 public void GetAdverb()
 {
     foreach (string root in new[] { "cheap", "quick", "slow" })
     {
         Assert.AreEqual(root + "ly", EnglishUtils.GetAdverb(root));
     }
     foreach (string root in new[] { "easy", "angry", "happy", "lucky" })
     {
         Assert.AreEqual(root.Substring(0, root.Length - 1) + "ily", EnglishUtils.GetAdverb(root));
     }
     foreach (string root in new[] { "probable", "terrible", "gentle" })
     {
         Assert.AreEqual(root.Substring(0, root.Length - 1) + "y", EnglishUtils.GetAdverb(root));
     }
     foreach (string root in new[] { "basic", "tragic", "economic" })
     {
         Assert.AreEqual(root + "ally", EnglishUtils.GetAdverb(root));
     }
 }
Esempio n. 10
0
        private static void LoadIrregularVerbs()
        {
            _irregularVerbs = new Dictionary <string, string[]>();
            string[][][] data =
                StringUtils.ReadIrregularTable(FileUtils.ReadResource("dict/irregular_verbs.csv"), "\n", ";", "/");
            foreach (string[][] subdata in data)
            {
                string[][] line = subdata;
                if (subdata.Length == 1)
                {
                    line = new[] { subdata[0], new[] { "" }, new[] { "" } }
                }
                ;
                else if (subdata.Length == 2)
                {
                    line = new[] { subdata[0], subdata[1], new[] { "" } }
                }
                ;

                _irregularVerbs.Add(line[0][0], new[] { line[1][0], line[2][0] });

                string root, pt, pp;
                int    maxDepth = line.Max(c => c.Length);
                for (int i = 0; i < maxDepth; i++)
                {
                    root = i < line[0].Length ? line[0][i] : line[0][0];
                    pt   = i < line[1].Length ? line[1][i] : line[1][0];
                    pp   = i < line[2].Length ? line[2][i] : line[2][0];
                    DbContext.Add(new Verb(root, pt, pp,
                                           pp.Length == 0 ? "" : EnglishUtils.GetPresentParticiple(root),
                                           GetThirdPerson(root)));
                }
            }

            DbContext.SaveChanges();
        }