Esempio n. 1
0
        internal bool MoveNext()
        {
            _rules.Clear();
            _selectedNodes.Clear();


            var nextSegment = findNextSegment();

            if (nextSegment == null)
            {
                //there are no more available segments.
                return(false);
            }

            _factory.Enqueue(nextSegment);

            _rules.AddRange(createRule(nextSegment));
            _selectedNodes.UnionWith(findSelectedNodes(nextSegment));


            ConsoleServices.Print("NEW TOPIC", Rules);
            ConsoleServices.PrintEmptyLine();

            return(true);
        }
Esempio n. 2
0
        private void setFilter(NodeReference correctAnswerNode, ActionBlock actionBlock, ContextPool pool)
        {
            foreach (var node in pool.ActiveNodes)
            {
                var isInOutput = node.Equals(correctAnswerNode);
                actionBlock.OutputFilter.Advice(node, isInOutput, false);
            }

            actionBlock.OutputFilter.Retrain();
            ConsoleServices.Print(actionBlock.OutputFilter.Root);
        }
Esempio n. 3
0
        private static double getDistance(NodeReference node1, NodeReference node2, ComposedGraph graph)
        {
            var paths = graph.GetPaths(node1, node2, MaximumGraphDepth, MaximumGraphWidth).Take(1000);

            double minDistance = double.MaxValue;

            foreach (var path in paths)
            {
                ConsoleServices.Print(path);
                var distance = getDistance(path);

                if (minDistance > distance)
                {
                    minDistance = distance;
                }
            }

            return(minDistance);
        }
Esempio n. 4
0
        private void addRule(ConstraintPoolRule[] rules, HashSet <NodeReference> remainingNodes)
        {
            var isCompleteRule = remainingNodes.Count == 0;

            if (isCompleteRule)
            {
                //complete rules don't need more extending
                _completeRules.Add(rules);
            }
            else
            {
                //rule is incomplete
                _incompleteRuleSequence.Add(rules);
                _remainingNodes.Add(remainingNodes);
            }

            ConsoleServices.Print("RULES", rules, remainingNodes);
            ConsoleServices.PrintEmptyLine();
        }
Esempio n. 5
0
        private static void RuleQuestionTest(string dbPath)
        {
            var loader    = loadDB(dbPath);
            var graph     = new ComposedGraph(loader.DataLayer);
            var generator = new StructuredInterpretationGenerator(graph);

            var denotation1 = graph.GetNode("Barack Obama");
            var q1          = "Who is United States of America president?";

            var denotation2 = graph.GetNode("Vladimir Putin");
            var q2          = "Who is Russia president?";

            var q3          = "Who is Czech republic president?";
            var denotation3 = graph.GetNode("Miloš Zeman");

            generator.AdviceAnswer(q1, denotation1);
            generator.AdviceAnswer(q2, denotation2);
            generator.Optimize(5000);

            var interpretations = new List <Ranked <StructuredInterpretation> >();

            foreach (var evidence in generator.GetEvidences(q3))
            {
                foreach (var interpretation in evidence.AvailableRankedInterpretations)
                {
                    interpretations.Add(interpretation);
                }
            }

            interpretations.Sort((a, b) => a.Rank.CompareTo(b.Rank));
            foreach (var interpretation in interpretations)
            {
                var answer = generator.Evaluate(q3, interpretation.Value);
                ConsoleServices.Print(interpretation);
                ConsoleServices.Print(answer);
                ConsoleServices.PrintEmptyLine();
            }

            var qGenerator = new QuestionGenerator(generator);

            //var questions = Generator.FindDistinguishingNodeQuestions();
            throw new NotImplementedException();
        }