public void RulesKeptAfterMergeTest()
        {
            var feClient = new CogniPySvr();
            // reason the new context
            var CnlContent = new List <string>()
            {
                "If a man is a human-being then the man is a cat."
            };
            var CnlToAdd = new List <string>()
            {
                "John is a man."
            };

            feClient.LoadCnlFromString(string.Join("\r\n", CnlContent), true, true);
            feClient.KnowledgeInsert(string.Join("\r\n", CnlToAdd), true, true);
            var mergedCnl = feClient.ToCNLList(true, true, true);

            Assert.AreEqual(2, mergedCnl.Count());
            foreach (var cnl in CnlContent)
            {
                Assert.IsTrue(mergedCnl.Any(x => x == cnl));
            }

            foreach (var cnl in CnlToAdd)
            {
                Assert.IsTrue(mergedCnl.Any(x => x == cnl));
            }
        }
Exemplo n.º 2
0
        public void ToCnlList()
        {
            var cnlSentences = new List <string>()
            {
                "John is a man.",
                "Every man is a human-being."
            };
            var feClient = new CogniPySvr();

            feClient.LoadCnlFromString(string.Join("\r\n", cnlSentences), true, false);
            var cnlOut = feClient.ToCNLList(true, true, true);

            Assert.AreEqual(cnlSentences.Count(), cnlOut.Count());
            for (int i = 0; i < cnlOut.Count(); i++)
            {
                Assert.AreEqual(cnlSentences[i], cnlOut[i]);
            }
        }
        public void AddCnl()
        {
            var feClient = new CogniPySvr();
            // reason the new context
            var CnlContent = "Every man is a human-being.\r\n Every human-being has-name equal-to 'aaa'.";
            var CnlToAdd   = new List <string>()
            {
                "John is a man."
            };

            feClient.LoadCnlFromString(CnlContent, true, true);
            feClient.KnowledgeInsert(string.Join("\r\n", CnlToAdd), true, true);
            var mergedCnl = feClient.ToCNLList(false);

            foreach (var cnl in CnlToAdd)
            {
                Assert.IsTrue(mergedCnl.Any(x => x == cnl));
            }
            Assert.AreEqual(3, mergedCnl.Count());
        }
Exemplo n.º 4
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 AddNumberCnl()
        {
            var feClient = new CogniPySvr();
            // reason the new context
            var CnlContent = "Vendor-0 is a vendor.";
            var CnlToAdd   = new List <string>()
            {
                "Vendor-0 has-latitude equal-to 43.737345.",
                "Vendor-0 has-longitude equal-to -79.442286."
            };

            feClient.LoadCnlFromString(CnlContent, true, false);
            feClient.KnowledgeInsert(string.Join("\r\n", CnlToAdd), true, false);

            var mergedCnl = feClient.ToCNLList(false);

            foreach (var cnl in CnlToAdd)
            {
                Assert.IsTrue(mergedCnl.Any(x => x == cnl));
            }
            Assert.AreEqual(3, mergedCnl.Count());
        }
Exemplo n.º 6
0
        public void KnowledgeInsertAnnotationsTest(bool includeImplicit, bool removeTrivials)
        {
            var cnlSentences = new List <string>()
            {
                "Data-Location-Form is a data-location-form.",
                "Annotations: _Data-Location-Form Instance: description 'A data location form.'@en.",
                "Comment: This comment should not be returned as CNL statement."
            };

            var feClient = new CogniPySvr();

            feClient.LoadCnlFromString(string.Join("\r\n", cnlSentences), true, true);


            var toInsert = new List <string>()
            {
                "Operational-Risk is a thing.",
                "Annotations: _Operational-Risk Instance: network-description 'Network of operational risk.'@en."
            };

            feClient.KnowledgeInsert(string.Join("\r\n", toInsert), true, true);
            var annots = feClient.GetAnnotationsForSignature(new List <string>()
            {
                "Operational-Risk"
            });

            Assert.IsTrue(annots.Where(a => a.Property == "network-description").Count() > 0);

            //Check for number of Annotations: blocks, should be exactly 1
            var toCnl = feClient.ToCNL(includeImplicit, true);

            Assert.AreEqual(1, toCnl.Split(' ').Where(tok => tok.Contains("Annotations:")).Count());

            var toCnlList = feClient.ToCNLList(includeImplicit, removeTrivials, true);

            Assert.AreEqual(1, toCnlList.Count(s => s.Contains("Annotations:")));
        }