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_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)); }
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 Sugggest_NamedScopeWithInnerNamedScopesAndMultipleSuggestions_ReturnesCombinedInsideGroup() { //More than one alternative for the named Scopes besides the default one suggest.Learn(new Suggestion(@".", "anything")); Scope root = new Scope("abc", "RootName"); Scope inner = root.DefineInnerScope(1, 1); inner.Name = "Inner"; Suggestion suggestion = suggest.Suggest(root)[0]; Assert.AreEqual(@"(?<RootName>^a$(?<Inner>^b$)^c$)", suggestion.RegexText); }