public ParseNodeDrawable(ParseNodeDrawable parent, string line, bool isLeaf, int depth)
        {
            var parenthesisCount = 0;
            var childLine        = "";

            this.depth  = depth;
            this.parent = parent;
            children    = new List <ParseNode>();
            if (isLeaf)
            {
                if (!line.Contains("{"))
                {
                    data = new Symbol(line);
                }
                else
                {
                    layers = new LayerInfo(line);
                }
            }
            else
            {
                var startPos = line.IndexOf(" ");

                data = new Symbol(line.Substring(1, startPos - 1));
                if (line.IndexOf(")") == line.LastIndexOf(")"))
                {
                    children.Add(new ParseNodeDrawable(this,
                                                       line.Substring(startPos + 1, line.IndexOf(")") - startPos - 1), true,
                                                       depth + 1));
                }
                else
                {
                    for (var i = startPos + 1; i < line.Length; i++)
                    {
                        if (line[i] != ' ' || parenthesisCount > 0)
                        {
                            childLine = childLine + line[i];
                        }

                        if (line[i] == '(')
                        {
                            parenthesisCount++;
                        }
                        else
                        {
                            if (line[i] == ')')
                            {
                                parenthesisCount--;
                            }
                        }

                        if (parenthesisCount == 0 && childLine != "")
                        {
                            children.Add(new ParseNodeDrawable(this, childLine.Trim(), false, depth + 1));
                            childLine = "";
                        }
                    }
                }
            }
        }
        public int GlossAgreementCount(ParseNodeDrawable parseNode, ViewLayerType viewLayerType)
        {
            if (children.Count == 0)
            {
                if (parseNode.NumberOfChildren() == 0)
                {
                    if (GetLayerData(viewLayerType).Equals(parseNode.GetLayerData(viewLayerType)))
                    {
                        return(1);
                    }

                    return(0);
                }

                return(0);
            }

            var sum = 0;

            for (var i = 0; i < children.Count; i++)
            {
                if (i < parseNode.NumberOfChildren())
                {
                    sum += ((ParseNodeDrawable)GetChild(i)).GlossAgreementCount(
                        (ParseNodeDrawable)parseNode.GetChild(i), viewLayerType);
                }
            }

            return(sum);
        }
        public void CombineWords(ParseNodeDrawable parent, ParseNodeDrawable child)
        {
            while (parent.NumberOfChildren() > 0)
            {
                parent.RemoveChild(parent.FirstChild());
            }

            parent.AddChild(child);
            ((ParseNodeDrawable)root).UpdateDepths(0);
        }
 public ParseNodeDrawable(ParseNodeDrawable parent, ParseNodeDrawable child, string symbol)
 {
     this.children = new List <ParseNode>();
     this.depth    = child.depth;
     child.UpdateDepths(this.depth + 1);
     this.parent = parent;
     this.parent.SetChild(parent.GetChildIndex(child), this);
     this.children.Add(child);
     child.parent = this;
     this.data    = new Symbol(symbol);
 }
        public object Clone()
        {
            var result = new ParseNodeDrawable(data)
            {
                children = new List <ParseNode>()
            };

            if (layers != null)
            {
                result.layers = (LayerInfo)layers.Clone();
            }
            return(result);
        }
        public int StructureAgreementCount(ParseNodeDrawable parseNode)
        {
            if (children.Count > 1)
            {
                var sum = 1;
                for (var i = 0; i < children.Count; i++)
                {
                    if (i < parseNode.NumberOfChildren())
                    {
                        if (!GetChild(i).GetData().GetName()
                            .Equals(parseNode.GetChild(i).GetData().GetName()))
                        {
                            sum = 0;
                            break;
                        }
                    }
                    else
                    {
                        sum = 0;
                        break;
                    }
                }

                for (var i = 0; i < children.Count; i++)
                {
                    if (i < parseNode.NumberOfChildren() && GetChild(i).GetData().GetName()
                        .Equals(parseNode.GetChild(i).GetData().GetName()))
                    {
                        sum += ((ParseNodeDrawable)GetChild(i)).StructureAgreementCount(
                            (ParseNodeDrawable)parseNode.GetChild(i));
                    }
                    else
                    {
                        for (var j = 0; j < parseNode.NumberOfChildren(); j++)
                        {
                            if (GetChild(i).GetData().GetName()
                                .Equals(parseNode.GetChild(j).GetData().GetName()))
                            {
                                sum += ((ParseNodeDrawable)GetChild(i)).StructureAgreementCount(
                                    (ParseNodeDrawable)parseNode.GetChild(j));
                                break;
                            }
                        }
                    }
                }

                return(sum);
            }

            return(0);
        }
        public ParseNodeDrawable PreviousLeafNode(ParseNodeDrawable parseNode)
        {
            var nodeDrawableCollector =
                new NodeDrawableCollector((ParseNodeDrawable)root, new IsTurkishLeafNode());
            var leafList = nodeDrawableCollector.Collect();

            for (var i = 1; i < leafList.Count; i++)
            {
                if (leafList[i].Equals(parseNode))
                {
                    return(leafList[i - 1]);
                }
            }

            return(null);
        }
        public void DivideIntoWords(ParseNodeDrawable parseNode)
        {
            var layers = parseNode.GetLayerInfo().DivideIntoWords();

            parseNode.GetParent().RemoveChild(parseNode);
            foreach (var layerInfo in layers)
            {
                var symbol = new Symbol(layerInfo.GetMorphologicalParseAt(0).GetTreePos());
                var child  = new ParseNodeDrawable(symbol);
                parseNode.GetParent().AddChild(child);
                var grandChild = new ParseNodeDrawable(child, layerInfo.GetLayerDescription(), true,
                                                       parseNode.GetDepth() + 1);
                child.AddChild(grandChild);
                ((ParseNodeDrawable)root).UpdateDepths(0);
            }
        }
        public ParseTreeDrawable(string fileName)
        {
            _name = fileName;
            var streamReader = new StreamReader(fileName);
            var line         = streamReader.ReadLine();

            if (line != null && line.Contains("(") && line.Contains(")"))
            {
                line = line.Substring(line.IndexOf("(") + 1, line.LastIndexOf(")") - line.IndexOf("(") - 1).Trim();
                root = new ParseNodeDrawable(null, line, false, 0);
            }
            else
            {
                root = null;
            }

            streamReader.Close();
        }
        private void ReadFromFile(string currentPath)
        {
            var streamReader = new StreamReader(_fileDescription.GetFileName(currentPath));
            var line         = streamReader.ReadLine();

            if (line.Contains("(") && line.Contains(")"))
            {
                line = line.Substring(line.IndexOf("(") + 1, line.LastIndexOf(")") - line.IndexOf("(") - 1).Trim();
                root = new ParseNodeDrawable(null, line, false, 0);
            }
            else
            {
                Console.WriteLine("File " + _fileDescription.GetFileName(currentPath) +
                                  " is not a valid parse tree file");
                root = null;
            }

            streamReader.Close();
        }
        private void AttachVgToVp(ParseNodeDrawable node)
        {
            var pn = new ParseNodeDrawable(new Symbol(VerbalLabel));

            pn.AddChild((ParseNodeDrawable)node.Clone());
            pn.parent = this;

            var current = node;

            while (current.parent != this)
            {
                current = (ParseNodeDrawable)current.parent;
            }

            var index = this.children.IndexOf(current);

            this.children.Insert(index + 1, pn);
            node.layers.SetLayerData(ViewLayerType.TURKISH_WORD, "*NONE*");
            node.layers.SetLayerData(ViewLayerType.ENGLISH_WORD, "*NONE*");
        }
 public void ReplaceChild(ParseNodeDrawable oldChild, ParseNodeDrawable newChild)
 {
     newChild.UpdateDepths(this.depth + 1);
     newChild.parent = this;
     children[children.IndexOf(oldChild)] = newChild;
 }