private void btnAddRule_Click(object sender, RoutedEventArgs e) { try { string[] filenames; var fileChooser = new OpenFileDialog(); fileChooser.Title = "Add rules"; fileChooser.InitialDirectory = GSApp.settings.RulesDirAbs; fileChooser.Filter = "grammar rule file (*.grxml)|*.grxml|xml file (*.xml)|*.xml"; fileChooser.Multiselect = true; if ((Boolean)fileChooser.ShowDialog(this)) { filenames = fileChooser.FileNames; if (filenames.GetLength(0) == 0) { MessageBox.Show("Error in rule loading. RuleSet unchanged", "Error in rule loading.", MessageBoxButton.OK, MessageBoxImage.Information); } else { foreach (string filename in filenames) { try { var tempRuleObj = GSApp.settings.filer.Open(filename); Ruleset.Add((grammarRule)tempRuleObj[0]); var ruleFileName = MyIOPath.GetRelativePath(filename, GSApp.settings.RulesDirAbs); var ruleNumber = listBoxOfRules.Items.Count + 1; var li = new ListBoxItem(); li.Content = ruleNumber + ". " + ruleFileName; listBoxOfRules.Items.Add(li); Ruleset.ruleFileNames.Add(ruleFileName); } catch { MessageBox.Show("Error in loading rule: " + filename, "Error in rule loading.", MessageBoxButton.OK, MessageBoxImage.Information); } } } } } catch (Exception exc) { ErrorLogger.Catch(exc); } }
private void addRuleButton_Click(object sender, EventArgs e) { string[] filenames; string justFileName; int ruleNumber; OpenFileDialog fileChooser = new OpenFileDialog(); fileChooser.Title = "Add rules"; fileChooser.InitialDirectory = Program.settings.rulesDirectory; fileChooser.Filter = "file (*.xml)|*.xml"; fileChooser.Multiselect = true; DialogResult result = fileChooser.ShowDialog(); if (result == DialogResult.Cancel) { return; } filenames = fileChooser.FileNames; if (filenames.GetLength(0) == 0) { MessageBox.Show("Error in rule loading. RuleSet unchanged", "Error in rule loading.", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { foreach (string filename in filenames) { try { ruleset.Add(grammarRule.openRuleFromXml(filename)); justFileName = Path.GetFileName(filename); ruleNumber = this.checkedListBox1.Items.Count + 1; this.checkedListBox1.Items.Add(ruleNumber.ToString() + ". " + justFileName); ruleset.ruleFileNames.Add(justFileName); } catch { MessageBox.Show("Error in loading rule: " + filename, "Error in rule loading.", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
public static void Run(designGraph seed, grammarRule rule, Relaxation RelaxationTemplate = null) { try { if (RelaxationTemplate == null) { RelaxationTemplate = new Relaxation(0); } var rnd = new Random(); int k = 0; var continueTesting = true; SearchIO.output("begin recognizing rule: " + rule.name + "on graph :" + seed.name, 2); var dummyRS = new ruleSet(); dummyRS.Add(rule); if (SearchIO.GetTerminateRequest(Thread.CurrentThread.ManagedThreadId)) { return; } var options = dummyRS.recognize(seed, false, RelaxationTemplate.copy()); if (SearchIO.GetTerminateRequest(Thread.CurrentThread.ManagedThreadId)) { return; } var numOptions = options.Count; if (numOptions == 0) { if (MessageBox.Show("There were no recognized options. Should the rule be relaxed?", "Test Rule Status", MessageBoxButton.YesNo, MessageBoxImage.Asterisk, MessageBoxResult.No) == MessageBoxResult.Yes) { Run(seed, rule, new Relaxation(RelaxationTemplate.NumberAllowable + 1)); } return; } do { var status = "There "; int choice = -1; switch (numOptions) { case 0: throw new Exception("Should not be able to reach here. (Test Rule Chooser, zero options.)"); case 1: status += "was only one recognized option and it applied as shown.\n"; choice = 0; status += options[choice].Relaxations.RelaxationSummary; break; default: status += "were " + numOptions + " recognized locations.\n"; choice = rnd.Next(options.Count); status += options[choice].Relaxations.RelaxationSummary; option.AssignOptionConfluence(options, new candidate(seed, 0), ConfluenceAnalysis.Full); var numberWithConfluence = options.Count(o => (o.confluence.Count > 0)); var maxConfluence = options.Max(o => o.confluence.Count); var withMaxConfluence = options.Count(o => (o.confluence.Count == maxConfluence)); if (numberWithConfluence > 0) { status += "Confluence existed between " + numberWithConfluence + " of them"; if (maxConfluence > 1) { status += "; \nwith " + withMaxConfluence + " options having a confluence with " + maxConfluence + " other options.\n"; } else { status += ".\n"; } } status += "Option #" + choice + " was randomly chosen, and invoked.\n"; break; } if (!continueTesting) { continue; } if (SearchIO.GetTerminateRequest(Thread.CurrentThread.ManagedThreadId)) { return; } var chosenOption = options[choice]; { var seedCopy = seed.copy(); SearchProcess.transferLmappingToChild(seedCopy, seed, chosenOption); seed = seedCopy; } chosenOption.apply(seed, null); SearchIO.output("Rule sucessfully applied", 4); SearchIO.addAndShowGraphWindow(seed, "After calling " + ++k + " rules"); if (SearchIO.GetTerminateRequest(Thread.CurrentThread.ManagedThreadId)) { return; } options = dummyRS.recognize(seed, true, RelaxationTemplate.copy()); if (SearchIO.GetTerminateRequest(Thread.CurrentThread.ManagedThreadId)) { return; } numOptions = options.Count; switch (numOptions) { case 0: status += "There are no recognized locations on the new graph"; continueTesting = false; MessageBox.Show(status, "Test Rule Status", MessageBoxButton.OK, MessageBoxImage.Asterisk); break; case 1: status += "There is one recognized location on the new graph. Would you like to invoke it?"; continueTesting = (MessageBox.Show(status, "Continue Applying?", MessageBoxButton.YesNo, MessageBoxImage.Asterisk, MessageBoxResult.No) == MessageBoxResult.Yes); break; default: status += "There are " + options.Count + " recognized locations on the new graph. Would you " + "like to randomly invoke one?"; continueTesting = (MessageBox.Show(status, "Continue Applying?", MessageBoxButton.YesNo, MessageBoxImage.Asterisk, MessageBoxResult.No) == MessageBoxResult.Yes); break; } } while (continueTesting); } catch (Exception exc) { ErrorLogger.Catch(exc); } }