Exemple #1
0
        public void ToCNLListTest(bool includeImplicit, bool removeTrivials = true)
        {
            var cnlSentences = new List <string>()
            {
                "Every location-form is a form.",
                "Every data-location-form is a location-form.",
                "Data-Location-Form is a data-location-form.",
                "If a form is a data-location-form then the form is-a-form-of-type Special-Form.",
                "Annotations:\r\n_Operational-Risk Instance: network-description 'Network of operational risk.'@en\r\n.",
            };

            var feClient = new CogniPySvr();

            feClient.SetDebugListener((statementId, elements) =>
            {
                int x = 10;
            }, (s, c) => Tuple.Create(s, c));
            feClient.LoadCnlFromString(string.Join("\r\n", cnlSentences.Union <string>(new List <string>()
            {
                "Comment: This comment should not be returned."
            })), true, true);
            var sentencesReturned = feClient.ToCNLList(includeImplicit, removeTrivials, true);

            Assert.AreEqual(sentencesReturned.Count, sentencesReturned.Distinct().ToList().Count, "There are duplicate senetences!");

            if (includeImplicit)
            {
                if (removeTrivials)
                {
                    Assert.AreEqual(9, sentencesReturned.Count);
                }
                else
                {
                    Assert.AreEqual(14, sentencesReturned.Count);
                }
            }
            else
            {
                CollectionAssert.AreEquivalent(cnlSentences, sentencesReturned);
            }
        }
        public void RuleDebuggerTest()
        {
            var cnlSentences = new List <string>()
            {
                "John is a man.",
                "Mary is a woman.",
                "John has-friend Mary.",
                "Mary has-name equal-to 'Mary'.",
                "If a man has-friend a woman and the woman has-name equal-to 'Mary' then the man is an happy-man."
            };
            var feClient = new CogniPySvr();
            var ruleId   = feClient.GetStatementId(cnlSentences[4]);

            feClient.SetDebugListener((statementId, elements) =>
            {
                Assert.AreEqual(ruleId, statementId);
                Assert.AreEqual(2, elements.Count());
                Assert.AreEqual("John", elements[0].Value.ToString());
                Assert.AreEqual("man", elements[0].Name);
                Assert.AreEqual("Mary", elements[1].Value.ToString());
                Assert.AreEqual("woman", elements[1].Name);
            }, (s, c) => Tuple.Create(s, c));
            feClient.LoadCnlFromString(string.Join("\r\n", cnlSentences), true, true);
        }