public void ToCnlStatementList()
        {
            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.ToCNLStatementList(true);

            Assert.AreEqual(cnlSentences.Count(), cnlOut.Count());
            for (int i = 0; i < cnlOut.Count(); i++)
            {
                Assert.AreEqual(cnlOut[i].CnlStatement, cnlSentences[i]);
                if (i == 0)
                {
                    CheckStatementCount(cnlOut[i], 1, 1, 0, 0);
                }
                else if (i == 1)
                {
                    CheckStatementCount(cnlOut[i], 2, 0, 0, 0);
                }
            }
        }
Exemple #2
0
        public void DescribeInstancesTest()
        {
            List <string> instances = new List <string>()
            {
                "John", "Mark"
            };
            var cnlSentences = new List <string>()
            {
                "John is a man.",
                "John has-nickname equal-to 'Jojo'.",
                "John has-friend Martha.",

                "Mark is a man.",
                "Mark has-nickname equal-to 'Maro'.",
                "Mark has-friend Mery."
            };

            var feClient = new CogniPySvr();

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

            var result = feClient.DescribeInstances("a man");
            var instancesFromResult = result.Keys.ToList();

            CollectionAssert.AreEquivalent(instances, instancesFromResult);
        }
        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));
            }
        }
Exemple #4
0
        public void ToCNLStatementListTest(bool includeImplicit)
        {
            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."
            };

            var feClient = new CogniPySvr();

            feClient.LoadCnlFromString(string.Join("\r\n", cnlSentences.Union <string>(new List <string>()
            {
                "Comment: This comment should not be returned."
            })), true, true);



            var sentencesReturned = feClient.ToCNLStatementList(includeImplicit);

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

            if (includeImplicit)
            {
                Assert.AreEqual(13, sentencesReturned.Count);
            }
            else
            {
                CollectionAssert.AreEquivalent(cnlSentences, sentencesReturned.Select(s => s.CnlStatement));
            }
        }
Exemple #5
0
        public void GetSubConceptsTest(string cnl, bool direct, string[] asserts)
        {
            var cnlSentences = new List <string>()
            {
                "Every location-form is a form.",
                "Every data-location-form is a location-form.",
                "Every data-location-form[sfo] is a location-form.",
                "Data-Location-Form is a data-location-form.",

                "Data-Location-Form is a data-location-form[sfo].",
                "Data-Location-Form[sfo] is a data-location-form.",

                "References: [sfo] 'http://sfo.com' ('http://sfo.com') ."
            };

            var feClient = new CogniPySvr();

            feClient.LoadCnlFromString(string.Join("\r\n", cnlSentences), true, true);
            var subconcepts = feClient.GetSubConceptsOf(cnl, direct);

            if (asserts.Count() == 0)
            {
                CollectionAssert.IsEmpty(subconcepts);
            }
            else
            {
                CollectionAssert.IsNotEmpty(subconcepts);
                CollectionAssert.AreEquivalent(asserts, subconcepts);
            }
        }
Exemple #6
0
        public void DescribeInstanceQueryWithPrefixTest()
        {
            var cnlSentences = new List <string>()
            {
                "John[sfo] is a man.",
                "John[sfo] has-nickname equal-to 'Jojo'.",
                "John[sfo] has-friend Martha.",
                "References: [sfo] 'http://sfo.com' ('http://sfo.com') ."
            };

            var feClient = new CogniPySvr();

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

            var result = feClient.DescribeInstances("John[sfo]");

            Assert.AreEqual(1, result.Count);

            var instanceDescription = result.FirstOrDefault();

            Assert.IsNotNull(instanceDescription);

            Assert.AreEqual("John[sfo]", instanceDescription.Key);
            Assert.AreEqual(1, instanceDescription.Value.AttributeValues.Count);

            Assert.True(instanceDescription.Value.AttributeValues.ContainsKey("has-nickname"));
            Assert.AreEqual("Jojo", (string)instanceDescription.Value.AttributeValues["has-nickname"].First());

            Assert.AreEqual(1, instanceDescription.Value.RelatedInstances.Count);
            Assert.True(instanceDescription.Value.RelatedInstances.ContainsKey("has-friend"));
            Assert.AreEqual("Martha", instanceDescription.Value.RelatedInstances["has-friend"].First());
        }
        public void StrageBug2a2BUG()
        {
            var reasoner = new CogniPySvr();

            reasoner.LoadCnlFromString("Bubu influences-with-weight-of-1 Dudu.", true, true);
            var toDel = "Bubu influence-with-weight-of-1 Dudu.";

            reasoner.KnowledgeDelete(toDel, true);
            var cnl = reasoner.ToCNL(false);
        }
        public void FromToUriTest(string cnlName, string type)
        {
            var feClient = new CogniPySvr();

            feClient.LoadCnlFromString("John is a man.\r\nReferences: [TIS] (\"http://www.somenamespace.com/\").", true, false);

            var uri            = feClient.UriFromCnl(cnlName, type);
            var transformedCnl = feClient.CnlFromUri(uri, type);

            Assert.AreEqual(cnlName, transformedCnl);
        }
        public void IncorrectCnlTest()
        {
            var feClient = new CogniPySvr();

            try
            {
                feClient.LoadCnlFromString(string.Join("\r\n", "Every man is a human-being"), true, true);
            }
            catch (Exception ex)
            {
                return;
            }
            Assert.Fail("I was expecting the client to throw a parse exception.");
        }
        public void OneSentenceIncorrectCnlTestII()
        {
            var feClient  = new CogniPySvr();
            var knowledge = "Vendor-0 has-value equal-to 3.4880694143167.\r\nVendor-0 is a vendor.\r\nVendor-0 has-message-type equal-to Receipt'.\r\n\r\n";

            try
            {
                feClient.LoadCnlFromString(knowledge, true, true);
            }
            catch (Exception ex)
            {
                return;
            }
            Assert.Fail("I was expecting the client to throw a parse exception.");
        }
        public void SparqlQueryToMaterializedGraphTest()
        {
            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, true);
            var res = feClient.SparqlQueryInternal("SELECT * WHERE {?x rdf:type :man}");

            Assert.IsNotNull(res);
            Assert.AreEqual(1, res.Item2.Count());
        }
Exemple #12
0
        public void CloneTest(string cnl, bool direct, string[] asserts)
        {
            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.",
                "Kiki must hava a miki.",

                "Data-Location-Form is a data-location-form[sfo].",
                "Data-Location-Form[sfo] is a data-location-form.",
                "References: [sfo] 'http://sfo.com' ('http://sfo.com') .",
                @"Annotations:
bela Concept: ""comment"":rdfs 'kaka maka'
bela Concept: ""comment"":rdfs 'biba'@en
_Ala Instance: ""backwardCompatibleWith"":owl 'sdsgd'@ar
.",
                "References: [sfo] 'http://sfo.com' ('http://sfo.com') ."
            };

            var feClient = new CogniPySvr();

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

            var superconcepts = feClient.GetSuperConceptsOf(cnl, direct);

            var clone1 = feClient.CloneForAboxChangesOnly();

            clone1.KnowledgeInsert("Clone-1 is a form.", true, true);
            var superconcepts2 = clone1.GetSuperConceptsOf(cnl, direct);

            var clone2 = feClient.CloneForAboxChangesOnly();

            clone2.KnowledgeInsert("Clone-2 is a form.", true, true);

            var resClone1 = clone1.GetInstancesOf("a form", false);
            var resClone2 = clone2.GetInstancesOf("a form", false);

            CollectionAssert.DoesNotContain(resClone2, "Clone-1");
            CollectionAssert.DoesNotContain(resClone1, "Clone-2");

            CollectionAssert.IsNotEmpty(superconcepts2);
            CollectionAssert.AreEquivalent(asserts, superconcepts2);

            var instances = clone2.GetInstancesOf("a form", direct);

            CollectionAssert.DoesNotContain(instances, "Clone-1");
        }
Exemple #13
0
        public void GetConstraintsTest(string subjectToCheck, Modality constraint, IEnumerable <string> relationsToCheck, IEnumerable <string> objectsToCheck)
        {
            var cnlSentences = new List <string>()
            {
                "Every data-location-form is a form.",
                "Every data-location-form can concern a data-location-section-1.",
                "Every data-location-form must concern a data-location-section-2.",
                "Data-Location-Form is a data-location-form.",

                "If a data-location-form is a bubu then the data-location-form is a bibi.",
                "Every bubu must have-value (some string value).",
                "Every bubu must have-value (some datetime value).",
                "Every bubu must have-value (some integer value).",
                "Every bubu must have-value (some real value).",
                "Every bubu must have-value (some boolean value).",
                "Every bubu must have-value (some duration value).",
                "Every bubu must have-this[sfo] a smth[sfo].",
                "Bubu is a bubu.",
                "Bubu[sfo] is a bubu.",

                "Every some-concept[sfo] must concern an other-concept.",

                "Element-1-Form-D-14-08-2018-T-14-50-7[<http://www.sfo.cognitum.eu/Survey/a536f37b-00f5-492d-80ff-c84948d862ec#>] is a some-concept[sfo].",

                "References: [sfo] 'http://sfo.com' ('http://sfo.com') ."
            };

            var feClient = new CogniPySvr();

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

            var sw = new Stopwatch();

            sw.Start();
            var constraints = feClient.GetConstraints(new List <string>()
            {
                subjectToCheck
            });                                                                               //, "a data-location-form", "Baba[sfo]", "baba[sfo]"

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

            CollectionAssert.Contains(constraints.Keys, subjectToCheck);
            CollectionAssert.IsSubsetOf(relationsToCheck, constraints[subjectToCheck].Relations[constraint]);
            CollectionAssert.IsSubsetOf(objectsToCheck, constraints[subjectToCheck].ThirdElement[constraint]);
        }
        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 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());
        }
        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());
        }
Exemple #17
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());
        }
Exemple #19
0
        public void GetAnnotationsTest(string ax, string lan, string[] signature)
        {
            var cnlSentences = new List <string>()
            {
                "Every data-location-form is a form.",
                @"Annotations:
bela Concept: ""comment"":rdfs 'kaka maka'
bela Concept: ""comment"":rdfs 'biba'@en
_Ala Instance: ""backwardCompatibleWith"":owl 'sdsgd'@ar
."
            };

            var feClient = new CogniPySvr();

            feClient.LoadCnlFromString(string.Join("\r\n", cnlSentences), true, true);
            var result = feClient.GetAnnotationsForSignature(signature);

            //TODO: add also test for adding annotation on a role.
            Assert.Contains(ax, result.Select(x => x.Value.ToString()).ToList());
            Assert.True(rgxForCnlFormat.IsMatch(result.Select(ann => ann.Property).First()));
            Assert.Contains(lan, result.Select(x => x.Language).ToList());
        }
        public void BasciSWRLRuleReasoning()
        {
            var cnlSentences = new List <string>()
            {
                "If an element-1-form concern[sfo] a subject[sfo] and an element-2-holder-form concern[sfo] a subject[sfo] then the element-2-holder-form is an element-2-form.",

                "Element-1-Form is an element-1-form.",
                "Doupa is a subject[sfo].",
                "Element-2-Holder-Form is an element-2-holder-form.",

                "Element-1-Form concerns[sfo] Doupa .",
                "Element-2-Holder-Form concerns[sfo] Doupa .",
            };
            var feClient = new CogniPySvr();

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


            var result = feClient.GetSuperConceptsOf("Element-2-Holder-Form", false);

            Assert.Contains("element-2-form", result);
        }
Exemple #21
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);
        }
Exemple #22
0
        public void DescribeInstancesNoRelationNoAttributeTest()
        {
            var cnlSentences = new List <string>()
            {
                "John is a man.",
                "John has-friend Martha.",

                "Mark is a man.",
                "Mark has-nickname equal-to 'Maro'."
            };

            var feClient = new CogniPySvr();

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

            var result = feClient.DescribeInstances("a man");

            Assert.AreEqual("Martha", result["John"].RelatedInstances["has-friend"].First());
            Assert.AreEqual(0, result["John"].AttributeValues.Count);

            Assert.AreEqual("Maro", (string)result["Mark"].AttributeValues["has-nickname"].First());
            Assert.AreEqual(0, result["Mark"].RelatedInstances.Count);
        }
        public void MaterializationTest(bool materialize)
        {
            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, materialize: materialize);
            //var res = feClient.SparqlQuery("SELECT * WHERE {?x ?y ?z}");
            var result = feClient.ToCNL(true, true);

            Assert.IsNotNull(result);
            if (materialize)
            {
                Assert.IsTrue(result.Contains("John is a human-being."));
            }
            else
            {
                Assert.IsFalse(result.Contains("John is a human-being."));
            }
        }
Exemple #24
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:")));
        }
        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);
        }