public static void TeachRules(RegexAdvisor advisor)
        {
            string currentFile = string.Empty;

            try
            {
                string rootDir = Application.StartupPath;
                string filter = "*.rules";
                string[] files = Directory.GetFiles(rootDir, filter, SearchOption.TopDirectoryOnly);
                foreach (string filename in files)
                {
                    if(filename.ToLower().Contains("auto.rules"))
                    {
                        continue;
                    }
                    string fullPath = Path.Combine(rootDir, filename);
                    currentFile = fullPath;
                    string rules = File.ReadAllText(fullPath);
                    advisor.Learn(rules);
                }
                TeachAutoRules(advisor);
            }
            catch (Exception e)
            {
                MessageBox.Show("Could not read rule file " + currentFile + " !\n" + e.Message);
            }
        }
示例#2
0
 private void initAutoAdvisor()
 {
     if (autoAdvisor == null)
     {
         autoAdvisor = new RegexAdvisor();
         autoAdvisor.autoLineStartEndSymbolOnSuggestions = false;
     }
 }
示例#3
0
        private static void doRunAutoScope(RegexAdvisor advisor, Scope root)
        {
            ThreadStart start = delegate
                                        {
                                            advisor.AutoScope(root);
                                        };

                Thread runner = new Thread(start);
                runner.Start();
        }
 public List<Suggestion> GetSuggestions(Scope target)
 {
     RegexAdvisor advisor = new RegexAdvisor();
     advisor.MaxSuggestionLength = 45;
     TeachRules(advisor);
     string selection;
     if(target!=null)
     {
         selection = target.Text;
     }
     else
     {
         selection = txt.SelectedText;
     }
     return advisor.Suggest(selection);
 }
示例#5
0
 private static RegexAdvisor GetAdvisor()
 {
     RegexAdvisor advisor = new RegexAdvisor();
     UIActionSuggestionProvider.TeachRules(advisor);
     return advisor;
 }
示例#6
0
        private void RefreshResults(bool makeAutoScopes)
        {
            //            if (DateTime.Now > new DateTime(2006, 12, 12))
            //            {
            //                DialogResult result = MessageBox.Show("This limited beta has expired.\n Press OK to go to the product homepage and download a new version.", "Application Expired", MessageBoxButtons.OKCancel);
            //                if (result == DialogResult.OK)
            //                {
            //                    NavURL("http://regulazy.osherove.com");
            //                }
            //                return;
            //            }
            Scope root = txtRegexInput.RootScope;
            RegexAdvisor advisor = new RegexAdvisor();
            UIActionSuggestionProvider.TeachRules(advisor);
            //            if (makeAutoScopes)
            //            {
            ////                ThreadStart start = delegate
            ////                                        {
            //                                            advisor.AutoScope(root);
            ////                                        };
            ////
            ////                Thread runner = new Thread(start);
            ////                runner.Start();
            //            }

            results.ShowInProgress();
            ThreadPool.QueueUserWorkItem(delegate
                                             {
                                                 Application.DoEvents();
                                                 string regex = advisor.Suggest(root)[0].RegexText;
                                                 regex = optimize(regex);
                                                 regex = decideIfStartOrEndLine(regex);
                                                 UIShowResultsAfterSuggest(root, regex);
                                             });
        }
 public List<Suggestion> GetSuggestionsOLD(Scope target)
 {
     RegexAdvisor advisor = new RegexAdvisor();
     advisor.Learn(Resources.RulesFile);
     string selection;
     if(target!=null)
     {
         selection = target.Text;
     }
     else
     {
         selection = txt.SelectedText;
     }
     return advisor.Suggest(selection);
 }
 private static void TeachAutoRules(RegexAdvisor advisor)
 {
     string fullPath = Path.Combine(Application.StartupPath, "auto.rules");
     try
     {
         if(!File.Exists(fullPath))
         {
             return;
         }
         string rules = File.ReadAllText(fullPath);
         advisor.LearnAutomaticRules(rules);
     }
     catch (Exception e)
     {
         MessageBox.Show("Could not read automatic rule file:\n" + fullPath + " !\n" + e.Message);
     }
 }
 private void initAutoAdvisor()
 {
     if(autoAdvisor==null)
     {
         autoAdvisor = new RegexAdvisor();
         autoAdvisor.autoLineStartEndSymbolOnSuggestions = false;
     }
 }