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 RuleToKeepOriginalTermAndAddAnAlternate()
        {
            Dictionary <string, KeyTermRule> rules = new Dictionary <string, KeyTermRule>();
            KeyTermRule rule = new KeyTermRule();

            rule.id                 = "Jesus";
            rule.Alternates         = new [] { new KeyTermRulesKeyTermRuleAlternate() };
            rule.Alternates[0].Name = "Jesus Christ";
            rules[rule.id]          = rule;
            KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("Jesus"), rules);

            Assert.AreEqual(2, bldr.Matches.Count());
            VerifyKeyTermMatch(bldr, 0, "jesus", "christ");
            VerifyKeyTermMatch(bldr, 1, "jesus");
        }
        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));
        }
        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>
		/// Adds the mocked key term.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private IKeyTerm AddMockedKeyTerm(string term, string bestRendering, string[] otherRenderings,
			params int[] occurences)
		{
			IKeyTerm mockedKt = KeyTermMatchBuilderTests.AddMockedKeyTerm(term, occurences);
			if (bestRendering != null)
			{
				otherRenderings = (otherRenderings == null) ? new [] { bestRendering } :
					(new [] { bestRendering }).Concat(otherRenderings).ToArray();
				mockedKt.Stub(kt => kt.BestRendering).Return(bestRendering);
			}
			mockedKt.Stub(kt => kt.Renderings).Return(otherRenderings);

			if (occurences.Length > 0)
			{
				if (m_keyTermRules == null)
				{
					m_keyTermRules = new KeyTermRules();
					m_keyTermRules.Items = new List<KeyTermRule>();
				}
				KeyTermRule rule = new KeyTermRule();
				rule.id = term;
				rule.Rule = KeyTermRule.RuleType.MatchForRefOnly;
				m_keyTermRules.Items.Add(rule);
			}
			m_dummyKtList.Add(mockedKt);
			return mockedKt;
		}
		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");
		}
		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));
		}
		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 RuleToKeepOriginalTermAndAddAnAlternate()
		{
			Dictionary<string, KeyTermRule> rules = new Dictionary<string, KeyTermRule>();
			KeyTermRule rule = new KeyTermRule();
			rule.id = "Jesus";
			rule.Alternates = new [] {new KeyTermRulesKeyTermRuleAlternate()};
			rule.Alternates[0].Name = "Jesus Christ";
			rules[rule.id] = rule;
			KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm("Jesus"), rules);
			Assert.AreEqual(2, bldr.Matches.Count());
			VerifyKeyTermMatch(bldr, 0, "jesus", "christ");
			VerifyKeyTermMatch(bldr, 1, "jesus");
		}