예제 #1
0
        private IEnumerable <NodeReference> getActualAnswer(PoolHypothesis hypothesis)
        {
            var pool = Pool.Clone();

            pool.SetSubstitutions(hypothesis.Substitutions);
            foreach (var action in hypothesis.ActionBlock.Actions)
            {
                action.Run(pool);
            }

            return(pool.ActiveNodes);
        }
예제 #2
0
        private bool updateFilterPart(NodeReference correctAnswerNode, PoolHypothesis bestHypothesis)
        {
            var pool = Pool.Clone();

            runActions(pool, bestHypothesis.ActionBlock, bestHypothesis.Substitutions, false);
            if (pool.ActiveNodes.Contains(correctAnswerNode))
            {
                setFilter(correctAnswerNode, bestHypothesis.ActionBlock, pool);
                return(true);
            }

            return(false);
        }
예제 #3
0
        internal IEnumerable <NodeReference> GetAnswer(PoolHypothesis bestHypothesis)
        {
            if (bestHypothesis == null)
            {
                return(new NodeReference[0]);
            }

            var pool = Pool.Clone();

            var substitutions = bestHypothesis.Substitutions;
            var block         = bestHypothesis.ActionBlock;

            runActions(pool, block, substitutions);

            return(pool.ActiveNodes);
        }
예제 #4
0
        internal IEnumerable <PoolHypothesis> GetSortedHypotheses(ParsedUtterance utterance)
        {
            var scoredActions  = Triggers.FindMapping(utterance);
            var availableNodes = GetRelatedNodes(utterance).ToArray();

            var result = new List <PoolHypothesis>();

            foreach (var scoredAction in scoredActions)
            {
                var substitutions = GetSubstitutions(availableNodes, scoredAction.Value.RequiredSubstitutions, Graph);

                var scoredHypothesis = new PoolHypothesis(substitutions, scoredAction);
                result.Add(scoredHypothesis);
            }

            result.Sort((a, b) => b.Control.Score.CompareTo(a.Control.Score));
            return(result);
        }
예제 #5
0
        private bool updatePushPart(QuestionEntry questionEntry, PoolHypothesis hypothesis, ContextPool pool)
        {
            pool = pool.Clone();
            if (!questionEntry.IsContextFree)
            {
                //TODO: we are now not able to learn this
                return(false);
            }

            pool.ClearAccumulator();
            //we don't need substitute anything - we ran rules with original nodes only
            pool.SetSubstitutions(null);

            var pushActions   = new List <PushAction>();
            var insertActions = new List <InsertAction>();

            //traverse all entries and collect all update/insert rules, that will
            //cover every correct answer
            var equivalentEntries = getPatternEquivalentEntries(questionEntry);
            var correctAnswers    = new HashSet <NodeReference>();

            foreach (var entry in equivalentEntries)
            {
                if (!entry.HasAnswer)
                {
                    continue;
                }

                if (!pool.ContainsInAccumulator(entry.CorrectAnswer))
                {
                    var action = createPushAction(entry.Question, entry.CorrectAnswer);
                    if (action == null)
                    {
                        //we cannot derive push rule
                        insertActions.Add(new InsertAction(entry.CorrectAnswer));
                        pool.Insert(entry.CorrectAnswer);
                    }
                    else
                    {
                        //we have got push rule - we will apply it without constraining and filtering
                        action.Run(pool);
                        if (entry.QuestionNodes.Count != hypothesis.Substitutions.OriginalNodes.Count)
                        {
                            //TODO we are not able to update this for now
                            return(false);
                        }

                        action = action.Resubstitution(entry.QuestionNodes, hypothesis.Substitutions.OriginalNodes);
                        pushActions.Add(action);
                    }

                    correctAnswers.Add(entry.CorrectAnswer);
                }
            }

            hypothesis.ActionBlock.UpdatePush(pushActions);
            hypothesis.ActionBlock.UpdateInsert(insertActions);

            foreach (var node in pool.ActiveNodes)
            {
                //TODO detection of inclusion collision in filter
                var isCorrect = correctAnswers.Contains(node);
                hypothesis.ActionBlock.OutputFilter.Advice(node, isCorrect);
            }
            return(true);
        }