Ejemplo n.º 1
0
        public void SR11BUG()
        {
            var toinstert = new string[] {
                "Deal-Criteria-2 is a reputational-risk-network-deal-criteria.",
                "Deal-Criteria-2 is a reputational-risk-network-component.",
                "Deal-Criteria-2 has-sql-name equal-to ''.",
                "Deal-Criteria-2 has-availability equal-to 'Data-Available'.",
                "Deal-Criteria-2 has-unit equal-to ''.",
                "Deal-Criteria-2 has-aggregation equal-to 'None'.",
                "Annotations:\r\n_Deal-Criteria-2 Instance: node-label 'Importance'@en\r\n_Deal-Criteria-2 Instance: node-description 'Importance'@en\r\n."
            };
            var reasoner = new CogniPySvr();

            reasoner.LoadCnl(Path.Combine(AssemblyDirectory, "TestFiles", "ont2.encnl"), true, true);
            foreach (var l in toinstert)
            {
                reasoner.KnowledgeInsert(l, true, true);
            }
            var sups = reasoner.GetSuperConceptsOf("Deal-Criteria-2", false);

            Assert.AreEqual(sups.Count(), 4);

            var descr = reasoner.DescribeInstances("Deal-Criteria-2");

            Assert.AreEqual(descr.Count(), 1);
        }
        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));
            }
        }
Ejemplo n.º 3
0
        public void GetInstancesOfTest()
        {
            var cnlSentencesToInsert = new List <string>()
            {
                "Survey[<http://www.sfo.cognitum.eu/Survey/29ed4b1d-fa55-479b-93aa-7773b30bda6b#>] is a subject[sfo].",
            };

            var feClient = new CogniPySvr();

            feClient.LoadCnl(Path.Combine(AssemblyDirectory, "TestFiles", "CSHC.encnl"), true, true);
            feClient.KnowledgeInsert(cnlSentencesToInsert.First(), true, true);
            feClient.KnowledgeInsert(cnlSentencesToInsert.Last(), true, true);

            var instances = feClient.GetInstancesOf("a subject[sfo]", false);

            Assert.Contains("Survey[<http://www.sfo.cognitum.eu/Survey/29ed4b1d-fa55-479b-93aa-7773b30bda6b#>]", instances);

            var instances2 = feClient.GetInstancesOf("Survey[<http://www.sfo.cognitum.eu/Survey/29ed4b1d-fa55-479b-93aa-7773b30bda6b#>]", false);

            Assert.Contains("Survey[<http://www.sfo.cognitum.eu/Survey/29ed4b1d-fa55-479b-93aa-7773b30bda6b#>]", instances2);
        }
Ejemplo n.º 4
0
        public void NonInitializedTest()
        {
            var feClient = new CogniPySvr();

            try
            {
                feClient.KnowledgeInsert("Every man is a human-being.", true, true);
            }
            catch (InvalidOperationException ex)
            {
                return;
            }
            Assert.Fail("Expecting an InvalidOperationException.");
        }
        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());
        }
Ejemplo n.º 6
0
        public void AddKnowledgeGetSuperConcept()
        {
            var cnlSentences = new List <string>()
            {
                "Every man is a human-being."
            };
            var feClient = new CogniPySvr();

            feClient.LoadCnlFromString(string.Join("\r\n", cnlSentences), true, true);
            feClient.KnowledgeInsert("John is a man.", true, true);

            var res1 = feClient.GetSuperConceptsOf("John", false);

            Assert.Contains("human-being", res1);

            var res2    = feClient.SparqlQueryInternal(feClient.SelectSuperconceptsSPARQL("John", false));
            var cnlRes2 = feClient.TranslateQueryResultsIntoCnlInPlace(res2);

            Assert.Contains("human-being", cnlRes2.Item2.SelectMany(x => x).ToList());
        }
Ejemplo n.º 7
0
        public void GetConstraintsBig()
        {
            var feClient = new CogniPySvr();

            feClient.LoadCnl(Path.Combine(AssemblyDirectory, "TestFiles", "CSHC.encnl"), true, true);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            feClient.KnowledgeInsert("Element-1-Form-D-14-08-2018-T-14-55-26[<http://www.sfo.cognitum.eu/Survey/5d09ffea-d461-4335-a3c9-03e74aec92eb#>] is a form[sfo].", true, true);
            sw.Stop();
            var elapUpdate = sw.ElapsedMilliseconds;

            sw.Restart();
            var constraints = feClient.GetConstraints(new List <string>()
            {
                "form[sfo]", "element-1-form", "Element-1-Form-D-14-08-2018-T-14-55-26[<http://www.sfo.cognitum.eu/Survey/5d09ffea-d461-4335-a3c9-03e74aec92eb#>]"
            });

            sw.Stop();
            var elap = sw.ElapsedMilliseconds;

            Assert.Contains("form[sfo]", constraints.Keys);
            Assert.Contains("element-1-form", constraints.Keys);
            Assert.Contains("Element-1-Form-D-14-08-2018-T-14-55-26[<http://www.sfo.cognitum.eu/Survey/5d09ffea-d461-4335-a3c9-03e74aec92eb#>]", constraints.Keys);
            Assert.IsTrue(elap < 1000);

            sw.Restart();
            var res1 = feClient.GetSuperConceptsOf("Element-1-Form-D-14-08-2018-T-14-55-26[<http://www.sfo.cognitum.eu/Survey/5d09ffea-d461-4335-a3c9-03e74aec92eb#>]", false);

            Assert.Contains("form[sfo]", res1);
            sw.Stop();
            var elapReasoner = sw.ElapsedMilliseconds;

            sw.Restart();
            var res2       = feClient.SparqlQueryInternal(feClient.SelectSuperconceptsSPARQL("Element-1-Form-D-14-08-2018-T-14-55-26[<http://www.sfo.cognitum.eu/Survey/5d09ffea-d461-4335-a3c9-03e74aec92eb#>]", false));
            var cnlRes2    = feClient.TranslateQueryResultsIntoCnlInPlace(res2);
            var elapSparql = sw.ElapsedMilliseconds;

            Assert.Contains("form[sfo]", cnlRes2.Item2.SelectMany(x => x).ToList());
        }
Ejemplo n.º 8
0
        public void GetInstancesOfWhenInsertWithAnnotationsTest()
        {//BUG: SR-10
            var initialOntology = new List <string>()
            {
                "Every-single-thing has-label nothing-but (some string value).",
                "Every deal-criteria is a network-component.",
                "Every reputational-risk-component is a network-component.",
                "Every reputational-risk-network-deal-criteria is a deal-criteria.",
                "Every reputational-risk-network-deal-criteria is a reputational-risk-network-component.",
                "Every reputational-risk-top-outcome is a reputational-risk-network-component.",
                "Reputational-Risk is a reputational-risk-top-outcome.",
                "Reputational-Risk has-label equal-to 'Reputational Risk'.",
                "Reputational-Risk is a positive-outcome.",
                "Reputational-Risk has-network-id equal-to 'Net-re'.",
                "Reputational-Risk is a network.",
                "Deal-Criteria-2 influences-with-weight-of-1 Reputational-Risk."
            };

            var feClient = new CogniPySvr();

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

            var toInsert = new List <string>()
            {
                "Deal-Criteria-2 is a reputational-risk-network-deal-criteria.",
                "Deal-Criteria-2 is a reputational-risk-network-component.",
                "Deal-Criteria-2 has-sql-name equal-to ''.",
                "Deal-Criteria-2 has-availability equal-to 'Data-Available'.",
                "Deal-Criteria-2 has-unit equal-to ''.",
                "Deal-Criteria-2 has-aggregation equal-to 'None'.",
                "Annotations:\r\n_Deal-Criteria-2 Instance: node-label 'Importance'@en\r\n_Deal-Criteria-2 Instance: node-description 'Importance'@en\r\n."
            };

            feClient.KnowledgeInsert(string.Join("\r\n", toInsert), true, true);

            var instances = feClient.GetInstancesOf("a reputational-risk-network-component", false);

            Assert.AreEqual(2, instances.Count);
        }
        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());
        }
Ejemplo n.º 10
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:")));
        }