public AbstractLattice(XmlNode modelXml)
        {
            if (modelXml != null)
            {
                _root = new AbstractTreeLatticeNode(modelXml.Name,AbstractTreeNodeType.Element);

                XmlNode x = modelXml.SelectSingleNode("text()");
                if (x != null)
                {
                    if (!String.IsNullOrEmpty(x.InnerText))
                    {
                        _root.addValue(x.InnerText);
                    }
                }

                foreach (XmlAttribute at in modelXml.Attributes)//read attributes
                {
                    AbstractTreeLatticeNode attnode = _root.addChild(at.Name, AbstractTreeNodeType.Attribute, -1);
                    attnode.Values.Add(at.Value);
                }

                foreach (XmlNode xn in modelXml.ChildNodes)
                    if (xn.NodeType != XmlNodeType.Text)
                        processXmlNodes(xn);

                prepare();
            }
        }
 public AbstractTreeLatticeNode(String nodeName, AbstractTreeLatticeNode nodeParent, AbstractTreeNodeType type, int ruleInd)
 {
     Name = nodeName;
     parent = nodeParent;
     ruleIndex = ruleInd;
     isMatched = false;
     Type = type;
     _valueType = null;//set it to null till values are added
 }
Beispiel #3
0
        /// <summary>
        /// Check all node types against each other
        /// </summary>
        /// <param name="s">Source Abstract tree lattice node</param>
        /// <param name="t">Target abstract tree lattice node</param>
        /// <returns></returns>
        private double checkTypes(AbstractTreeLatticeNode s, AbstractTreeLatticeNode t)
        {
            if (string.IsNullOrEmpty(s.ValueType) || string.IsNullOrEmpty(t.ValueType))
                return 0;

            if (s.ValueType.Equals(t.ValueType))
                return 1;

            return 0;
        }
Beispiel #4
0
        /// <summary>
        /// Check all node values against each other
        /// </summary>
        /// <param name="s">Source Abstract tree lattice node</param>
        /// <param name="t">Target abstract tree lattice node</param>
        /// <returns></returns>
        private double checkNames(AbstractTreeLatticeNode s, AbstractTreeLatticeNode t)
        {
            int heu = 0;

            if (s.Name.Equals(t.Name))
                heu++;
            //heu = 1;

            if (s.Name.ToLower().Contains(t.Name.ToLower()))
                heu++;
            //heu = 1;

            if (t.Name.ToLower().Contains(s.Name.ToLower()))
                heu++;
            //heu = 1;

            return heu;
        }
        public AbstractLattice(AbstractTreeLatticeNode node)
        {
            if (node != null)
            {

                _root = node.duplicate();
                /*_root = new AbstractTreeLatticeNode(node.Name);

                foreach (string s in node.Values)
                    _root.Values.Add(s);

                foreach (AbstractTreeLatticeNode n in node.Children)
                    _root.Children.Add(n.duplicate());
                */

                prepare();
            }
            else
                MessageBox.Show("Initiation failed, Node is Null");
        }
        private double checkNames(AbstractTreeLatticeNode s, AbstractTreeLatticeNode t)
        {
            //return computeLevenshteinDistance(s.Name.ToLower(), t.Name.ToLower());

            int heu = 0;

            if (s.Name.Equals(t.Name))
                heu++;
            //heu = 1;

            if (s.Name.ToLower().Contains(t.Name.ToLower()))
                heu++;
            //heu = 1;

            if (t.Name.ToLower().Contains(s.Name.ToLower()))
                heu++;
            //heu = 1;

            return heu;
        }
 public AbstractTreeLatticeNode(string nodeName, AbstractTreeLatticeNode nodeParent, AbstractTreeNodeType type)
     : this(nodeName, nodeParent, type, -1)
 {
 }
 internal AbstractTreeLatticeNode find(AbstractTreeLatticeNode toFind)
 {
     if (this.Name.Equals(toFind.Name) && this.Address.Equals(toFind.Address) && this.Type == toFind.Type)
         return this;
     else
         foreach (AbstractTreeLatticeNode c in Children)
         {
             AbstractTreeLatticeNode yes = c.find(toFind);
             if (yes != null)
                 return yes;
         }
     return null;
 }
        /// <summary>
        /// Duplicate node, keep node names and children names, No values, No rule indexes and all isMatched are false
        /// </summary>
        /// <returns></returns>
        public AbstractTreeLatticeNode duplicate()
        {
            AbstractTreeLatticeNode newNode = new AbstractTreeLatticeNode(this.Name, this.Type);

            foreach (string s in this.Values)
                newNode.Values.Add(s);

            foreach (AbstractTreeLatticeNode child in this.Children)
                newNode.Children.Add(child.duplicate());

            return newNode;
        }
        public AbstractTreeLatticeNode addChild(string s, AbstractTreeNodeType t, int rIndex)
        {
            bool check = false;
            foreach (AbstractTreeLatticeNode c in _children)
                if (c.Name.Equals(s) && c.Type == t)
                {
                    check = true;
                    break;
                }

            if (!check)
            {
                AbstractTreeLatticeNode a = new AbstractTreeLatticeNode(s, this, t, rIndex);

                _children.Add(a);
                return a;
            }
            else
                return null;
        }
Beispiel #11
0
        public void processVisual_TreeNodeDrop(TreeNodeViewModel treeN, String FullAddress)
        {
            //set header for template XSLT
            templateVM.HeaderNode = treeN; // I do not think these will be used, they have been used in visualiser to check and set visualfunction abstraction

            //set address Id for template XSLT
            templateVM.TemplateAddress = FullAddress; // I do not think these will be used

            AbstractTreeLatticeNode matchingNode = (ParentWindow as Visualiser).sourceASTL.getAbstractNodeAtAddress(FullAddress);

            //define correspondence
            if (matchingNode != null)//if you have found the node
            {
                if (matchingNode.ruleIndex == -1)
                {
                    sourceLatticeNodeToMatch = matchingNode;
                }
                else if (matchingNode.parent != null)
                {
                    //create a duplicate****************************** duplicate not implemented yet
                    sourceLatticeNodeToMatch = matchingNode.duplicate();
                    matchingNode.parent.Children.Add(sourceLatticeNodeToMatch);
                }

                sourceLatticeNodeToMatch.isMatched = true;
                sourceLatticeNodeToMatch.ruleIndex = RULEINDEX;//assign an index for current rule

                //assign same rule index for this.abstractTree
                this.abstractTree.Root.ruleIndex = sourceLatticeNodeToMatch.ruleIndex;
                this.abstractTree.Root.isMatched = true;

                //increment index for other correspondences
                RULEINDEX++;

                //go for reverse, the top part will be obsolete
                //this.abstractTreeReverse = new AbstractLattice(matchingNode);//might not need abstract tree for reverse, as one way suggestion will eb shown
                this.ReverseData = matchingNode.ToXML();// treeNode.ToXML();//matchingNode might have worked as well but the signature problems might get in the way
                this.templateVMR.TemplateName = this.Data.Name;
            }

            //suggester initiation
            AbstractLattice sourceAST = new AbstractLattice(matchingNode);
            this.abstractTree.prepare();
            SuggesterConfig config = new SuggesterConfig();
            config.UseNameSimSuggester = true;
            config.UseTypeSimSuggester = true;
            config.UseIsoRankSimSuggester = true;
            config.UseValueSimSuggester = true;
            config.UseStructSimSuggester = true;
            (ParentWindow as Visualiser).visualiserSuggester = new Suggester(sourceAST, this.abstractTree, config);

            (ParentWindow as Visualiser).updateSuggestions((ParentWindow as Visualiser).visualiserSuggester.getSuggestionsAsStrings((ParentWindow as Visualiser).visualiserSuggester.imFeelingLucky()));

            //log event
            (ParentWindow as Visualiser).logger.log("\"" + FullAddress + "\" was dropped on \"" + this.VEName + "\"", ReportIcon.OK);
            (ParentWindow as Visualiser).ReportStatusBar.ShowStatus("Mapping " + treeN.Name + " to " + this.Data.Name, ReportIcon.Info);
        }
Beispiel #12
0
        /// <summary>
        /// Check all node values against each other
        /// </summary>
        /// <param name="s">Source Abstract tree lattice node</param>
        /// <param name="t">Target abstract tree lattice node</param>
        /// <returns></returns>
        private double checkValues(AbstractTreeLatticeNode s, AbstractTreeLatticeNode t)
        {
            double heuTotal = 0;
            int count = 0;//for normalisation

            foreach (String sv in s.Values)
                foreach (String tv in t.Values)
                {
                    int heu = 0;
                    if (sv.Equals(tv))
                        heu++;
                    //heu = 1;

                    if (sv.ToLower().Contains(tv.ToLower()))
                        heu++;
                    //heu = 1;

                    if (tv.ToLower().Contains(sv.ToLower()))
                        heu++;
                    //heu = 1;

                    if (heu > 0)
                    {
                        count++;
                        heuTotal += heu; // / 3; //do not do local normalisation
                    }
                }

            if (count > 0)
                return heuTotal / count;//normalise the values
            else
                return 0;
        }
Beispiel #13
0
        public void addConcept(string[] val, int ruleIndex)
        {
            AbstractTreeLatticeNode temp = null;
            AbstractTreeLatticeNode temp2 = null;
            int i = 0;

            temp = searchNodeInTree(val[i]);
            temp2 = temp;
            i++;

            while (i < val.Length & temp != null)//find first node in tree
            {
                temp2 = temp;
                temp = temp.searchNode(val[i]);
                i++;
            }

            if (temp != null)
                temp2 = temp;

            if (temp2 == null) //could not find a match from start
            {
                if (_root != null)
                    MessageBox.Show("Error in assigning rules to root");
                else //first branch to be added
                {
                    if (val[0].StartsWith("@"))//this will not happen
                        _root = new AbstractTreeLatticeNode(val[0].Replace("@",""), AbstractTreeNodeType.Attribute);
                    else
                        _root = new AbstractTreeLatticeNode(val[0], AbstractTreeNodeType.Element);

                    string[] val2 = new string[val.Length - 1];
                    for (int j = 1; j < val.Length; j++)//shift values
                        val2[j - 1] = val[j];

                    _root.addChild(val2, ruleIndex);
                }
            }
            else  //partial matches exist
            {
                if (temp != null) //exact match
                {
                    //temp2.Name = ruleIndex.ToString(); //update rule value of the match
                    //MessageBox.Show("repeated pattern");
                    temp.ruleIndex = ruleIndex;//30/8/2011
                }
                else
                {
                    String[] newVal = new String[val.Length - (i - 1)];
                    for (int k = 0; k < newVal.Length; k++)
                        newVal[k] = val[k + (i - 1)];

                    temp2.addChild(newVal, ruleIndex);

                }
            }
        }
Beispiel #14
0
 public string findRelativeAddress(AbstractTreeLatticeNode top, AbstractTreeLatticeNode low)
 {
     //check for types of low and top
     if (top.findInChildrenByName(low.Name) != null)
     {
         string lowAddress = low.Address;
         string diff = lowAddress.Substring(lowAddress.IndexOf(top.Address) + 1 + top.Address.Length);//diff includes low.Name
         //MessageBox.Show("top:" + top.Address +"\nlow: "+low.Address+ "\nrelative address: "+diff);
         return diff;
     }
     else
     {
         MessageBox.Show("Element: " + low.Name + " is not child of: " + top.Name, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         return null;
     }
 }
Beispiel #15
0
        private void createGraphFromAbstractTreeNode(BidirectionalGraph<AbstractTreeLatticeNode, Edge<AbstractTreeLatticeNode>> g, AbstractTreeLatticeNode n)
        {
            //create the vertex
            g.AddVertex(n);

            //Call for childs
            if (n.Children.Count > 0)
            {
                //create childs and edges
                foreach (AbstractTreeLatticeNode tNode in n.Children)
                {
                    createGraphFromAbstractTreeNode(g, tNode);
                    Edge<AbstractTreeLatticeNode> edge = new Edge<AbstractTreeLatticeNode>(n, tNode);
                    g.AddEdge(edge);
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// Reads XML node and creates a tree lattice based on it.
        /// </summary>
        /// <param name="modelFile"></param>
        public void processXmlData(XmlNode x1)
        {
            //detach x1 from its parent
            XmlNode xnode = x1.Clone();

            _root = new AbstractTreeLatticeNode(xnode.Name,AbstractTreeNodeType.Element);
            //MessageBox.Show(Root.Name);

            XmlNode x = xnode.SelectSingleNode("text()");
            if (x != null)
            {
                if (!String.IsNullOrEmpty(x.InnerText))
                {
                    _root.addValue(x.InnerText);
                }
            }

            foreach (XmlAttribute at in xnode.Attributes)//read attributes
            {
                AbstractTreeLatticeNode attnode = _root.addChild(at.Name, AbstractTreeNodeType.Attribute, -1);
                attnode.Values.Add(at.Value);
            }

            foreach (XmlNode xn in xnode.ChildNodes)
                if (xn.NodeType != XmlNodeType.Text)
                    processXmlNodes(xn);
        }
Beispiel #17
0
        /// <summary>
        /// Reads XML model example file and creates a tree lattice based on it.
        /// </summary>
        /// <param name="modelFile"></param>
        public void processModelFile(String modelFile)
        {
            //Test = new Collection<AbstractTreeLatticeNode>();
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(modelFile);

            _root = new AbstractTreeLatticeNode(xdoc.DocumentElement.Name,AbstractTreeNodeType.Element);
            //MessageBox.Show(Root.Name);

            XmlNode x = xdoc.DocumentElement.SelectSingleNode("text()");
            if (x != null)
            {
                if (!String.IsNullOrEmpty(x.InnerText))
                {
                    _root.addValue(x.InnerText);
                }
            }

            foreach (XmlAttribute at in xdoc.DocumentElement.Attributes)//read attributes
            {
                AbstractTreeLatticeNode attnode = _root.addChild(at.Name, AbstractTreeNodeType.Attribute, -1);
                attnode.Values.Add(at.Value);
            }

            foreach (XmlNode xn in xdoc.DocumentElement.ChildNodes)
                if (xn.NodeType != XmlNodeType.Text)
                    processXmlNodes(xn);

            //MessageBox.Show("lattice should now be complete\n\n"+ Root.printTreeNode());
            //Test.Add(_root);
        }
Beispiel #18
0
 public AbstractLattice()
 {
     _root = null;
 }