Ejemplo n.º 1
0
        public void TestChiInString()
        {
            var runner = new TestRunner("hey there,0101010101 excited to see you");

            runner.Run();

            FailurePart p = runner.ResultsOfValidate.Single();

            Assert.AreEqual("0101010101", p.Word);
            Assert.AreEqual(10, p.Offset);
        }
Ejemplo n.º 2
0
        public void Test_IncludesSingleChar()
        {
            string origin = "this word f is the problem";

            var part = new FailurePart("f", FailureClassification.Organization, origin.IndexOf("f"));

            Assert.IsFalse(part.Includes(0));
            Assert.IsFalse(part.Includes(9));
            Assert.IsTrue(part.Includes(10));
            Assert.IsFalse(part.Includes(11));
            Assert.IsFalse(part.Includes(12));
            Assert.IsFalse(part.Includes(13));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Applies all <see cref="Rules"/> and returns the consensus <see cref="RuleAction"/>.  All rules must agree on the action and at least one index of one word that is a <see cref="FailurePart"/>
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="fieldValue"></param>
        /// <param name="badParts"></param>
        /// <returns></returns>
        public RuleAction Apply(string fieldName, string fieldValue, out IEnumerable <FailurePart> badParts)
        {
            RuleAction?        firstRuleOperation = null;
            List <FailurePart> parts = new List <FailurePart>();

            foreach (var rule in Rules)
            {
                //first time
                if (firstRuleOperation == null)
                {
                    firstRuleOperation = rule.Apply(fieldName, fieldValue, out IEnumerable <FailurePart> newParts);
                    parts.AddRange(newParts);
                }
                else
                {
                    //subsequent times
                    var newOperation = rule.Apply(fieldName, fieldValue, out IEnumerable <FailurePart> newParts);

                    // There is not consensus on whether the value should be classified as bad
                    if (newOperation != firstRuleOperation)
                    {
                        badParts = new FailurePart[0];
                        return(RuleAction.None);
                    }

                    parts = Intersect(parts, new List <FailurePart>(newParts));

                    if (!parts.Any() && firstRuleOperation == RuleAction.Report)
                    {
                        //if both rules agree it should be reported but cannot agree on the specific words that should be reported

                        //do not report anything

                        badParts = new FailurePart[0];
                        return(RuleAction.None);
                    }
                }

                //if anyone wants no action taken at any point stop consulting others.  Either they will agree in which case we have wasted time or they disagree so we say there is no consensus
                if (firstRuleOperation == RuleAction.None)
                {
                    badParts = new FailurePart[0];
                    return(RuleAction.None);
                }
            }

            badParts = parts;
            return(firstRuleOperation ?? RuleAction.None);
        }
Ejemplo n.º 4
0
        public void TestChiAndNameInString()
        {
            var runner = new TestRunner("David Smith should be referred to with chi 0101010101");

            runner.Run();
            Assert.AreEqual(1, runner.ResultsOfValidate.Count);

            FailurePart w1 = runner.ResultsOfValidate[0];

            /* Names are now picked up by the Socket NER Daemon
             * //FailurePart w2 = runner.ResultsOfValidate[1];
             * //FailurePart w3 = runner.ResultsOfValidate[2];
             *
             *
             * Assert.AreEqual("David", w1.Word);
             * Assert.AreEqual(0, w1.Offset);
             *
             * Assert.AreEqual("Smith", w2.Word);
             * Assert.AreEqual(6, w2.Offset);
             */

            Assert.AreEqual("0101010101", w1.Word);
            Assert.AreEqual(43, w1.Offset);
        }