public static KnowledgeClassifier <string> Assert(this KnowledgeClassifier <string> classifier, string expectedClass, params string[] nodesData)
        {
            foreach (var nodeData in nodesData)
            {
                var node        = classifier.Knowledge.GetNode(nodeData);
                var actualClass = classifier.Classify(node);

                U.Assert.AreEqual(expectedClass, actualClass, "Incorrect classification for '" + nodeData + "'");
            }
            return(classifier);
        }
Beispiel #2
0
        private static void KnowledgeClassifier()
        {
            var dataLayer = new PresidentLayer();
            var graph     = new ComposedGraph(dataLayer);

            var node1 = graph.GetNode("Barack_Obama");
            var node2 = graph.GetNode("Miloš_Zeman");
            var node3 = graph.GetNode("Michelle_Obama");

            var log = new MultiTraceLog(new[] { node1, node2, node3 }, graph);

            var classifier = new KnowledgeClassifier <string>(graph);

            classifier.Advice(node1, "president");
            classifier.Advice(node2, "president");
            classifier.Advice(node3, "wife");

            var node4 = graph.GetNode("Ivana_Zemanová");
            var node5 = graph.GetNode("Andrej_Kiska");

            var test1 = classifier.Classify(node4);
            var test2 = classifier.Classify(node5);
        }
Beispiel #3
0
        internal void Filter(KnowledgeClassifier <bool> knowledgeClassifier)
        {
            if (knowledgeClassifier.Root == null)
            {
                //there is no initialization yet
                return;
            }

            var newLayer = new HashSet <NodeReference>();

            foreach (var node in _accumulator)
            {
                var isAccepted = knowledgeClassifier.Classify(node);
                if (isAccepted)
                {
                    newLayer.Add(node);
                }
            }

            _accumulator = newLayer;
        }
Beispiel #4
0
        public string GetPattern(IEnumerable <NodeReference> nodes)
        {
            switch (nodes.Count())
            {
            case 0:
                throw new NotSupportedException("Cannot get patter for zero nodes");

            case 1:
                if (_singleDefaultValue != null)
                {
                    return(_singleDefaultValue);
                }
                return(SingleNodeClassifier.Classify(nodes.First()));

            default:
                if (_multiDefaultValue != null)
                {
                    return(_multiDefaultValue);
                }

                //TODO other nodes can be also taken into consideration
                return(MultipleNodesClassifier.Classify(nodes.First()));
            }
        }