public void Suggest_NoSuggestionsWithSpecialMarks_SuggestsExactTextEscaped() { RegexAdvisor s = new RegexAdvisor(); List <Suggestion> suggestions = s.Suggest(@"\a"); Assert.AreEqual(new Suggestion(@"^\\a$", @"Exactly '\a'", 900), suggestions[0]); }
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); } }
public void Suggest_NoSuggestions_SuggestsExactText2() { RegexAdvisor s = new RegexAdvisor(); List <Suggestion> suggestions = s.Suggest("b"); Assert.AreEqual(new Suggestion("^b$", "Exactly 'b'", 900), suggestions[0]); }
private static RegexAdvisor GetAdvisor() { RegexAdvisor advisor = new RegexAdvisor(); UIActionSuggestionProvider.TeachRules(advisor); return(advisor); }
public void Suggest_InputTextLegthExceedsMaxSuggestionLength_SuggestsExactTrimmedText2() { RegexAdvisor s = new RegexAdvisor(); s.MaxSuggestionLength = 2; List <Suggestion> suggestions = s.Suggest("abc"); Assert.AreEqual(new Suggestion("^abc$", "Exactly 'ab...'", 900), suggestions[0]); }
public void Suggest_NoSuggestionsImplicitScope_SuggestsExactText() { RegexAdvisor s = new RegexAdvisor(); Scope scope = new Scope("abc"); scope.DefineInnerScope(1, 1); List <Suggestion> suggestions = s.Suggest(scope.InnerRightScope); Assert.AreEqual(new Suggestion("^c$", "Exactly 'c'", 900), suggestions[0]); }
private static void doRunAutoScope(RegexAdvisor advisor, Scope root) { ThreadStart start = delegate { advisor.AutoScope(root); }; Thread runner = new Thread(start); runner.Start(); }
public void Suggest_CombinedScopes_SuggestsExactWhenPossible() { RegexAdvisor s = new RegexAdvisor(); s.Learn(new Suggestion(@"\w", "any letter or num", 100)); Scope scope = new Scope("abc"); scope.DefineInnerScope(1, 1); List <Suggestion> suggestions = s.Suggest(scope); Assert.AreEqual(new Suggestion("^a$^b$^c$", "Combined"), suggestions[0]); }
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); } }
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)); }
private void RefreshResultsOLD(bool makeAutoScopes) { if (DateTime.Now > new DateTime(2006, 12, 11)) { 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 = GetAdvisor(); WaitCallback onThreadFinish = new WaitCallback(OnSuggestThreadFinish); string regex = advisor.Suggest(root)[0].RegexText; regex = optimize(regex); regex = decideIfStartOrEndLine(regex); results.RegexText = regex; results.RefreshResults(); results.ShowScopeTree(root); }
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 void Setup() { auto = new RegexAdvisor(); }
public void Suggest_NoSuggestions_SuggestsExactText2() { RegexAdvisor s = new RegexAdvisor(); List<Suggestion> suggestions = s.Suggest("b"); Assert.AreEqual(new Suggestion("^b$", "Exactly 'b'", 900), suggestions[0]); }
public void Suggest_NoSuggestionsImplicitScope_SuggestsExactText() { RegexAdvisor s = new RegexAdvisor(); Scope scope = new Scope("abc"); scope.DefineInnerScope(1, 1); List<Suggestion> suggestions = s.Suggest(scope.InnerRightScope); Assert.AreEqual(new Suggestion("^c$", "Exactly 'c'", 900), suggestions[0]); }
public void Suggest_NoSuggestionsWithSpecialMarks_SuggestsExactTextEscaped() { RegexAdvisor s = new RegexAdvisor(); List<Suggestion> suggestions = s.Suggest(@"\a"); Assert.AreEqual(new Suggestion(@"^\\a$", @"Exactly '\a'", 900), suggestions[0]); }
public void Suggest_InputTextLegthExceedsMaxSuggestionLength_SuggestsExactTrimmedText2() { RegexAdvisor s = new RegexAdvisor(); s.MaxSuggestionLength = 2; List<Suggestion> suggestions = s.Suggest("abc"); Assert.AreEqual(new Suggestion("^abc$", "Exactly 'ab...'", 900), suggestions[0]); }
public void Create() { RegexAdvisor s = new RegexAdvisor(); Assert.IsNotNull(s); }
public void Suggest_CombinedScopes_SuggestsExactWhenPossible() { RegexAdvisor s = new RegexAdvisor(); s.Learn(new Suggestion(@"\w", "any letter or num", 100)); Scope scope = new Scope("abc"); scope.DefineInnerScope(1, 1); List<Suggestion> suggestions = s.Suggest(scope); Assert.AreEqual(new Suggestion("^a$^b$^c$", "Combined"), suggestions[0]); }
public void Setup() { suggest = new RegexAdvisor(); }
public void Create() { RegexAdvisor s = new RegexAdvisor(); Assert.IsNotNull(s); }
public void Setup() { auto = new RegexAdvisor(); }
public void Setup() { suggest = new RegexAdvisor(); }