/// <summary> /// Saves the rule. /// </summary> /// <param name = "filename">The filename.</param> /// <param name = "ruleToSave">The rule to save.</param> protected void SaveRule(string filename, grammarRule ruleToSave) { StreamWriter ruleWriter = null; try { ruleToSave.name = Path.GetFileNameWithoutExtension(filename); ruleToSave.L.checkForRepeatNames(); removeNullWhiteSpaceEmptyLabels(ruleToSave.L); ruleToSave.R.checkForRepeatNames(); removeNullWhiteSpaceEmptyLabels(ruleToSave.R); ruleToSave.ReorderNodes(); ruleWriter = new StreamWriter(filename); var s = SerializeRuleToXml(ruleToSave); if (s != null) { ruleWriter.Write(s); } } catch (Exception ioe) { SearchIO.output("***XML Serialization Error***"); SearchIO.output(ioe.ToString()); } finally { if (ruleWriter != null) { ruleWriter.Close(); } } }
/// <summary> /// Checks the rule with some issues that may have been overlooked. /// </summary> /// <param name="gR">The grammar rule.</param> /// <returns></returns> public static Boolean checkRule(grammarRule gR) { if ((gR.L.checkForRepeatNames()) && !SearchIO.MessageBoxShow("You are not allowed to have repeat names in L. I have changed these " + "names to be unique, which may have disrupted your context graph, K. Do you want to continue?", "Repeat names in L", "Information", "YesNo", "Yes")) { return(false); } if ((gR.R.checkForRepeatNames()) && !SearchIO.MessageBoxShow("You are not allowed to have repeat names in R. I have changed" + " these names to be unique, which may have disrupted your context graph, K. Do you" + " want to continue?", "Repeat names in R", "Information", "YesNo", "Yes")) { return(false); } if ((NotExistElementsinKR(gR)) && !SearchIO.MessageBoxShow("There appears to be common elements between " + "the left and right hand sides of the rule that are indicated as \"Must NOT Exist\"" + " within the left-hand side. This is not allowed. Continue Anyway?", "Improper use of negative elements", "Error", "YesNo", "No")) { return(false); } if ((NumKElements(gR) == 0) && !SearchIO.MessageBoxShow("There appears to be no common elements between " + "the left and right hand sides of the rule. Is this intentional? If so, click yes to continue.", "No Context Graph", "Information", "YesNo", "Yes")) { return(false); } if ((KarcsChangeDirection(gR) != "") && !SearchIO.MessageBoxShow("It appears that arc(s): " + KarcsChangeDirection(gR) + " change direction (to = from or vice-versa). Even though the arc(s) might be undirected," + " this can still lead to problems in the rule application, it is recommended that this is" + " fixed before saving. Save anyway?", "Change in Arc Direction", "Information", "YesNo", "Yes")) { return(false); } if ((!ValidateFreeArcEmbeddingRules(gR)) && !SearchIO.MessageBoxShow("There appears to be invalid references in the free arc embedding rules." + " Node names used in free arc embedding rules do not exist. Continue Anyway?", "Invalid Free-Arc References", "Error", "YesNo", "No")) { return(false); } gR.ReorderNodes(); return(true); }
private new Boolean checkRule(grammarRule gR) { if (progWindow == null) { return(true); } if ((gR.L.checkForRepeatNames()) && !suppressWarnings && !progWindow.QueryUser("You are not allowed to have repeat names in L. I have changed these " + "names to be unique, which may have disrupted your context graph, K. Do you want to continue" + "saving?", 0, "Yes", "No", false)) { return(false); } if (UserCancelled) { return(false); } progress += 2; if ((gR.R.checkForRepeatNames()) && !suppressWarnings && !progWindow.QueryUser("You are not allowed to have repeat names in R. I have changed" + " these names to be unique, which may have disrupted your context graph, K. Do you" + " want to continue saving?", 0, "Yes", "No", false)) { return(false); } if (UserCancelled) { return(false); } if ((NotExistElementsinKR(gR)) && !suppressWarnings && !progWindow.QueryUser("There appears to be common elements between " + "the left and right hand sides of the rule that are indicated as \"Must NOT Exist\"" + " within the left-hand side. This is not allowed. Continue Anyway?", 0, "Yes", "No", false)) { return(false); } progress += 2; if ((NumKElements(gR) == 0) && !suppressWarnings && !progWindow.QueryUser("No Context Graph: There appears to be no common elements between " + "the left and right hand sides of the rule. Is this intentional? If so, click yes to continue.", 0, "Yes", "No", false)) { return(false); } if (UserCancelled) { return(false); } progress += 2; if ((KarcsChangeDirection(gR) != "") && !suppressWarnings && !progWindow.QueryUser("It appears that arc(s): " + KarcsChangeDirection(gR) + " change direction (to = from or vice-versa). Even though the arc(s) might be undirected," + " this can still lead to problems in the rule application, it is recommended that this is" + " fixed before saving. Save anyway?", 0, "Yes", "No", false)) { return(false); } if (UserCancelled) { return(false); } progress += 2; if ((!ValidateFreeArcEmbeddingRules(gR)) && !suppressWarnings && !progWindow.QueryUser("There appears to be invalid references in the free arc embedding rules." + " Node names used in free arc embedding rules do not exist. Save Anyway?", 0, "Yes", "No", false)) { return(false); } if (UserCancelled) { return(false); } progress += 2; if ((!ValidateFreeArcEmbeddingRules(gR)) && !suppressWarnings && !progWindow.QueryUser("There appears to be invalid references in the free arc embedding rules." + " Node names used in free arc embedding rules do not exist. Save Anyway?", 0, "Yes", "No", false)) { return(false); } if (UserCancelled) { return(false); } progress += 2; gR.ReorderNodes(); return(true); }