/* * private int getNextState(int srcState, int action) * { * var matchedRules = rules.Where(r => r.srcState == srcState && r.action == action); * if (matchedRules.Count() > 0) * return matchedRules.First().dstState; * else * return -1; * }*/ public BotState getNextState(BotState srcState, string action) { var matchedRules = ruleNextActions.Where(r => r.srcState == srcState && r.action.isAction(action)); if (matchedRules.Count() > 0) { return(matchedRules.First().dstState); } else { var elseRule = ruleNextActions.Where(r => r.srcState == srcState && r.action.GetType() == typeof(ElseAction)); if (elseRule.Count() > 0) { return(elseRule.First().dstState); } else { return(BotStates.Invalid); } } }
public PostFunction getPostFunction(BotState preState, BotState nextState) { var spfList = rulePostFunctions.Where(spf => spf.preState == preState && spf.nextState == nextState); if (spfList.Count() > 0) { return(spfList.First().function); } else { spfList = rulePostFunctions.Where(spf => spf.preState == -1 && spf.nextState == nextState); if (spfList.Count() > 0) { return(spfList.First().function); } else { return (PostFunctionData pfd) => { } }; } } }
public void addRulePostFunction(BotState newState, PostFunction function) { rulePostFunctions.Add(new RulePostFunction(newState, BotStates.Invalid, function)); }
public void addRulePostFunction(BotState newState, BotState preState, PostFunction function) { rulePostFunctions.Add(new RulePostFunction(newState, preState, function)); }
private void addRuleNextAction(BotState srcState, IAction action, BotState dstState) { ruleNextActions.Add(new RuleNextAction(srcState, action, dstState)); }
public void addElseRule(BotState srcState, BotState dstState) { addRuleNextAction(srcState, new ElseAction(), dstState); }
public void addRegexRule(BotState srcState, string regexExpr, BotState dstState) { addRuleNextAction(srcState, new RegexAction(regexExpr), dstState); }
public void addRule(BotState srcState, BotState dstState) { addRuleNextAction(srcState, new LambdaAction(), dstState); }
public void addRule(BotState srcState, int action, BotState dstState) { addRuleNextAction(srcState, new NormalAction(action.ToString()), dstState); }
public void addRule(BotState srcState, string action, BotState dstState) { addRuleNextAction(srcState, new NormalAction(action), dstState); }
public RuleNextAction(BotState srcState, IAction action, BotState dstState) { this.srcState = srcState; this.action = action; this.dstState = dstState; }