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)); }
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)); } }
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(); }