public void RealData7() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("someone who sins against someone else and therefore 'owes' that person")); Assert.AreEqual(1, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "someone", "who", "sins", "against", "someone", "else", "and", "therefore", "owes", "that", "person"); }
public void OptionalLeadingWord() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("(fun) stuff")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "stuff"); VerifyKeyTermMatch(bldr, 1, "fun", "stuff"); }
public void TwoWordKeyTerm() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("fun stuff")); Assert.AreEqual(1, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "fun", "stuff"); }
public void TwoWordKeyTermWithImplicitOptionalInfinitiveMarker() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("to cry")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "cry"); VerifyKeyTermMatch(bldr, 1, "to", "cry"); }
public void CanRenderingBeDeleted_NonExistentRendering() { IKeyTerm ktFun = KeyTermMatchBuilderTests.AddMockedKeyTerm("having a blast"); ktFun.Stub(kt => kt.Renderings).Return(new[] { "abc" }); KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(ktFun); KeyTermMatch matchFun = bldr.Matches.First(); Assert.IsFalse(matchFun.CanRenderingBeDeleted("xyz")); }
public void AddRenderingFailsToAddDuplicate() { IKeyTerm ktFun = KeyTermMatchBuilderTests.AddMockedKeyTerm("good times"); ktFun.Stub(kt => kt.Renderings).Return(new[] { "abc", "xyz" }); KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(ktFun); KeyTermMatch matchFun = bldr.Matches.First(); Assert.Throws(typeof(ArgumentException), () => matchFun.AddRendering("abc")); }
public void OptionalPhrase() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("(things of this) life")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "life"); VerifyKeyTermMatch(bldr, 1, "things", "of", "this", "life"); }
public void GetNormalRenderings() { IKeyTerm ktFun = KeyTermMatchBuilderTests.AddMockedKeyTerm("diversion"); ktFun.Stub(kt => kt.Renderings).Return(new [] {"abc", "xyz"}); KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(ktFun); KeyTermMatch matchFun = bldr.Matches.First(); Assert.IsTrue(matchFun.Renderings.SequenceEqual(ktFun.Renderings)); }
public void RealData12() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("olive oil (used as food")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "olive", "oil"); VerifyKeyTermMatch(bldr, 1, "olive", "oil", "used", "as", "food"); }
public void OptionalInitialPart() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("(loving)kindness")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "kindness"); VerifyKeyTermMatch(bldr, 1, "lovingkindness"); }
public void RealData6() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("exempt, free from")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "exempt"); VerifyKeyTermMatch(bldr, 1, "free", "from"); }
public void RealData4() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("Canaanean = Zealot")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "canaanean"); VerifyKeyTermMatch(bldr, 1, "zealot"); }
public void RealData8() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("state of fearing, standing in awe")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "state", "of", "fearing"); VerifyKeyTermMatch(bldr, 1, "standing", "in", "awe"); }
public void OptionalTrailingWord() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("morning (star)")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "morning"); VerifyKeyTermMatch(bldr, 1, "morning", "star"); }
public void OptionalMiddlePart() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("anti(dis)establishment")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "antiestablishment"); VerifyKeyTermMatch(bldr, 1, "antidisestablishment"); }
public void RealDataWithOr1() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("courtyard or sheepfold")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "courtyard"); VerifyKeyTermMatch(bldr, 1, "sheepfold"); }
public void RealData14() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("(one's own) burial-place")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "burial-place"); VerifyKeyTermMatch(bldr, 1, "one's", "own", "burial-place"); }
public void OptionalFinal() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("kind(ness)")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "kind"); VerifyKeyTermMatch(bldr, 1, "kindness"); }
public void RealDataWithOr2() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("give up or lay aside what one possesses")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "give", "up", "what", "one", "possesses"); VerifyKeyTermMatch(bldr, 1, "lay", "aside", "what", "one", "possesses"); }
public void RealDataWithOr4() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("and the flowers are white or pink. The whole plant gives off an agreeable odour")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "and", "the", "flowers", "are", "white", "off", "an", "agreeable", "odour"); VerifyKeyTermMatch(bldr, 1, "pink.", "the", "whole", "plant", "gives", "off", "an", "agreeable", "odour"); }
public void RealData5() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("dreadful event or sight")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "dreadful", "event"); VerifyKeyTermMatch(bldr, 1, "dreadful", "sight"); }
public void RealData1() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("worm, maggot")); Assert.AreEqual(2, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "worm"); VerifyKeyTermMatch(bldr, 1, "maggot"); }
public void RealData13() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("(Lord, LORD, God of) hosts")); Assert.AreEqual(3, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "hosts"); VerifyKeyTermMatch(bldr, 1, "lord", "of", "hosts"); VerifyKeyTermMatch(bldr, 2, "god", "of", "hosts"); }
public void RealData2() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("castor oil plant (FF 106, 107)")); Assert.LessOrEqual(1, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "castor", "oil", "plant"); // Ideally, we don't want to get anything for the junk in parentheses, but it // shouldn't really hurt anything, so we'll live with it. }
public void RealData9() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("to be favorably disposed to someone, or to experience an emotion of compassion towards other people")); Assert.AreEqual(4, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "be", "favorably", "disposed", "to", "someone"); VerifyKeyTermMatch(bldr, 1, "to", "be", "favorably", "disposed", "to", "someone"); VerifyKeyTermMatch(bldr, 2, "experience", "an", "emotion", "of", "compassion", "towards", "other", "people"); VerifyKeyTermMatch(bldr, 3, "to", "experience", "an", "emotion", "of", "compassion", "towards", "other", "people"); }
public void RealDataWithOr3() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("to perform the ritual of removing the state of guilt or uncleanness from oneself")); Assert.AreEqual(4, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "perform", "the", "ritual", "of", "removing", "the", "state", "of", "guilt"); VerifyKeyTermMatch(bldr, 1, "to", "perform", "the", "ritual", "of", "removing", "the", "state", "of", "guilt"); VerifyKeyTermMatch(bldr, 2, "perform", "the", "ritual", "of", "removing", "the", "uncleanness", "from", "oneself"); VerifyKeyTermMatch(bldr, 3, "to", "perform", "the", "ritual", "of", "removing", "the", "uncleanness", "from", "oneself"); }
public void GetNormalRenderings() { IKeyTerm ktFun = KeyTermMatchBuilderTests.AddMockedKeyTerm("diversion"); ktFun.Stub(kt => kt.Renderings).Return(new [] { "abc", "xyz" }); KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(ktFun); KeyTermMatch matchFun = bldr.Matches.First(); Assert.IsTrue(matchFun.Renderings.SequenceEqual(ktFun.Renderings)); }
public void RealData3() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("(loving)kindness, solidarity, joint liability, grace")); Assert.AreEqual(5, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "kindness"); VerifyKeyTermMatch(bldr, 1, "lovingkindness"); VerifyKeyTermMatch(bldr, 2, "solidarity"); VerifyKeyTermMatch(bldr, 3, "joint", "liability"); VerifyKeyTermMatch(bldr, 4, "grace"); }
public void RuleToExcludeTermCompletely() { Dictionary <string, KeyTermRule> rules = new Dictionary <string, KeyTermRule>(); KeyTermRule rule = new KeyTermRule(); rule.id = "Jesus"; rule.Rule = KeyTermRule.RuleType.Exclude; rules[rule.id] = rule; KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("Jesus"), rules); Assert.AreEqual(0, bldr.Matches.Count()); }
public void CanRenderingBeDeleted_DefaultRendering() { IKeyTerm ktFun = KeyTermMatchBuilderTests.AddMockedKeyTerm("time of my life"); ktFun.Stub(kt => kt.Renderings).Return(new[] { "abc" }); KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(ktFun); KeyTermMatch matchFun = bldr.Matches.First(); matchFun.AddRendering("bestest"); matchFun.BestRendering = "bestest"; Assert.IsFalse(matchFun.CanRenderingBeDeleted("bestest")); }
public void RealData10() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("to recompense, to reward, to pay")); Assert.AreEqual(6, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "recompense"); VerifyKeyTermMatch(bldr, 1, "to", "recompense"); VerifyKeyTermMatch(bldr, 2, "reward"); VerifyKeyTermMatch(bldr, 3, "to", "reward"); VerifyKeyTermMatch(bldr, 4, "pay"); VerifyKeyTermMatch(bldr, 5, "to", "pay"); }
public void AddAndRemoveRenderings() { IKeyTerm ktFun = KeyTermMatchBuilderTests.AddMockedKeyTerm("fun"); ktFun.Stub(kt => kt.Renderings).Return(new [] { "abc", "xyz" }); KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(ktFun); KeyTermMatch matchFun = bldr.Matches.First(); matchFun.AddRendering("wunkyboo"); Assert.AreEqual(3, matchFun.Renderings.Count()); Assert.IsTrue(matchFun.Renderings.Contains("wunkyboo")); Assert.IsTrue(matchFun.CanRenderingBeDeleted("wunkyboo")); Assert.IsFalse(matchFun.CanRenderingBeDeleted("abc")); matchFun.DeleteRendering("wunkyboo"); Assert.IsFalse(matchFun.Renderings.Contains("wunkyboo")); }
public void RealData11() { KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("to lift up (one's hand, heart, or soul) = to worship, pray")); Assert.AreEqual(7, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "lift", "up"); VerifyKeyTermMatch(bldr, 1, "to", "lift", "up"); VerifyKeyTermMatch(bldr, 2, "lift", "up", "one's", "hand", "heart", "soul"); VerifyKeyTermMatch(bldr, 3, "to", "lift", "up", "one's", "hand", "heart", "soul"); VerifyKeyTermMatch(bldr, 4, "worship"); VerifyKeyTermMatch(bldr, 5, "to", "worship"); VerifyKeyTermMatch(bldr, 6, "pray"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Verifies the key term match. /// </summary> /// ------------------------------------------------------------------------------------ private static void VerifyKeyTermMatch(KeyTermMatchBuilder bldr, int iMatch, params string[] words) { VerifyKeyTermMatch(bldr, iMatch, true, words); }
public void RuleToReplaceOriginalTermWithAlternates() { Dictionary<string, KeyTermRule> rules = new Dictionary<string, KeyTermRule>(); KeyTermRule rule = new KeyTermRule(); rule.id = "to lift up (one's hand, heart, or soul) = to worship, pray"; rule.Rule = KeyTermRule.RuleType.Exclude; rule.Alternates = new[] { new KeyTermRulesKeyTermRuleAlternate(), new KeyTermRulesKeyTermRuleAlternate(), new KeyTermRulesKeyTermRuleAlternate() }; rule.Alternates[0].Name = "worship"; rule.Alternates[1].Name = "praise exuberantly"; rule.Alternates[2].Name = "pray"; rules[rule.id] = rule; KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm(rule.id), rules); Assert.AreEqual(3, bldr.Matches.Count()); VerifyKeyTermMatch(bldr, 0, "worship"); VerifyKeyTermMatch(bldr, 1, "praise", "exuberantly"); VerifyKeyTermMatch(bldr, 2, "pray"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Populates the key terms table. /// </summary> /// ------------------------------------------------------------------------------------ private void PopulateKeyTermsTable(IEnumerable<IKeyTerm> keyTerms, KeyTermRules rules) { Dictionary<string, KeyTermRule> ktRules = new Dictionary<string, KeyTermRule>(); if (rules != null) { foreach (KeyTermRule keyTermRule in rules.Items.Where(keyTermRule => !String.IsNullOrEmpty(keyTermRule.id))) ktRules[keyTermRule.id] = keyTermRule; } KeyTermMatchBuilder matchBuilder; foreach (IKeyTerm keyTerm in keyTerms) { matchBuilder = new KeyTermMatchBuilder(keyTerm, ktRules); foreach (KeyTermMatch matcher in matchBuilder.Matches) { if (!matcher.Words.Any()) continue; List<KeyTermMatch> foundMatchers; Word firstWord = matcher.Words.First(); if (!m_keyTermsTable.TryGetValue(firstWord, out foundMatchers)) m_keyTermsTable[firstWord] = foundMatchers = new List<KeyTermMatch>(); KeyTermMatch existingMatcher = foundMatchers.FirstOrDefault(m => m.Equals(matcher)); if (existingMatcher == null) foundMatchers.Add(matcher); else existingMatcher.AddTerm(keyTerm); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Verifies the key term match. /// </summary> /// ------------------------------------------------------------------------------------ private static KeyTermMatch VerifyKeyTermMatch(KeyTermMatchBuilder bldr, int iMatch, bool matchAnywhere, params string[] words) { KeyTermMatch ktm = bldr.Matches.ElementAt(iMatch); Assert.AreEqual(words.Length, ktm.Words.Count()); for (int i = 0; i < words.Length; i++) Assert.AreEqual(words[i], ktm.Words.ElementAt(i).Text); if (matchAnywhere) { Random r = new Random(DateTime.Now.Millisecond); Assert.IsTrue(ktm.AppliesTo(r.Next(), r.Next())); } return ktm; }
public void RuleToLimitMatchToTermRefs() { Dictionary<string, KeyTermRule> rules = new Dictionary<string, KeyTermRule>(); KeyTermRule rule = new KeyTermRule(); rule.id = "ask"; rule.Rule = KeyTermRule.RuleType.MatchForRefOnly; rules[rule.id] = rule; KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm(rule.id, 34), rules); Assert.AreEqual(1, bldr.Matches.Count()); KeyTermMatch ktm = VerifyKeyTermMatch(bldr, 0, false, "ask"); Assert.IsFalse(ktm.AppliesTo(30, 33)); Assert.IsTrue(ktm.AppliesTo(34, 34)); Assert.IsFalse(ktm.AppliesTo(35, 39)); }