public static Boolean checkRule(grammarRule rule, GraphControl graphControlLHS,
                                        GraphControl graphControlRHS, Label LglobalLabelsText, Label RglobalLabelsText)
        {
            rule.updateFromGraphControl(graphControlLHS);
            rule.updateFromGraphControl(graphControlRHS);
            rule.updateGraphControl(graphControlLHS, graphControlRHS, LglobalLabelsText, RglobalLabelsText);

            if ((rule.L.checkForRepeatNames()) &&
                (DialogResult.Cancel ==
                 (MessageBox.Show("Sorry, but 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", "Repeat Names in L",
                                  MessageBoxButtons.OKCancel, MessageBoxIcon.Information))))
            {
                return(false);
            }
            else
            {
                rule.updateGraphControl(graphControlLHS, graphControlRHS, LglobalLabelsText, RglobalLabelsText);
            }

            if ((rule.R.checkForRepeatNames()) &&
                (DialogResult.Cancel ==
                 (MessageBox.Show("Sorry, but 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", "Repeat Names in R",
                                  MessageBoxButtons.OK, MessageBoxIcon.Information))))
            {
                return(false);
            }
            else
            {
                rule.updateGraphControl(graphControlLHS, graphControlRHS, LglobalLabelsText, RglobalLabelsText);
            }


            if ((rule.numElementsInK == 0) && (DialogResult.No == MessageBox.Show(
                                                   "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",
                                                   MessageBoxButtons.YesNo, MessageBoxIcon.Question)))
            {
                return(false);
            }
            if ((rule.KarcsChangeDirection() != "") && (DialogResult.No ==
                                                        MessageBox.Show("It appears that arc(s): " + rule.KarcsChangeDirection() +
                                                                        " 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?", "Misdirected Arcs in K", MessageBoxButtons.YesNo,
                                                                        MessageBoxIcon.Question)))
            {
                return(false);
            }

            return(true);
        }
Exemple #2
0
        public static grammarRule openRuleFromXml(string filename)
        {
            try
            {
                StreamReader ruleReader = new StreamReader(filename);
                try
                {
                    XmlSerializer ruleDeserializer = new XmlSerializer(typeof(grammarRule));
                    grammarRule   newGrammarRule   = (grammarRule)ruleDeserializer.Deserialize(ruleReader);
                    if (newGrammarRule.L == null)
                    {
                        newGrammarRule.L = new designGraph();
                    }
                    if (newGrammarRule.R == null)
                    {
                        newGrammarRule.R = new designGraph();
                    }
                    newGrammarRule.L.internallyConnectGraph();
                    newGrammarRule.R.internallyConnectGraph();

                    SearchIO.output("Successfully loaded rule: " + Path.GetFileName(filename), 4);

                    if (newGrammarRule.name == null)
                    {
                        newGrammarRule.name =
                            Path.GetFileName(filename).TrimEnd(new char[] { '.', 'x', 'm', 'l' });
                    }
                    newGrammarRule.rulesDir = Path.GetDirectoryName(filename) + "\\";
                    return(newGrammarRule);
                }
                catch (Exception ioe)
                {
                    MessageBox.Show(ioe.Message, "XML Serialization Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }
                finally
                {
                    ruleReader.Close();
                }
            }
            catch (FileNotFoundException fnfe)
            {
                MessageBox.Show(fnfe.Message, "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
        public static void saveRuleToXml(string filename, grammarRule ruleToSave)
        {
            StreamWriter ruleWriter = null;
            try
            {
                ruleWriter = new StreamWriter(filename);
                XmlSerializer ruleSerializer = new XmlSerializer(typeof(grammarRule));
                ruleSerializer.Serialize(ruleWriter, ruleToSave);
            }
            catch (Exception ioe)
            {
                MessageBox.Show(ioe.ToString(), "XML Serialization Error", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            finally
            {
                if (ruleWriter != null) ruleWriter.Close();
            }
        }
        private void initGrammarRuleDisplay(grammarRule initRule, string formTitle)
        {
            InitializeComponent();
            this.MdiParent = Program.main;
            graphControlLHS.LoadLibraries();
            graphControlRHS.LoadLibraries();

            if (initRule == null)
            {
                rule = new grammarRule();
                rule.L = new designGraph();
                rule.R = new designGraph();
            }
            else rule = initRule;
            rule.L.displayGraph(graphControlLHS, this.globalLabelsLText);
            rule.R.displayGraph(graphControlRHS, this.globalLabelsRText);
            if ((formTitle == null) || (formTitle == "")) this.Text = rule.name;
            else this.Text = formTitle;
            this.rule.updateGraphControl(graphControlLHS, graphControlRHS, globalLabelsLText, globalLabelsRText);
        }
 public void showProperties(Netron.GraphLib.UI.GraphControl GC, designGraph graph1, object[] props)
 {
     graphControl = GC;
     graph = graph1;
     rule = null;
     try
     {
         graph.updateFromGraphControl(graphControl);
         if (graph.Bag == null) graph.initPropertiesBag();
         this.graphRuleProps.SelectedObject = graph.Bag;
         this.graphRulePropsTab.Text = "Graph Properties";
     }
     catch (Exception exc)
     {
         MessageBox.Show("The properties of the graph has thrown an exception and cannot be displayed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         SearchIO.output(exc.Message, 2);
     }
     showDisplayProperties(graphControl, (Netron.GraphLib.PropertyBag)props[0]);
     showNodeArcProperties((Netron.GraphLib.PropertyBag)props[0], graph);
 }
        public static Boolean checkRule(grammarRule rule, GraphControl graphControlLHS,
            GraphControl graphControlRHS, Label LglobalLabelsText, Label RglobalLabelsText)
        {
            rule.updateFromGraphControl(graphControlLHS);
            rule.updateFromGraphControl(graphControlRHS);
            rule.updateGraphControl(graphControlLHS, graphControlRHS, LglobalLabelsText, RglobalLabelsText);

            if ((rule.L.checkForRepeatNames()) &&
                (DialogResult.Cancel ==
                (MessageBox.Show("Sorry, but 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", "Repeat Names in L",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Information))))
                return false;
            else
                rule.updateGraphControl(graphControlLHS, graphControlRHS, LglobalLabelsText, RglobalLabelsText);

            if ((rule.R.checkForRepeatNames()) &&
            (DialogResult.Cancel ==
                (MessageBox.Show("Sorry, but 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", "Repeat Names in R",
                    MessageBoxButtons.OK, MessageBoxIcon.Information))))
                return false;
            else
                            rule.updateGraphControl(graphControlLHS, graphControlRHS, LglobalLabelsText, RglobalLabelsText);

            if ((rule.numElementsInK == 0) && (DialogResult.No == MessageBox.Show(
                    "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",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question)))

                return false;
            if ((rule.KarcsChangeDirection() != "") && (DialogResult.No ==
                MessageBox.Show("It appears that arc(s): " + rule.KarcsChangeDirection() +
                    " 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?", "Misdirected Arcs in K", MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question)))
                return false;

            return true;
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="option"/> class.
        /// </summary>
        /// <param name="rule">The rule.</param>
        public option(grammarRule rule)
        {
            var numNodes     = rule.L.nodes.Count;
            var numArcs      = rule.L.arcs.Count;
            var numHyperarcs = rule.L.hyperarcs.Count;

            for (int i = 0; i < numNodes; i++)
            {
                nodes.Add(null);
            }
            for (int i = 0; i < numArcs; i++)
            {
                arcs.Add(null);
            }
            for (int i = 0; i < numHyperarcs; i++)
            {
                hyperarcs.Add(null);
            }
            this.rule         = rule;
            positionTransform = MatrixMath.Identity(3);
        }
Exemple #8
0
        public static void saveRuleToXml(string filename, grammarRule ruleToSave)
        {
            StreamWriter ruleWriter = null;

            try
            {
                ruleWriter = new StreamWriter(filename);
                XmlSerializer ruleSerializer = new XmlSerializer(typeof(grammarRule));
                ruleSerializer.Serialize(ruleWriter, ruleToSave);
            }
            catch (Exception ioe)
            {
                MessageBox.Show(ioe.ToString(), "XML Serialization Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                if (ruleWriter != null)
                {
                    ruleWriter.Close();
                }
            }
        }
        public void showProperties(Netron.GraphLib.UI.GraphControl GC, grammarRule rule1, object[] props)
        {
            graphControl = GC;
            rule = rule1;

            if (graphControl.Name == "graphControlLHS") graph = rule.L;
            else graph = rule.R;

            rule.updateFromGraphControl(graphControl);
            try
            {
                this.graphRulePropsTab.Text = "Rule Properties";
                if (rule.Bag == null) rule.initPropertiesBag();
                this.graphRuleProps.SelectedObject = rule.Bag;
            }
            catch (Exception exc)
            {
                MessageBox.Show("The properties of the rule has thrown an exception and cannot be displayed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SearchIO.output(exc.Message, 2);
            }
            showDisplayProperties(graphControl, (Netron.GraphLib.PropertyBag)props[0]);
            showRuleNodeArcProperties((Netron.GraphLib.PropertyBag)props[0], graph);
        }
Exemple #10
0
 public void Remove(grammarRule removeRule)
 {
     rules.Remove(removeRule);
 }
Exemple #11
0
        /// <summary>
        /// Overrides the object method to check all details of the graphs to see
        /// if they are identical. It is potentially time-consuming as it makes
        /// rules and assigns the graphs as the L of the rule, and then performs
        /// the "recognize" function on the other graph.
        /// </summary>
        /// <param name="obj">The other graph to compare to this one.</param>
        /// <param name="contentsOfGraphAreEqual">if set to <c>true</c> then check that contents of graph are equal even though they occupy different memory.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public bool Equals(object obj, bool contentsOfGraphAreEqual)
        {
            if (Equals(obj))
            {
                return(true);
            }
            if (!contentsOfGraphAreEqual)
            {
                return(false);
            }
            if (!(obj is designGraph))
            {
                return(false);
            }
            var g = (designGraph)obj;

            if (!grammarRule.LabelsMatch(globalLabels, g.globalLabels, null, true))
            {
                return(false);
            }
            if (nodes.Count != g.nodes.Count)
            {
                return(false);
            }
            if (arcs.Count != g.arcs.Count)
            {
                return(false);
            }
            if (hyperarcs.Count != g.hyperarcs.Count)
            {
                return(false);
            }
            if (!DegreeSequence.SequenceEqual(g.DegreeSequence))
            {
                return(false);
            }

            var thisSecondaryDegree = new List <List <int> >();
            var gSecondaryDegree    = new List <List <int> >();

            for (int i = 0; i < nodes.Count; i++)
            {
                var thisDegreelist = new List <int>();
                var gDegreelist    = new List <int>();
                var thisNode       = nodes[i];
                var gNode          = g.nodes[i];
                foreach (var a in thisNode.arcs)
                {
                    if (a is arc)
                    {
                        thisDegreelist.Add(((arc)a).otherNode(thisNode).degree);
                    }
                }
                thisDegreelist.Sort();
                thisSecondaryDegree.Add(thisDegreelist);
                foreach (var a in gNode.arcs)
                {
                    if (a is arc)
                    {
                        gDegreelist.Add(((arc)a).otherNode(gNode).degree);
                    }
                }
                gDegreelist.Sort();
                gSecondaryDegree.Add(gDegreelist);
            }
            foreach (var degreeList in thisSecondaryDegree)
            {
                var i = gSecondaryDegree.FindIndex(v => v.SequenceEqual(degreeList));
                if (i == -1)
                {
                    return(false);
                }
                else
                {
                    gSecondaryDegree.RemoveAt(i);
                }
            }
            if (gSecondaryDegree.Any())
            {
                return(false);
            }
            var maxDegree = DegreeSequence[0];
            var dummyRule = new grammarRule
            {
                spanning = true,
                containsAllGlobalLabels = true,
                induced = true,
                L       = new designGraph()
            };

            #region put g's nodes, arcs and hyperarcs into the LHS of the rule
            foreach (var n in g.nodes)
            {
                var rn = new ruleNode(n)
                {
                    containsAllLocalLabels = true, strictDegreeMatch = true
                };
                if (n.degree == maxDegree)
                {
                    dummyRule.L.nodes.Insert(0, rn);
                }
                else
                {
                    dummyRule.L.nodes.Add(rn);
                }
            }
            foreach (var a in g.arcs)
            {
                var ra = new ruleArc(a)
                {
                    containsAllLocalLabels = true, directionIsEqual = true
                };
                dummyRule.L.arcs.Add(ra);
            }
            foreach (var ha in g.hyperarcs)
            {
                var rha = new ruleHyperarc(ha)
                {
                    containsAllLocalLabels = true, strictNodeCountMatch = true
                };
                dummyRule.L.hyperarcs.Add(rha);
            }
            dummyRule.L.RepairGraphConnections();
            #endregion

            if (dummyRule.recognize(this).Count < 1)
            {
                return(false);
            }

            #region put this's nodes, arcs and hyperarcs into the LHS of the rule
            dummyRule.L = new designGraph();
            foreach (var n in this.nodes)
            {
                var rn = new ruleNode(n)
                {
                    containsAllLocalLabels = true, strictDegreeMatch = true
                };
                if (n.degree == maxDegree)
                {
                    dummyRule.L.nodes.Insert(0, rn);
                }
                else
                {
                    dummyRule.L.nodes.Add(rn);
                }
            }
            foreach (var a in this.arcs)
            {
                var ra = new ruleArc(a)
                {
                    containsAllLocalLabels = true, directionIsEqual = true
                };
                dummyRule.L.arcs.Add(ra);
            }
            foreach (var ha in this.hyperarcs)
            {
                var rha = new ruleHyperarc(ha)
                {
                    containsAllLocalLabels = true, strictNodeCountMatch = true
                };
                dummyRule.L.hyperarcs.Add(rha);
            }
            dummyRule.L.RepairGraphConnections();
            #endregion
            if (dummyRule.recognize(g).Count < 1)
            {
                return(false);
            }
            return(true);
        }
 /// <summary>
 ///   Removes the specified remove rule.
 /// </summary>
 /// <param name = "removeRule">The remove rule.</param>
 public void Remove(grammarRule removeRule)
 {
     rules.Remove(removeRule);
 }
        /* simple functions to add and remove rules from the ruleSet */

        /// <summary>
        ///   Adds the specified new rule.
        /// </summary>
        /// <param name = "newRule">The new rule.</param>
        public void Add(grammarRule newRule)
        {
            rules.Add(newRule);
        }
 public grammarRuleDisplay(grammarRule initRule, string formTitle)
 {
     initGrammarRuleDisplay(initRule, formTitle);
 }
Exemple #15
0
 /* simple functions to add and remove rules from the ruleSet */
 public void Add(grammarRule newRule)
 {
     rules.Add(newRule);
 }
Exemple #16
0
 public void showProperties(Netron.GraphLib.UI.GraphControl GC, grammarRule rule, object sender,
     object[] props)
 {
     if (props.GetLength(0) > 0)
     {
         if ((propWindow == null) || !propWindow.CanSelect)
         {
             propWindow = new PropertiesWindow();
         }
         if (this.ActiveMdiChild.WindowState.Equals(FormWindowState.Maximized))
             propWindow.MdiParent = null;
         propWindow.Show();
         propWindow.Activate();
         propWindow.showProperties(GC, rule, props);
     }
 }
 public grammarRuleDisplay(grammarRule initRule)
 {
     initGrammarRuleDisplay(initRule, initRule.name);
 }