public void KnowledgeTest_RelationImplicationChainingFamily()
        {
            var target = new KnowledgeStore();

            target.AddAttribute(new KnowledgeAttribute {
                Attribute = "cat", Subject = "Pixel"
            }, new HashSet <string> {
                "test"
            });
            target.AddAttribute(new KnowledgeAttribute {
                Attribute = "cat", Subject = "Tiger"
            }, new HashSet <string> {
                "test"
            });
            target.AddRelation(new KnowledgeRelation {
                Relation = "brotherof", Subject = "Tiger", Target = "Pixel"
            }, new HashSet <string> {
                "test"
            });
            target.AddImplication(new KnowledgeImplication {
                Implicator = "brotherof", Implied = "siblingof"
            }, new HashSet <string> {
                "test"
            });
            target.AddImplication(new KnowledgeImplication {
                Implicator = "siblingof", Implied = "familyof"
            }, new HashSet <string> {
                "test"
            });
            var actual = target.ListAllRelated("familyof", "Pixel");

            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual("Tiger", actual.Single());
        }
        public void KnowledgeTest_GetAllVariablesFromRelations()
        {
            var target = new KnowledgeStore();

            target.AddRelation(new KnowledgeRelation {
                Relation = "brotherOf", Subject = "Tiger", Target = "Pixel"
            }, new HashSet <string> {
                "test"
            });

            var actual = target.GetAllVariables();

            Assert.AreEqual(2, actual.Count);
            Assert.IsTrue(actual.Contains("Tiger"));
            Assert.IsTrue(actual.Contains("Pixel"));
        }
Exemplo n.º 3
0
        public static KnowledgeStore Create(BaseObject root)
        {
            var frame = new KnowledgeStore();

            frame.AddAttribute(new KnowledgeAttribute
            {
                Attribute = root.GetType().Name,
                Subject   = root.ToString()
            }, root.ToString());
            var fields = GetAllProperties(root);

            foreach (var field in fields)
            {
                frame.AddRelation(new KnowledgeRelation
                {
                    Subject  = field.Value,
                    Relation = $"{field.Key} of",
                    Target   = root.ToString()
                }, root.ToString());
            }
            return(frame);
        }