private static void runActions(ContextPool pool, ActionBlock actionBlock, NodesSubstitution substitutions = null, bool useFiltering = true) { if (substitutions != null) { pool.SetSubstitutions(substitutions); } var sortedActions = actionBlock.Actions.OrderByDescending((a) => a.Priority).ToArray(); var hasPushAction = sortedActions.Any(action => action is PushAction); if (hasPushAction) { //start new topic - but only once! (multiple pushes can appear) pool.ClearAccumulator(); } foreach (var action in sortedActions) { action.Run(pool); } if (useFiltering && pool.ActiveCount > 1) { pool.Filter(actionBlock.OutputFilter); } }
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); }