/// <summary> /// Initializes a new instance of the <see cref="Expander"/> class. /// </summary> /// <param name="templates">Template list.</param> /// <param name="expressionParser">Given expression parser.</param> /// <param name="opt">Options for LG. including strictMode, replaceNull and lineBreakStyle.</param> public Expander(List <Template> templates, ExpressionParser expressionParser, EvaluationOptions opt = null) { Templates = templates; TemplateMap = templates.ToDictionary(x => x.Name); _lgOptions = opt; _expressionParser = expressionParser; // generate a new customized expression parser by injecting the template as functions ExpanderExpressionParser = new ExpressionParser(CustomizedEvaluatorLookup(expressionParser.EvaluatorLookup, true)); EvaluatorExpressionParser = new ExpressionParser(CustomizedEvaluatorLookup(expressionParser.EvaluatorLookup, false)); }
/// <summary> /// Expand a template with given name and scope. /// Return all possible responses instead of random one. /// </summary> /// <param name="templateName">Template name to be evaluated.</param> /// <param name="scope">The state visible in the evaluation.</param> /// <param name="opt">The evaluation option for current expander.</param> /// <returns>Expand result.</returns> public IList <object> ExpandTemplate(string templateName, object scope = null, EvaluationOptions opt = null) { CheckErrors(); var evalOpt = opt ?? LgOptions; var expander = new Expander(AllTemplates.ToList(), ExpressionParser, evalOpt); return(expander.ExpandTemplate(templateName, scope)); }
/// <summary> /// Initializes a new instance of the <see cref="Evaluator"/> class. /// </summary> /// <param name="templates">Template list.</param> /// <param name="expressionParser">Expression parser.</param> /// <param name="opt">Options for LG. </param> public Evaluator(List <Template> templates, ExpressionParser expressionParser, EvaluationOptions opt = null) { Templates = templates; TemplateMap = templates.ToDictionary(x => x.Name); _lgOptions = opt; _cachedResult.Clear(); // generate a new customized expression parser by injecting the template as functions ExpressionParser = new ExpressionParser(CustomizedEvaluatorLookup(expressionParser.EvaluatorLookup)); }
public EvaluationOptions(EvaluationOptions opt) { this.StrictMode = opt.StrictMode; this.NullSubstitution = opt.NullSubstitution; this.LineBreakStyle = opt.LineBreakStyle; }
/// <summary> /// Expands a template with given name and scope. /// Return all possible responses instead of random one. /// </summary> /// <param name="templateName">Template name to be evaluated.</param> /// <param name="scope">State visible in the evaluation.</param> /// <param name="opt">EvaluationOptions in expanding a template.</param> /// <returns>Expanded result.</returns> public IList <object> ExpandTemplate(string templateName, object scope = null, EvaluationOptions opt = null) { CheckErrors(); var evalOpt = opt != null?opt.Merge(LgOptions) : LgOptions; var expander = new Expander(this, evalOpt); return(expander.ExpandTemplate(templateName, scope)); }