Example #1
0
        internal QuestionEntry GetQuestionEntry(ParsedUtterance question)
        {
            QuestionEntry entry;

            if (!_questions.TryGetValue(question.OriginalSentence, out entry))
            {
                _questions[question.OriginalSentence] = entry = new QuestionEntry(question.OriginalSentence, Graph);
                var pattern = getPatternQuestion(entry);

                List <QuestionEntry> patternQuestions;
                if (!_questionsPatternIndex.TryGetValue(pattern, out patternQuestions))
                {
                    _questionsPatternIndex[pattern] = patternQuestions = new List <QuestionEntry>();
                }

                patternQuestions.Add(entry);
            }

            return(entry);
        }
Example #2
0
        private string getPatternQuestion(QuestionEntry question)
        {
            var builder = new StringBuilder();

            foreach (var word in question.ParsedQuestion.Words)
            {
                if (builder.Length > 0)
                {
                    builder.Append(' ');
                }

                if (Graph.HasEvidence(word))
                {
                    builder.Append("#");
                }
                else
                {
                    builder.Append(word);
                }
            }

            return(builder.ToString());
        }
Example #3
0
        private IEnumerable <QuestionEntry> getPatternEquivalentEntries(QuestionEntry entry)
        {
            var pattern = getPatternQuestion(entry);

            return(_questionsPatternIndex[pattern]);
        }
Example #4
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);
        }
Example #5
0
 internal AnswerReport(QuestionEntry question, NodeReference answer)
 {
     Question = question;
     Answer   = answer;
 }