예제 #1
0
파일: MutableTree.cs 프로젝트: nunb/code
        public static MutableTree GetParent(MutableTree node, MutableTree root)
        {
            if (root == null || node == null)
            {
                return(null);
            }

            if (root == node)
            {
                return(null);
            }

            if (root.GetChildren().Contains(node))
            {
                return(root);
            }


            foreach (MutableTree child in root.GetChildren())
            {
                MutableTree found = GetParent(node, child);
                if (found != null)
                {
                    return(found);
                }
            }

            return(null);
        }
예제 #2
0
        public static MutableTree GetParent(MutableTree node, MutableTree root)
        {
            if (root == null || node == null)
                return null;

            if (root == node)
                return null;

            if (root.GetChildren().Contains(node))
                return root;

            foreach (MutableTree child in root.GetChildren())
            {
                MutableTree found = GetParent(node, child);
                if (found != null)
                    return found;
            }

            return null;
        }
예제 #3
0
파일: Tree.cs 프로젝트: nunb/code
        public static Tree FromMutable(MutableTree mutable)
        {
            Tree node = Tree.FromBoundingBox(mutable, mutable.Tags);

            foreach (MutableTree child in mutable.GetChildren())
            {
                node._children.Add(FromMutable(child));
            }

            return(node);
        }
예제 #4
0
파일: MutableTree.cs 프로젝트: nunb/code
        public static IEnumerable <MutableTree> GetSiblings(MutableTree node, MutableTree root)
        {
            MutableTree        parent   = GetParent(node, root);
            List <MutableTree> siblings = new List <MutableTree>();

            if (parent != null)
            {
                foreach (MutableTree child in parent.GetChildren())
                {
                    if (child != node)
                    {
                        siblings.Add(node);
                    }
                }
            }

            return(siblings);
        }
예제 #5
0
파일: Tree.cs 프로젝트: nunb/interpretation
        public static Tree FromMutable(MutableTree mutable)
        {
            Tree node = Tree.FromBoundingBox(mutable, mutable.Tags);

            foreach (MutableTree child in mutable.GetChildren())
            {
                node._children.Add(FromMutable(child));
            }

            return node;
        }
예제 #6
0
        private static int GetNodeIndex(MutableTree node, MutableTree parent)
        {
            int index = 0;

            string pixelhash = null;
            string type = "none";
            if (node.ContainsAttribute("type"))
                type = node["type"].ToString();

            if (node.ContainsAttribute("type") && node["type"].Equals("content"))
                pixelhash = node["pixel_hash"].ToString();

            if (parent != null)
            {
                var children = parent.GetChildren();
                children.Sort(BoundingBox.CompareByTopThenLeft);
                foreach (MutableTree sibling in children)
                {
                    if (sibling == node)
                        return index;
                    else
                    {
                        string sibtype = "none";
                        if (sibling.ContainsAttribute("type"))
                            sibtype = sibling["type"].ToString();

                        if (sibtype.Equals("ptype") && type.Equals("ptype"))
                        {
                            if (sibling["ptype_id"].Equals(node["ptype_id"]))
                                index++;
                        }
                        else if (sibtype.Equals(type))
                        {
                            index++;
                        }
                    }
                }
            }

            return index;
        }