Esempio n. 1
0
        }//loadCodeModules(List<ResourceFile> resourceFiles)

        private void compileRules(string parentId, List <Rule> rules)
        {
            int ruleCount   = rules.Count;
            int ruleCurrent = 0;

            foreach (Rule r in rules)
            {
                try
                {
                    ruleCurrent++;
                    foreach (Input i in r.Inputs)
                    {
                        if (i.Condition != "")
                        {
                            this.csToolbox.AddCondition(i.Id, i.Condition);
                        }
                        InputRecognizer ir = new InputRecognizer(i.Text, r.Id, i.Id, i.Condition, this.synonyms, this.inputReplacements);
                        if (!this.inputs.ContainsKey(parentId))
                        {
                            this.inputs.Add(parentId, new List <InputRecognizer>());
                        }
                        this.inputs[parentId].Add(ir);
                        //Go through virtualparents and add this input recognizer to virtual parent id keys
                        foreach (string virtualParentId in r.VirtualParents)
                        {
                            if (!this.inputs.ContainsKey(virtualParentId))
                            {
                                this.inputs.Add(virtualParentId, new List <InputRecognizer>());
                            }
                            this.inputs[virtualParentId].Add(ir);
                        }
                    }
                    foreach (Output o in r.Outputs)
                    {
                        if (o.Condition != "")
                        {
                            this.csToolbox.AddCondition(o.Id, o.Condition);
                        }
                        if (this.csToolbox.ContainsCSharpTags(o.Text))
                        {
                            this.csToolbox.AddOutput(o.Id, o.Text);
                        }
                        if (this.csToolbox.ContainsCSharpTags(o.Cmd))
                        {
                            this.csToolbox.AddOutput(o.Id + "_cmd", o.Cmd);
                        }
                        if (!this.outputs.ContainsKey(r.Id))
                        {
                            this.outputs.Add(r.Id, new List <Output>());
                        }
                        this.outputs[r.Id].Add(o);
                    }
                }
                catch (Exception e)
                {
                    if (this.OnRuleCompileFailed != null)
                    {
                        this.OnRuleCompileFailed(r.Id, r.Name, e.ToString() + "\r\n" + e.StackTrace);
                    }
                }
                //compile children
                this.compileRules(r.Id, r.Children);
                if (this.OnRuleCompiled != null && parentId == "_root")
                {
                    this.OnRuleCompiled(ruleCurrent, ruleCount);
                }
            }
        }//compileRules(string parentId, List<Rule> rules)
Esempio n. 2
0
 public Match()
 {
     this.InputRecognizer  = null;
     this.ConfidenceFactor = 0.0;
     this.Vars             = null;
 }