Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.core.syntaxgraph.edge.Edge moveDependencyEdge(org.maltparser.core.syntaxgraph.node.DependencyNode newHead, org.maltparser.core.syntaxgraph.node.DependencyNode dependent) throws org.maltparser.core.exception.MaltChainedException
        public virtual Edge.Edge moveDependencyEdge(DependencyNode newHead, DependencyNode dependent)
        {
            if (dependent == null || !dependent.hasHead() || newHead.BelongsToGraph != this || dependent.BelongsToGraph != this)
            {
                return(null);
            }
            Edge.Edge headEdge = dependent.HeadEdge;

            LabelSet labels = null;

            if (headEdge.Labeled)
            {
                labels = CheckOutNewLabelSet();
                foreach (SymbolTable table in headEdge.LabelTypes)
                {
                    labels.put(table, headEdge.getLabelCode(table));
                }
            }
            headEdge.clear();
            headEdge.BelongsToGraph = this;
            headEdge.setEdge((Node.Node)newHead, (Node.Node)dependent, Edge_Fields.DEPENDENCY_EDGE);
            if (labels != null)
            {
                headEdge.addLabel(labels);
                labels.clear();
                CheckInLabelSet(labels);
            }
            return(headEdge);
        }
Пример #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void update(org.maltparser.core.syntaxgraph.MappablePhraseStructureGraph graph, org.maltparser.core.syntaxgraph.edge.Edge e, Object arg) throws org.maltparser.core.exception.MaltChainedException
        public virtual void update(MappablePhraseStructureGraph graph, Edge.Edge e, object arg)
        {
            if (lockUpdate == false)
            {
                //			if (e.getType() == Edge.PHRASE_STRUCTURE_EDGE && e.getSource() instanceof NonTerminalNode && lockUpdate == false) {
                //				if(e.getTarget() instanceof TerminalNode) {
                //					PhraseStructureNode top = (PhraseStructureNode)e.getTarget();
                //					while (top.getParent() != null && ((NonTerminalNode)top.getParent()).getLexicalHead() == (PhraseStructureNode)e.getTarget()) {
                //						top = top.getParent();
                //					}
                //					updateDependenyGraph(graph, top);
                //				}
                //				else if (e.getSource().isRoot()) {
                //					updateDependenyGraph(graph, graph.getPhraseStructureRoot());
                //				}
                //			}
                if (e.Type == Edge_Fields.DEPENDENCY_EDGE && e.Source is DependencyNode && e.Target is DependencyNode)
                {
                    if (e.Labeled && e.LabelSet.size() == 4)
                    {
                        updatePhraseStructureGraph(graph, (Edge.Edge)e, false);
                    }
                }
            }
        }
Пример #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.core.syntaxgraph.edge.Edge addPhraseStructureEdge(org.maltparser.core.syntaxgraph.node.PhraseStructureNode parent, org.maltparser.core.syntaxgraph.node.PhraseStructureNode child) throws org.maltparser.core.exception.MaltChainedException
        public virtual Edge.Edge addPhraseStructureEdge(PhraseStructureNode parent, PhraseStructureNode child)
        {
            if (parent == null || child == null)
            {
                throw new MaltChainedException("Parent or child node is missing in sentence " + SentenceID);
            }
            else if (parent.BelongsToGraph != this || child.BelongsToGraph != this)
            {
                throw new MaltChainedException("Parent or child node is not a member of the graph in sentence " + SentenceID);
            }
            else if (parent == child)
            {
                throw new MaltChainedException("It is not allowed to add a phrase structure edge connecting the same node in sentence " + SentenceID);
            }
            else if (parent is NonTerminalNode && !child.Root)
            {
                Edge.Edge e = edgePool.checkOut();
                e.BelongsToGraph = this;
                e.setEdge((Node.Node)parent, (Node.Node)child, Edge_Fields.PHRASE_STRUCTURE_EDGE);
                graphEdges.Add(e);
                return(e);
            }
            else
            {
                throw new MaltChainedException("Parent or child node is not of correct node type.");
            }
        }
Пример #4
0
        public virtual string toStringNonTerminalNode(NonTerminalNode node)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final StringBuilder sb = new StringBuilder();
            StringBuilder sb = new StringBuilder();

            sb.Append(node.ToString().Trim());
            sb.Append('\n');
            IEnumerator <Edge.Edge> ie = ((Node.Node)node).OutgoingEdgeIterator;

            while (ie.MoveNext())
            {
                Edge.Edge e = ie.Current;
                if (e.Target is TokenNode)
                {
                    sb.Append("   T");
                    sb.Append(e.Target.Index);
                }
                if (e.Target is NonTerminalNode)
                {
                    sb.Append("   N");
                    sb.Append(e.Target.Index);
                }
                sb.Append('\t');
                sb.Append(e.ToString());
                sb.Append('\n');
            }
            return(sb.ToString());
        }
Пример #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void copyPartialDependencyStructure(DependencyStructure sourceGraph, DependencyStructure targetGraph) throws org.maltparser.core.exception.MaltChainedException
        public virtual void copyPartialDependencyStructure(IDependencyStructure sourceGraph, IDependencyStructure targetGraph)
        {
            SymbolTable partHead   = cachedSource.SymbolTables.getSymbolTable("PARTHEAD");
            SymbolTable partDeprel = cachedSource.SymbolTables.getSymbolTable("PARTDEPREL");

            if (partHead == null || partDeprel == null)
            {
                return;
            }
            SymbolTable deprel = cachedTarget.SymbolTables.getSymbolTable("DEPREL");

            foreach (int index in sourceGraph.TokenIndices)
            {
                DependencyNode snode = sourceGraph.GetTokenNode(index);
                DependencyNode tnode = targetGraph.GetTokenNode(index);
                if (snode != null && tnode != null)
                {
                    int    spartheadindex = int.Parse(snode.getLabelSymbol(partHead));
                    string spartdeprel    = snode.getLabelSymbol(partDeprel);
                    if (spartheadindex > 0)
                    {
                        Edge.Edge tedge = targetGraph.AddDependencyEdge(spartheadindex, snode.Index);
                        tedge.addLabel(deprel, spartdeprel);
                    }
                }
            }
        }
Пример #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void removeDependencyEdge(org.maltparser.core.syntaxgraph.node.Node head, org.maltparser.core.syntaxgraph.node.Node dependent) throws org.maltparser.core.exception.MaltChainedException
        protected internal virtual void removeDependencyEdge(Node.Node head, Node.Node dependent)
        {
            if (head == null || dependent == null)
            {
                throw new SyntaxGraphException("Head or dependent node is missing.");
            }
            else if (!dependent.Root)
            {
                IEnumerator <Edge.Edge> ie = dependent.IncomingEdgeIterator;

                while (ie.MoveNext())
                {
                    Edge.Edge e = ie.Current;
                    if (e.Source == head)
                    {
                        graphEdges.remove(e);
//JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only:
                        ie.remove();
                        edgePool.checkIn(e);
                    }
                }
            }
            else
            {
                throw new SyntaxGraphException("Head node is not a root node or a terminal node.");
            }
        }
Пример #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected org.maltparser.core.syntaxgraph.edge.Edge addDependencyEdge(org.maltparser.core.syntaxgraph.node.DependencyNode head, org.maltparser.core.syntaxgraph.node.DependencyNode dependent) throws org.maltparser.core.exception.MaltChainedException
        protected internal virtual Edge.Edge addDependencyEdge(DependencyNode head, DependencyNode dependent)
        {
            if (head == null || dependent == null)
            {
                throw new SyntaxGraphException("Head or dependent node is missing.");
            }
            else if (!dependent.Root)
            {
                if (singleHeadedConstraint && dependent.hasHead())
                {
                    return(moveDependencyEdge(head, dependent));
                }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.DependencyNode hc = ((org.maltparser.core.syntaxgraph.node.DependencyNode)head).findComponent();
                DependencyNode hc = ((DependencyNode)head).findComponent();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.DependencyNode dc = ((org.maltparser.core.syntaxgraph.node.DependencyNode)dependent).findComponent();
                DependencyNode dc = ((DependencyNode)dependent).findComponent();
                if (hc != dc)
                {
                    link(hc, dc);
                    numberOfComponents--;
                }
                Edge.Edge e = edgePool.checkOut();
                e.BelongsToGraph = this;
                e.setEdge((Node.Node)head, (Node.Node)dependent, Edge_Fields.DEPENDENCY_EDGE);
                graphEdges.Add(e);
                return(e);
            }
            else
            {
                throw new SyntaxGraphException("Head node is not a root node or a terminal node.");
            }
        }
Пример #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void addOutgoingEdge(org.maltparser.core.syntaxgraph.edge.Edge out) throws org.maltparser.core.exception.MaltChainedException
        public override void addOutgoingEdge(Edge.Edge @out)
        {
            base.addOutgoingEdge(@out);
            if (@out.Type == Edge_Fields.PHRASE_STRUCTURE_EDGE && @out.Target is PhraseStructureNode)
            {
                children.Add((PhraseStructureNode)@out.Target);
                //			boolean notSorted = true;
                //			PhraseStructureNode prev = children.first();
                //			for (PhraseStructureNode node : children) {
                //				if (prev != node) {
                //					if (node.compareTo(prev) == -1) {
                //						notSorted = false;
                //						System.out.println("NS");
                //						break;
                //					}
                //				}
                //				prev = node;
                //			}
                //			if (notSorted == false) {
                //				SortedSet<PhraseStructureNode> tmp = new TreeSet<PhraseStructureNode>(children);
                //				children.clear();
                //				for (PhraseStructureNode node : tmp) {
                //					children.add(node);
                //				}
                //			}
            }
        }
Пример #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.core.syntaxgraph.edge.Edge addDependencyEdge(org.maltparser.core.syntaxgraph.node.DependencyNode head, org.maltparser.core.syntaxgraph.node.DependencyNode dependent) throws org.maltparser.core.exception.MaltChainedException
        public virtual Edge.Edge addDependencyEdge(DependencyNode head, DependencyNode dependent)
        {
            if (head == null || dependent == null || head.BelongsToGraph != this || dependent.BelongsToGraph != this)
            {
                throw new SyntaxGraphException("Head or dependent node is missing.");
            }
            else if (!dependent.Root)
            {
                if (singleHeadedConstraint && dependent.hasHead())
                {
                    throw new SyntaxGraphException("The dependent already have a head. ");
                }
                DependencyNode hc = ((DependencyNode)head).findComponent();
                DependencyNode dc = ((DependencyNode)dependent).findComponent();
                if (hc != dc)
                {
                    link(hc, dc);
                    numberOfComponents--;
                }
                Edge.Edge e = edgePool.checkOut();
                e.BelongsToGraph = this;
                e.setEdge((Node.Node)head, (Node.Node)dependent, Edge_Fields.DEPENDENCY_EDGE);
                graphEdges.Add(e);
                return(e);
            }
            else
            {
                throw new SyntaxGraphException("Head node is not a root node or a terminal node.");
            }
        }
Пример #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void removeOutgoingEdge(org.maltparser.core.syntaxgraph.edge.Edge out) throws org.maltparser.core.exception.MaltChainedException
        public virtual void removeOutgoingEdge(Edge.Edge @out)
        {
            if (@out.Source != this)
            {
                throw new SyntaxGraphException("The outgoing edge's 'from' reference is not correct");
            }
            outgoingEdges.remove(@out);
        }
Пример #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void removeIncomingEdge(org.maltparser.core.syntaxgraph.edge.Edge in) throws org.maltparser.core.exception.MaltChainedException
        public virtual void removeIncomingEdge(Edge.Edge @in)
        {
            if (@in.Target != this)
            {
                throw new SyntaxGraphException("The incoming edge's 'to' reference is not correct");
            }
            incomingEdges.remove(@in);
        }
Пример #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void removeOutgoingEdge(org.maltparser.core.syntaxgraph.edge.Edge out) throws org.maltparser.core.exception.MaltChainedException
        public override void removeOutgoingEdge(Edge.Edge @out)
        {
            base.removeOutgoingEdge(@out);
            if (@out.Type == Edge_Fields.PHRASE_STRUCTURE_EDGE && @out.Target is PhraseStructureNode)
            {
                children.remove(@out.Target);
            }
        }
Пример #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void addIncomingEdge(org.maltparser.core.syntaxgraph.edge.Edge in) throws org.maltparser.core.exception.MaltChainedException
        public override void addIncomingEdge(Edge.Edge @in)
        {
            base.addIncomingEdge(@in);
            if (@in.Type == Edge_Fields.PHRASE_STRUCTURE_EDGE && @in.Source is PhraseStructureNode)
            {
                parent = (PhraseStructureNode)@in.Source;
            }
        }
Пример #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void removeIncomingEdge(org.maltparser.core.syntaxgraph.edge.Edge in) throws org.maltparser.core.exception.MaltChainedException
        public override void removeIncomingEdge(Edge.Edge @in)
        {
            base.removeIncomingEdge(@in);
            if (@in.Type == Edge_Fields.PHRASE_STRUCTURE_EDGE && @in.Source is PhraseStructureNode)
            {
                if (@in.Source == parent)
                {
                    parent = null;
                }
            }
        }
Пример #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void linkAllTreesToRoot() throws org.maltparser.core.exception.MaltChainedException
        public virtual void LinkAllTreesToRoot()
        {
            foreach (int i in terminalNodes.Keys)
            {
                if (!terminalNodes[i].hasHead())
                {
                    Edge.Edge e = addDependencyEdge(root, terminalNodes[i]);
                    mapping.updatePhraseStructureGraph(this, e, false);
                }
            }
        }
Пример #16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.core.syntaxgraph.edge.Edge addSecondaryEdge(org.maltparser.core.syntaxgraph.node.ComparableNode source, org.maltparser.core.syntaxgraph.node.ComparableNode target) throws org.maltparser.core.exception.MaltChainedException
        public virtual Edge.Edge addSecondaryEdge(ComparableNode source, ComparableNode target)
        {
            if (source == null || target == null)
            {
                throw new SyntaxGraphException("Head or dependent node is missing.");
            }
            else if (!target.Root)
            {
                Edge.Edge e = edgePool.checkOut();
                e.BelongsToGraph = this;
                e.setEdge((Node.Node)source, (Node.Node)target, Edge_Fields.SECONDARY_EDGE);
                graphEdges.Add(e);
                return(e);
            }
            return(null);
        }
Пример #17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void updateDependenyGraph(org.maltparser.core.syntaxgraph.MappablePhraseStructureGraph graph, org.maltparser.core.syntaxgraph.node.PhraseStructureNode top) throws org.maltparser.core.exception.MaltChainedException
        public virtual void updateDependenyGraph(MappablePhraseStructureGraph graph, PhraseStructureNode top)
        {
            if (graph.NTokenNode() == 1 && graph.nNonTerminals() == 0)
            {
                // Special case when the root dominates direct a single terminal node
                Edge.Edge e = graph.addDependencyEdge(graph.DependencyRoot, graph.GetDependencyNode(1));
                e.addLabel(graph.SymbolTables.getSymbolTable(DEPREL), graph.GetDefaultRootEdgeLabelSymbol(graph.SymbolTables.getSymbolTable(DEPREL)));
                e.addLabel(graph.SymbolTables.getSymbolTable(HEADREL), graph.GetDefaultRootEdgeLabelSymbol(graph.SymbolTables.getSymbolTable(HEADREL)));
                e.addLabel(graph.SymbolTables.getSymbolTable(PHRASE), "*");
                //			e.addLabel(graph.getSymbolTables().getSymbolTable(PHRASE), graph.getDefaultRootEdgeLabelSymbol(graph.getSymbolTables().getSymbolTable(PHRASE)));
                e.addLabel(graph.SymbolTables.getSymbolTable(ATTACH), graph.GetDefaultRootEdgeLabelSymbol(graph.SymbolTables.getSymbolTable(ATTACH)));
            }
            else
            {
                updateDependencyEdges(graph, top);
                updateDependenyLabels(graph);
            }
        }
Пример #18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.core.syntaxgraph.edge.Edge addPhraseStructureEdge(org.maltparser.core.syntaxgraph.node.PhraseStructureNode parent, org.maltparser.core.syntaxgraph.node.PhraseStructureNode child) throws org.maltparser.core.exception.MaltChainedException
        public virtual Edge.Edge addPhraseStructureEdge(PhraseStructureNode parent, PhraseStructureNode child)
        {
            if (parent == null || child == null)
            {
                throw new MaltChainedException("Parent or child node is missing.");
            }
            else if (parent is NonTerminalNode && !child.Root)
            {
                Edge.Edge e = edgePool.checkOut();
                e.BelongsToGraph = this;
                e.setEdge((Node.Node)parent, (Node.Node)child, Edge_Fields.PHRASE_STRUCTURE_EDGE);
                graphEdges.Add(e);
                return(e);
            }
            else
            {
                throw new MaltChainedException("Parent or child node is not of correct node type.");
            }
        }
Пример #19
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void removeSecondaryEdge(org.maltparser.core.syntaxgraph.node.ComparableNode source, org.maltparser.core.syntaxgraph.node.ComparableNode target) throws org.maltparser.core.exception.MaltChainedException
        public virtual void removeSecondaryEdge(ComparableNode source, ComparableNode target)
        {
            if (source == null || target == null || source.BelongsToGraph != this || target.BelongsToGraph != this)
            {
                throw new SyntaxGraphException("Head or dependent node is missing.");
            }
            else if (!target.Root)
            {
                IEnumerator <Edge.Edge> ie = ((Node.Node)target).IncomingEdgeIterator;
                while (ie.MoveNext())
                {
                    Edge.Edge e = ie.Current;
                    if (e.Source == source)
                    {
//JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only:
                        ie.remove();
                        graphEdges.remove(e);
                        edgePool.checkIn(e);
                    }
                }
            }
        }
Пример #20
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected org.maltparser.core.syntaxgraph.edge.Edge moveDependencyEdge(org.maltparser.core.syntaxgraph.node.DependencyNode newHead, org.maltparser.core.syntaxgraph.node.DependencyNode dependent) throws org.maltparser.core.exception.MaltChainedException
        protected internal virtual Edge.Edge moveDependencyEdge(DependencyNode newHead, DependencyNode dependent)
        {
            if (dependent == null || !dependent.hasHead())
            {
                return(null);
            }
            Edge.Edge headEdge = dependent.HeadEdge;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LabelSet labels = checkOutNewLabelSet();
            LabelSet labels = CheckOutNewLabelSet();

            foreach (SymbolTable table in headEdge.LabelTypes)
            {
                labels.put(table, headEdge.getLabelCode(table));
            }
            headEdge.clear();
            headEdge.BelongsToGraph = this;
            headEdge.setEdge((Node.Node)newHead, (Node.Node)dependent, Edge_Fields.DEPENDENCY_EDGE);
            headEdge.addLabel(labels);
            labels.clear();
            CheckInLabelSet(labels);
            return(headEdge);
        }
Пример #21
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void removeOutgoingEdge(org.maltparser.core.syntaxgraph.edge.Edge out) throws org.maltparser.core.exception.MaltChainedException
        public override void removeOutgoingEdge(Edge.Edge @out)
        {
            base.removeOutgoingEdge(@out);
            if (@out.Target != null)
            {
                if (@out.Type == Edge_Fields.DEPENDENCY_EDGE && @out.Target is DependencyNode)
                {
                    Node dependent = @out.Target;
                    if (compareTo(dependent) > 0)
                    {
                        leftDependents.remove((DependencyNode)dependent);
                    }
                    else if (compareTo(dependent) < 0)
                    {
                        rightDependents.remove((DependencyNode)dependent);
                    }
                }
                else if (@out.Type == Edge_Fields.PHRASE_STRUCTURE_EDGE && @out.Target is PhraseStructureNode)
                {
                    children.remove((PhraseStructureNode)@out.Target);
                }
            }
        }
Пример #22
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void removeSecondaryEdge(org.maltparser.core.syntaxgraph.node.ComparableNode source, org.maltparser.core.syntaxgraph.node.ComparableNode target) throws org.maltparser.core.exception.MaltChainedException
        public virtual void removeSecondaryEdge(ComparableNode source, ComparableNode target)
        {
            if (source == null || target == null)
            {
                throw new SyntaxGraphException("Head or dependent node is missing.");
            }
            else if (!target.Root)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Iterator<org.maltparser.core.syntaxgraph.edge.Edge> ie = ((org.maltparser.core.syntaxgraph.node.Node)target).getIncomingEdgeIterator();
                IEnumerator <Edge.Edge> ie = ((Node.Node)target).IncomingEdgeIterator;
                while (ie.MoveNext())
                {
                    Edge.Edge e = ie.Current;
                    if (e.Source == source)
                    {
//JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only:
                        ie.remove();
                        graphEdges.remove(e);
                        edgePool.checkIn(e);
                    }
                }
            }
        }
Пример #23
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean readSentence(org.maltparser.core.syntaxgraph.TokenStructure syntaxGraph) throws org.maltparser.core.exception.MaltChainedException
        public virtual bool readSentence(ITokenStructure syntaxGraph)
        {
            if (syntaxGraph == null || !(syntaxGraph is PhraseStructure))
            {
                return(false);
            }
            syntaxGraph.Clear();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.PhraseStructure phraseStructure = (org.maltparser.core.syntaxgraph.PhraseStructure)syntaxGraph;
            PhraseStructure     phraseStructure = (PhraseStructure)syntaxGraph;
            PhraseStructureNode parent          = null;
            PhraseStructureNode child           = null;

            //		if (header == null) {
            //			header = new TigerXMLHeader(syntaxGraph.getSymbolTables());
            //		}

            try
            {
                while (true)
                {
                    int @event = reader.next();
                    if (@event == XMLStreamConstants.START_ELEMENT)
                    {
                        if (reader.LocalName.length() == 0)
                        {
                            continue;
                        }
                        if (reader.LocalName.charAt(0) == 'e')
                        {
                            // e -> edge, edgelabel
                            if (reader.LocalName.length() == 4)
                            {                             //edge
                                int childid  = -1;
                                int indexSep = reader.getAttributeValue(null, "idref").IndexOf('_');

                                try
                                {
                                    if (indexSep != -1)
                                    {
                                        childid = int.Parse(reader.getAttributeValue(null, "idref").substring(indexSep + 1));
                                    }
                                    else
                                    {
                                        childid = int.Parse(reader.getAttributeValue(null, "idref"));
                                    }
                                    if (childid == -1)
                                    {
                                        throw new SyntaxGraphException("The tiger reader couldn't recognize the idref attribute '" + reader.getAttributeValue(null, "idref") + "' of the edge element. ");
                                    }
                                }
                                catch (System.FormatException)
                                {
                                    throw new SyntaxGraphException("The tiger reader couldn't recognize the idref attribute '" + reader.getAttributeValue(null, "idref") + "' of the edge element. ");
                                }

                                if (childid < START_ID_OF_NONTERMINALS)
                                {
                                    child = phraseStructure.GetTokenNode(childid);
                                }
                                else
                                {
                                    child = phraseStructure.getNonTerminalNode(childid - START_ID_OF_NONTERMINALS + 1);
                                }

                                Edge.Edge e = phraseStructure.addPhraseStructureEdge(parent, child);
                                SortedDictionary <string, SymbolTable> inputTables = dataFormatInstance.getPhraseStructureEdgeLabelSymbolTables(phraseStructure.SymbolTables);
                                foreach (string name in inputTables.Keys)
                                {
                                    e.addLabel(inputTables[name], reader.getAttributeValue(null, name.ToLower()));
                                }
                            }
                            else if (reader.LocalName.Equals("edgelabel"))
                            {                             // edgelabel
                                //							domain = Domain.EL;
                            }
                        }
                        else if (reader.LocalName.charAt(0) == 'n')
                        {
                            // n -> nt, nonterminals, name
                            if (reader.LocalName.length() == 2)
                            {                             // nt
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String id = reader.getAttributeValue(null, "id");
                                string id = reader.getAttributeValue(null, "id");
                                if (graphRootID.Length == id.Length && graphRootID.ToString().Equals(id))
                                {
                                    parent = phraseStructure.PhraseStructureRoot;
                                }
                                else
                                {
                                    int index = id.IndexOf('_');
                                    if (index != -1)
                                    {
                                        parent = phraseStructure.addNonTerminalNode(int.Parse(id.Substring(index + 1)) - START_ID_OF_NONTERMINALS + 1);
                                    }
                                }
                                SortedDictionary <string, SymbolTable> inputTables = dataFormatInstance.getPhraseStructureNodeLabelSymbolTables(phraseStructure.SymbolTables);
                                foreach (string name in inputTables.Keys)
                                {
                                    parent.addLabel(inputTables[name], reader.getAttributeValue(null, name.ToLower()));
                                }
                            }
                            else if (reader.LocalName.Equals("name"))
                            {                             // name
                                //							elementContent.setLength(0);
                                //							collectChar = true;
                            }
                        }
                        else if (reader.LocalName.charAt(0) == 't')
                        {
                            // t -> t, terminals
                            if (reader.LocalName.length() == 1)
                            {                             // t
                                SortedDictionary <string, SymbolTable> inputTables = dataFormatInstance.getInputSymbolTables(phraseStructure.SymbolTables);
                                child = syntaxGraph.AddTokenNode();
                                foreach (string name in inputTables.Keys)
                                {
                                    child.addLabel(inputTables[name], reader.getAttributeValue(null, name.ToLower()));
                                }
                            }
                        }
                        else if (reader.LocalName.charAt(0) == 's')
                        {
                            // s -> subcorpus, secedge, s, secedgelabel
                            if (reader.LocalName.length() == 1)
                            {                             // s
                                string id        = reader.getAttributeValue(null, "id");
                                bool   indexable = false;
                                int    index     = -1;
                                if (!ReferenceEquals(id, null) && id.Length > 0)
                                {
                                    for (int i = 0, n = id.Length; i < n; i++)
                                    {
                                        if (char.IsDigit(id[i]))
                                        {
                                            if (index == -1)
                                            {
                                                index = i;
                                            }
                                            indexable = true;
                                        }
                                    }
                                }
                                if (indexable)
                                {
                                    phraseStructure.SentenceID = int.Parse(id.Substring(index));
                                }
                                else
                                {
                                    phraseStructure.SentenceID = sentenceCount + 1;
                                }
                            }
                        }
                        else if (reader.LocalName.charAt(0) == 'v')
                        {
                            // v -> variable, value
                            //						if (reader.getLocalName().equals("value")) {
                            //							valueName.setLength(0);
                            //							valueName.append(reader.getAttributeValue(null, "name"));
                            //							elementContent.setLength(0);
                            //							collectChar = true;
                            //						}
                        }
                        else
                        {
                            //						 a -> annotation, author
                            //						 b -> body
                            //						 c -> corpus
                            //						 d -> date, description,
                            //						 f -> feature, format
                            //						 g -> graph
                            //						 h -> head, history
                            //						 m -> matches, match
                            if (reader.LocalName.Equals("graph"))
                            {
                                graphRootID.Length = 0;
                                graphRootID.Append(reader.getAttributeValue(null, "root"));
                            }
                            else if (reader.LocalName.Equals("corpus"))
                            {
                                //							header.setCorpusID(reader.getAttributeValue(null, "id"));
                                //							header.setCorpusID(reader.getAttributeValue(null, "version"));
                            }
                            else if (reader.LocalName.Equals("feature"))
                            {
                                //							if (header != null) {
                                //								currentFeatureName.setLength(0);
                                //								currentFeatureName.append(reader.getAttributeValue(null, "name"));
                                //								header.addFeature(reader.getAttributeValue(null, "name"), reader.getAttributeValue(null, "domain"));
                                //							}
                                //							domain = Domain.valueOf(reader.getAttributeValue(null, "domain"));
                            }
                            else if (reader.LocalName.Equals("secedgelabel"))
                            {
                                //							domain = Domain.SEL;
                            }
                            else if (reader.LocalName.Equals("author"))
                            {
                                //							elementContent.setLength(0);
                                //							collectChar = true;
                            }
                            else if (reader.LocalName.Equals("date"))
                            {
                                //							elementContent.setLength(0);
                                //							collectChar = true;
                            }
                            else if (reader.LocalName.Equals("description"))
                            {
                                //							elementContent.setLength(0);
                                //							collectChar = true;
                            }
                            else if (reader.LocalName.Equals("format"))
                            {
                                //							elementContent.setLength(0);
                                //							collectChar = true;
                            }
                            else if (reader.LocalName.Equals("history"))
                            {
                                //							elementContent.setLength(0);
                                //							collectChar = true;
                            }
                        }
                    }
                    else if (@event == XMLStreamConstants.END_ELEMENT)
                    {
                        if (reader.LocalName.length() == 0)
                        {
                            continue;
                        }
                        if (reader.LocalName.charAt(0) == 'e')
                        {
                            // e -> edge, edgelabel
                        }
                        else if (reader.LocalName.charAt(0) == 'n')
                        {
                            // n -> nt, nonterminals, name
                            if (reader.LocalName.Equals("nt"))
                            {
                                ntid.Length = 0;
                            }
                            else if (reader.LocalName.Equals("nonterminals"))
                            {
                                if (phraseStructure.NTokenNode() == 1 && phraseStructure.nNonTerminals() == 0 && ((NonTerminalNode)phraseStructure.PhraseStructureRoot).nChildren() == 0)
                                {
                                    Edge.Edge e = phraseStructure.addPhraseStructureEdge(phraseStructure.PhraseStructureRoot, phraseStructure.GetTokenNode(1));
                                    SortedDictionary <string, SymbolTable> inputTables = dataFormatInstance.getPhraseStructureEdgeLabelSymbolTables(phraseStructure.SymbolTables);
                                    foreach (string name in inputTables.Keys)
                                    {
                                        e.addLabel(inputTables[name], "--");
                                    }
                                }
                            }
                            //						else if (reader.getLocalName().equals("name")) {
                            //							if (header != null) {
                            //								header.setMetaName(elementContent.toString());
                            //							}
                            //							collectChar = false;
                            //						}
                        }
                        else if (reader.LocalName.charAt(0) == 't')
                        {
                            // t -> t, terminals
                        }
                        else if (reader.LocalName.charAt(0) == 's')
                        {
                            // s -> subcorpus, secedge, s, secedgelabel
                            if (reader.LocalName.Equals("s"))
                            {
                                if (syntaxGraph.HasTokens())
                                {
                                    sentenceCount++;
                                }
                                if (syntaxGraph is MappablePhraseStructureGraph)
                                {
                                    ((MappablePhraseStructureGraph)syntaxGraph).Mapping.updateDependenyGraph(((MappablePhraseStructureGraph)syntaxGraph), ((PhraseStructure)syntaxGraph).PhraseStructureRoot);
                                }
                                return(true);
                            }
                        }
                        else if (reader.LocalName.charAt(0) == 'v')
                        {
                            // v -> variable, value
                            //						if (reader.getLocalName().equals("value")) {
                            //							if (header != null) {
                            //								if (domain == Domain.T || domain == Domain.NT || domain == Domain.FREC) {
                            //									header.addFeatureValue(currentFeatureName.toString(), valueName.toString(), elementContent.toString());
                            //								} else if (domain == Domain.EL) {
                            //									header.addEdgeLabelValue(valueName.toString(), elementContent.toString());
                            //								} else if (domain == Domain.SEL) {
                            //									header.addSecEdgeLabelValue(valueName.toString(), elementContent.toString());
                            //								}
                            //							}
                            //							collectChar = false;
                            //						}
                        }
                        else
                        {
                            //						 a -> annotation, author
                            //						 b -> body
                            //						 c -> corpus
                            //						 d -> date, description,
                            //						 f -> feature, format
                            //						 g -> graph
                            //						 h -> head, history
                            //						 m -> matches, match
                            if (reader.LocalName.Equals("body"))
                            {
                                //sentence = dataStructures.getSentence();
                                //phraseTree = dataStructures.getInPhraseTree();
                                //sentence.clear();
                                //phraseTree.clear();
                                //dataStructures.setLastProcessObject(true);
                            }
                            else if (reader.LocalName.Equals("author"))
                            {
                                //							if (header != null) {
                                //								header.setMetaAuthor(elementContent.toString());
                                //							}
                                //							collectChar = false;
                            }
                            else if (reader.LocalName.Equals("date"))
                            {
                                //							if (header != null) {
                                //								header.setMetaInDate(elementContent.toString());
                                //							}
                                //							collectChar = false;
                            }
                            else if (reader.LocalName.Equals("description"))
                            {
                                //							if (header != null) {
                                //								header.setMetaDescription(elementContent.toString());
                                //							}
                                //							collectChar = false;
                            }
                            else if (reader.LocalName.Equals("format"))
                            {
                                //							if (header != null) {
                                //								header.setMetaFormat(elementContent.toString());
                                //							}
                                //							collectChar = false;
                            }
                            else if (reader.LocalName.Equals("history"))
                            {
                                //							if (header != null) {
                                //								header.setMetaHistory(elementContent.toString());
                                //							}
                                //							collectChar = false;
                            }                             /* else if (reader.getLocalName().equals("annotation")) {
                                                           *    if (header != null) {
                                                           *            System.out.println(header.toTigerXML());
                                                           *    }
                                                           *    collectChar = false;
                                                           * } */
                        }
                    }
                    else if (@event == XMLStreamConstants.END_DOCUMENT)
                    {
                        if (syntaxGraph.HasTokens())
                        {
                            sentenceCount++;
                        }
                        if (cIterations < nIterations)
                        {
                            cIterations++;
                            reopen();
                            return(true);
                        }
                        return(false);
                    }
                    else if (@event == XMLStreamConstants.CHARACTERS)
                    {
                        //					if (collectChar) {
                        //						char[] ch = reader.getTextCharacters();
                        //						final int size = reader.getTextStart()+reader.getTextLength();
                        //						for (int i = reader.getTextStart(); i < size; i++) {
                        //							elementContent.append(ch[i]);
                        //						}
                        //					}
                    }
                }
            }
            catch (XMLStreamException e)
            {
                throw new DataFormatException("", e);
            }
        }
Пример #24
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean readSentence(org.maltparser.core.syntaxgraph.TokenStructure syntaxGraph) throws org.maltparser.core.exception.MaltChainedException
        public virtual bool readSentence(ITokenStructure syntaxGraph)
        {
            if (syntaxGraph == null || !(syntaxGraph is PhraseStructure))
            {
                return(false);
            }
            syntaxGraph.Clear();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.PhraseStructure phraseStructure = (org.maltparser.core.syntaxgraph.PhraseStructure)syntaxGraph;
            PhraseStructure phraseStructure = (PhraseStructure)syntaxGraph;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.symbol.SymbolTableHandler symbolTables = phraseStructure.getSymbolTables();
            SymbolTableHandler  symbolTables = phraseStructure.SymbolTables;
            PhraseStructureNode parent       = null;
            PhraseStructureNode child        = null;

            currentHeaderTable = NegraTables.UNDEF;
            string line = null;

            syntaxGraph.Clear();
            nonterminals.Clear();
            try
            {
                while (true)
                {
                    line = reader.ReadLine();
                    if (ReferenceEquals(line, null))
                    {
                        if (syntaxGraph.HasTokens())
                        {
                            sentenceCount++;
                            if (syntaxGraph is MappablePhraseStructureGraph)
                            {
                                ((MappablePhraseStructureGraph)syntaxGraph).Mapping.updateDependenyGraph(((MappablePhraseStructureGraph)syntaxGraph), ((PhraseStructure)syntaxGraph).PhraseStructureRoot);
                            }
                        }
                        if (cIterations < nIterations)
                        {
                            cIterations++;
                            reopen();
                            return(true);
                        }
                        return(false);
                    }
                    else if (line.StartsWith("#EOS", StringComparison.Ordinal))
                    {
                        currentTerminalSize    = 0;
                        currentNonTerminalSize = 0;
                        currentHeaderTable     = NegraTables.UNDEF;
                        if (syntaxGraph is MappablePhraseStructureGraph)
                        {
                            ((MappablePhraseStructureGraph)syntaxGraph).Mapping.updateDependenyGraph(((MappablePhraseStructureGraph)syntaxGraph), ((PhraseStructure)syntaxGraph).PhraseStructureRoot);
                        }
                        return(true);
                    }
                    else if (line.StartsWith("#BOS", StringComparison.Ordinal))
                    {
                        currentHeaderTable = NegraTables.SENTENCE;
                        int s = -1, e = -1;
                        for (int i = 5, n = line.Length; i < n; i++)
                        {
                            if (char.IsDigit(line[i]) && s == -1)
                            {
                                s = i;
                            }
                            if (line[i] == ' ')
                            {
                                e = i;
                                break;
                            }
                        }
                        if (s != e && s != -1 && e != -1)
                        {
                            phraseStructure.SentenceID = int.Parse(line.Substring(s, e - s));
                        }
                        sentenceCount++;
                    }
                    else if (currentHeaderTable == NegraTables.SENTENCE)
                    {
                        if (line.Length >= 2 && line[0] == '#' && char.IsDigit(line[1]))
                        {                         // Non-terminal
                            IEnumerator <ColumnDescription> columns = dataFormatInstance.GetEnumerator();
                            ColumnDescription column = null;
                            currentNonTerminalSize++;
                            char[] lineChars      = line.ToCharArray();
                            int    start          = 0;
                            int    secedgecounter = 0;
                            for (int i = 0, n = lineChars.Length; i < n; i++)
                            {
                                if (lineChars[i] == '\t' && start == i)
                                {
                                    start++;
                                }
                                else if (lineChars[i] == '\t' || i == n - 1)
                                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                    if (columns.hasNext())
                                    {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                        column = columns.next();
                                    }
                                    if (column.Position == 0)
                                    {
                                        int index = int.Parse((i == n - 1)?line.Substring(start + 1):line.Substring(start + 1, i - (start + 1)));
                                        child = nonterminals[index];
                                        if (child == null)
                                        {
                                            if (index != 0)
                                            {
                                                child = ((PhraseStructure)syntaxGraph).addNonTerminalNode(index - START_ID_OF_NONTERMINALS + 1);
                                            }
                                            nonterminals[index] = child;
                                        }
                                    }
                                    else if (column.Position == 2 && child != null)
                                    {
                                        syntaxGraph.AddLabel(child, "CAT", (i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                    }
                                    else if (column.Category == ColumnDescription.PHRASE_STRUCTURE_EDGE_LABEL)
                                    {
                                        edgelabelSymbol.Length = 0;
                                        edgelabelSymbol.Append((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                        edgelabelTableName.Length = 0;
                                        edgelabelTableName.Append(column.Name);
                                    }
                                    else if (column.Category == ColumnDescription.PHRASE_STRUCTURE_NODE_LABEL && child != null)
                                    {
                                        int index = int.Parse((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                        parent = nonterminals[index];
                                        if (parent == null)
                                        {
                                            if (index == 0)
                                            {
                                                parent = phraseStructure.PhraseStructureRoot;
                                            }
                                            else
                                            {
                                                parent = phraseStructure.addNonTerminalNode(index - START_ID_OF_NONTERMINALS + 1);
                                            }
                                            nonterminals[index] = parent;
                                        }
                                        Edge.Edge e = phraseStructure.addPhraseStructureEdge(parent, child);
                                        syntaxGraph.AddLabel(e, edgelabelTableName.ToString(), edgelabelSymbol.ToString());
                                    }
                                    else if (column.Category == ColumnDescription.SECONDARY_EDGE_LABEL && child != null)
                                    {
                                        if (secedgecounter % 2 == 0)
                                        {
                                            edgelabelSymbol.Length = 0;
                                            edgelabelSymbol.Append((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                            secedgecounter++;
                                        }
                                        else
                                        {
                                            int index = int.Parse((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                            if (index == 0)
                                            {
                                                parent = phraseStructure.PhraseStructureRoot;
                                            }
                                            else if (index < START_ID_OF_NONTERMINALS)
                                            {
                                                parent = phraseStructure.GetTokenNode(index);
                                            }
                                            else
                                            {
                                                parent = nonterminals[index];
                                                if (parent == null)
                                                {
                                                    parent = phraseStructure.addNonTerminalNode(index - START_ID_OF_NONTERMINALS + 1);
                                                    nonterminals[index] = parent;
                                                }
                                            }
                                            Edge.Edge e = phraseStructure.addSecondaryEdge(parent, child);
                                            e.addLabel(symbolTables.getSymbolTable(column.Name), edgelabelSymbol.ToString());
                                            secedgecounter++;
                                        }
                                    }
                                    start = i + 1;
                                }
                            }
                        }
                        else
                        {                         // Terminal
                            IEnumerator <ColumnDescription> columns = dataFormatInstance.GetEnumerator();
                            ColumnDescription column = null;

                            currentTerminalSize++;
                            child = syntaxGraph.AddTokenNode(currentTerminalSize);
                            char[] lineChars      = line.ToCharArray();
                            int    start          = 0;
                            int    secedgecounter = 0;
                            for (int i = 0, n = lineChars.Length; i < n; i++)
                            {
                                if (lineChars[i] == '\t' && start == i)
                                {
                                    start++;
                                }
                                else if (lineChars[i] == '\t' || i == n - 1)
                                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                    if (columns.hasNext())
                                    {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                        column = columns.next();
                                    }
                                    if (column.Category == ColumnDescription.INPUT && child != null)
                                    {
                                        syntaxGraph.AddLabel(child, column.Name, (i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                    }
                                    else if (column.Category == ColumnDescription.PHRASE_STRUCTURE_EDGE_LABEL && child != null)
                                    {                                     // && column.getName().equals("EDGELABEL")) {
                                        edgelabelSymbol.Length = 0;
                                        edgelabelSymbol.Append((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                        edgelabelTableName.Length = 0;
                                        edgelabelTableName.Append(column.Name);
                                    }
                                    else if (column.Category == ColumnDescription.PHRASE_STRUCTURE_NODE_LABEL && child != null)
                                    {
                                        int index = int.Parse((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                        parent = nonterminals[index];
                                        if (parent == null)
                                        {
                                            if (index == 0)
                                            {
                                                parent = phraseStructure.PhraseStructureRoot;
                                            }
                                            else
                                            {
                                                parent = phraseStructure.addNonTerminalNode(index - START_ID_OF_NONTERMINALS + 1);
                                            }
                                            nonterminals[index] = parent;
                                        }

                                        Edge.Edge e = phraseStructure.addPhraseStructureEdge(parent, child);
                                        syntaxGraph.AddLabel(e, edgelabelTableName.ToString(), edgelabelSymbol.ToString());
                                    }
                                    else if (column.Category == ColumnDescription.SECONDARY_EDGE_LABEL && child != null)
                                    {
                                        if (secedgecounter % 2 == 0)
                                        {
                                            edgelabelSymbol.Length = 0;
                                            edgelabelSymbol.Append((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                            secedgecounter++;
                                        }
                                        else
                                        {
                                            int index = int.Parse((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                            if (index == 0)
                                            {
                                                parent = phraseStructure.PhraseStructureRoot;
                                            }
                                            else if (index < START_ID_OF_NONTERMINALS)
                                            {
                                                parent = phraseStructure.GetTokenNode(index);
                                            }
                                            else
                                            {
                                                parent = nonterminals[index];
                                                if (parent == null)
                                                {
                                                    parent = phraseStructure.addNonTerminalNode(index - START_ID_OF_NONTERMINALS + 1);
                                                    nonterminals[index] = parent;
                                                }
                                            }
                                            Edge.Edge e = phraseStructure.addSecondaryEdge(parent, child);
                                            e.addLabel(symbolTables.getSymbolTable(column.Name), edgelabelSymbol.ToString());
                                            secedgecounter++;
                                        }
                                    }
                                    start = i + 1;
                                }
                            }
                        }
                    }
                    else if (line.StartsWith("%%", StringComparison.Ordinal))
                    {                     // comment skip
                    }
                    else if (line.StartsWith("#FORMAT", StringComparison.Ordinal))
                    {
                        //				int index = line.indexOf(' ');
                        //				if (index > -1) {
                        //					try {
                        //						formatVersion = Integer.parseInt(line.substring(index+1));
                        //					} catch (NumberFormatException e) {
                        //
                        //					}
                        //				}
                    }
                    else if (line.StartsWith("#BOT", StringComparison.Ordinal))
                    {
                        //				int index = line.indexOf(' ');
                        //				if (index > -1) {
                        //					if (line.substring(index+1).equals("ORIGIN")) {
                        //						currentHeaderTable = NegraTables.ORIGIN;
                        //					} else if (line.substring(index+1).equals("EDITOR")) {
                        //						currentHeaderTable = NegraTables.EDITOR;
                        //					} else if (line.substring(index+1).equals("WORDTAG")) {
                        //						currentHeaderTable = NegraTables.WORDTAG;
                        //					} else if (line.substring(index+1).equals("MORPHTAG")) {
                        //						currentHeaderTable = NegraTables.MORPHTAG;
                        //					} else if (line.substring(index+1).equals("NODETAG")) {
                        //						currentHeaderTable = NegraTables.NODETAG;
                        //					} else if (line.substring(index+1).equals("EDGETAG")) {
                        //						currentHeaderTable = NegraTables.EDGETAG;
                        //					} else if (line.substring(index+1).equals("SECEDGETAG")) {
                        //						currentHeaderTable = NegraTables.SECEDGETAG;
                        //					} else {
                        //						currentHeaderTable = NegraTables.UNDEF;
                        //					}
                        //				}
                    }
                    else if (line.StartsWith("#EOT", StringComparison.Ordinal))
                    {
                        currentHeaderTable = NegraTables.UNDEF;
                    }
                }
            }
            catch (IOException e)
            {
                throw new DataFormatException("Error when reading from the input file. ", e);
            }
        }
Пример #25
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean readSentence(org.maltparser.core.syntaxgraph.TokenStructure syntaxGraph) throws org.maltparser.core.exception.MaltChainedException
        public virtual bool readSentence(ITokenStructure syntaxGraph)
        {
            if (syntaxGraph == null || dataFormatInstance == null)
            {
                return(false);
            }
            syntaxGraph.Clear();
            syntaxGraph.SymbolTables.cleanUp();
            Element node = null;

            Edge.Edge edge = null;


            List <string> tokens = new List <string>();

            try
            {
                string line;
                while (!ReferenceEquals((line = reader.ReadLine()), null))
                {
                    if (line.Trim().Length == 0)
                    {
                        break;
                    }
                    else
                    {
                        tokens.Add(line.Trim());
                    }
                }
            }
            catch (IOException e)
            {
                close();
                throw new DataFormatException("Error when reading from the input file. ", e);
            }

            int terminalCounter = 0;

            for (int i = 0; i < tokens.Count; i++)
            {
                string token = tokens[i];

                if (token[0] == '#')
                {
                    syntaxGraph.AddComment(token, terminalCounter + 1);
                    continue;
                }
                string[] columns = token.Split("\t", true);
                if (columns[0].Contains("-") || columns[0].Contains("."))
                {
                    syntaxGraph.AddComment(token, terminalCounter + 1);
                    continue;
                }
                terminalCounter++;
                node = syntaxGraph.AddTokenNode(terminalCounter);

                IEnumerator <ColumnDescription> columnDescriptions = dataFormatInstance.GetEnumerator();
                for (int j = 0; j < columns.Length; j++)
                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    ColumnDescription columnDescription = columnDescriptions.next();

                    if (columnDescription.Category == ColumnDescription.INPUT && node != null)
                    {
                        syntaxGraph.AddLabel(node, columnDescription.Name, columns[j]);
                    }
                    else if (columnDescription.Category == ColumnDescription.HEAD)
                    {
                        if (syntaxGraph is IDependencyStructure)
                        {
                            if (columnDescription.Category != ColumnDescription.IGNORE && !columns[j].Equals(IGNORE_COLUMN_SIGN))
                            {
                                edge = ((IDependencyStructure)syntaxGraph).AddDependencyEdge(int.Parse(columns[j]), terminalCounter);
                            }
                        }
                        else
                        {
                            close();
                            throw new DataFormatException("The input graph is not a dependency graph and therefore it is not possible to add dependncy edges. ");
                        }
                    }
                    else if (columnDescription.Category == ColumnDescription.DEPENDENCY_EDGE_LABEL && edge != null)
                    {
                        syntaxGraph.AddLabel(edge, columnDescription.Name, columns[j]);
                    }
                }
            }

            if (!syntaxGraph.HasTokens())
            {
                return(false);
            }
            sentenceCount++;
            return(true);
        }
Пример #26
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void addIncomingEdge(org.maltparser.core.syntaxgraph.edge.Edge in) throws org.maltparser.core.exception.MaltChainedException
        public override void addIncomingEdge(Edge.Edge @in)
        {
            throw new SyntaxGraphException("It is not allowed for a root node to have an incoming edge");
        }
Пример #27
0
 public override void removeIncomingEdge(Edge.Edge @in)
 {
 }
Пример #28
0
        //	private void updateDependenyLabels(MappablePhraseStructureGraph graph, PhraseStructureNode top) throws MaltChainedException {
        //		if (top == null) {
        //			return;
        //		}
        //		DependencyNode head = null;
        //		DependencyNode dependent = null;
        //		if (top instanceof NonTerminalNode) {
        //			for (PhraseStructureNode node : ((NonTerminalNode)top).getChildren()) {
        //				if (node instanceof NonTerminalNode) {
        //					updateDependenyLabels(graph, node);
        //				} else {
        //					head = ((NonTerminalNode)top).getLexicalHead(headRules);
        //					dependent = (DependencyNode)node;
        //					if (head != null && dependent != null && head != dependent) {
        //						lockUpdate = true;
        //						if (dependent.hasHead()) {
        //							Edge e = dependent.getHeadEdge();
        //							labelDependencyEdge(graph, e, node);
        //						}
        //						lockUpdate = false;
        //					}
        //				}
        //			}
        //		}
        //
        //		dependent = null;
        //		if (top instanceof NonTerminalNode) {
        //			dependent = ((NonTerminalNode)top).getLexicalHead(headRules);
        //		}
        //
        //		if (dependent != null) {
        //			lockUpdate = true;
        //			if (dependent.hasHead()) {
        //				Edge e = dependent.getHeadEdge();
        //				labelDependencyEdge(graph, e, top);
        //			}
        //			lockUpdate = false;
        //		}
        //	}

//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void labelDependencyEdge(org.maltparser.core.syntaxgraph.MappablePhraseStructureGraph graph, org.maltparser.core.syntaxgraph.edge.Edge e, org.maltparser.core.syntaxgraph.node.PhraseStructureNode top) throws org.maltparser.core.exception.MaltChainedException
        private void labelDependencyEdge(MappablePhraseStructureGraph graph, Edge.Edge e, PhraseStructureNode top)
        {
            if (e == null)
            {
                return;
            }
            SymbolTableHandler symbolTables = graph.SymbolTables;

            deprel.Length  = 0;
            phrase.Length  = 0;
            headrel.Length = 0;

            e.removeLabel(symbolTables.getSymbolTable(DEPREL));
            e.removeLabel(symbolTables.getSymbolTable(HEADREL));
            e.removeLabel(symbolTables.getSymbolTable(PHRASE));
            e.removeLabel(symbolTables.getSymbolTable(ATTACH));

            int i = 0;
            SortedDictionary <string, SymbolTable> edgeLabelSymbolTables = phraseStructuretDataFormatInstance.getPhraseStructureEdgeLabelSymbolTables(symbolTableHandler);
            SortedDictionary <string, SymbolTable> nodeLabelSymbolTables = phraseStructuretDataFormatInstance.getPhraseStructureNodeLabelSymbolTables(symbolTableHandler);

            if (!top.Root)
            {
                foreach (string name in edgeLabelSymbolTables.Keys)
                {
                    if (top.hasParentEdgeLabel(symbolTables.getSymbolTable(name)))
                    {
                        deprel.Append(top.getParentEdgeLabelSymbol(symbolTables.getSymbolTable(name)));
                    }
                    else
                    {
                        deprel.Append(EMPTY_LABEL);
                    }
                    i++;
                    if (i < edgeLabelSymbolTables.Count)
                    {
                        deprel.Append(LABEL_ELEMENT_SEPARATOR);
                    }
                }
                if (deprel.Length != 0)
                {
                    e.addLabel(symbolTables.getSymbolTable(DEPREL), deprel.ToString());
                }
            }
            else
            {
                string deprelDefaultRootLabel = graph.GetDefaultRootEdgeLabelSymbol(symbolTables.getSymbolTable(DEPREL));
                if (!ReferenceEquals(deprelDefaultRootLabel, null))
                {
                    e.addLabel(symbolTables.getSymbolTable(DEPREL), deprelDefaultRootLabel);
                }
                else
                {
                    e.addLabel(symbolTables.getSymbolTable(DEPREL), EMPTY_LABEL);
                }
            }
            PhraseStructureNode tmp = (PhraseStructureNode)e.Target;

            while (tmp != top && tmp.Parent != null)
            {             // && !tmp.getParent().isRoot()) {
                i = 0;
                foreach (string name in edgeLabelSymbolTables.Keys)
                {
                    if (tmp.hasParentEdgeLabel(symbolTables.getSymbolTable(name)))
                    {
                        headrel.Append(tmp.getParentEdgeLabelSymbol(symbolTables.getSymbolTable(name)));
                    }
                    else
                    {
                        headrel.Append(EMPTY_LABEL);
                    }
                    i++;
                    if (i < edgeLabelSymbolTables.Count)
                    {
                        headrel.Append(LABEL_ELEMENT_SEPARATOR);
                    }
                }
                i = 0;
                headrel.Append(SPINE_ELEMENT_SEPARATOR);
                foreach (string name in nodeLabelSymbolTables.Keys)
                {
                    if (tmp.Parent.hasLabel(symbolTables.getSymbolTable(name)))
                    {
                        phrase.Append(tmp.Parent.getLabelSymbol(symbolTables.getSymbolTable(name)));
                    }
                    else
                    {
                        if (tmp.Parent.Root)
                        {
                            string deprelDefaultRootLabel = graph.GetDefaultRootEdgeLabelSymbol(symbolTables.getSymbolTable(PHRASE));
                            if (!ReferenceEquals(deprelDefaultRootLabel, null))
                            {
                                phrase.Append(deprelDefaultRootLabel);
                            }
                            else
                            {
                                phrase.Append(EMPTY_LABEL);
                            }
                        }
                        else
                        {
                            phrase.Append(EMPTY_LABEL);
                        }
                    }
                    i++;
                    if (i < nodeLabelSymbolTables.Count)
                    {
                        phrase.Append(LABEL_ELEMENT_SEPARATOR);
                    }
                }
                phrase.Append(SPINE_ELEMENT_SEPARATOR);
                tmp = tmp.Parent;
            }
            if (phrase.Length == 0)
            {
                headrel.Append(EMPTY_SPINE);
                phrase.Append(EMPTY_SPINE);
            }
            else
            {
                headrel.Length = headrel.Length - 1;
                phrase.Length  = phrase.Length - 1;
            }
            e.addLabel(symbolTables.getSymbolTable(HEADREL), headrel.ToString());
            e.addLabel(symbolTables.getSymbolTable(PHRASE), phrase.ToString());
            int a = 0;

            tmp = (PhraseStructureNode)e.Source;
            while (top.Parent != null && tmp.Parent != null && tmp.Parent != top.Parent)
            {
                a++;
                tmp = tmp.Parent;
            }
            e.addLabel(symbolTables.getSymbolTable(ATTACH), Convert.ToString(a));
        }
Пример #29
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void extract(org.maltparser.core.syntaxgraph.PhraseStructure phraseStructure, int begin, int end, org.maltparser.core.syntaxgraph.node.PhraseStructureNode parent) throws org.maltparser.core.exception.MaltChainedException
        private void extract(PhraseStructure phraseStructure, int begin, int end, PhraseStructureNode parent)
        {
            SymbolTableHandler symbolTables = phraseStructure.SymbolTables;
            int index = -1;

            for (int i = begin; i < end; i++)
            {
                if (input[i] == STARTING_BRACKET && (i == begin || input[i - 1] != '\\'))
                {
                    index = i;
                    break;
                }
            }
            if (index == -1)
            {
                TokenNode t = phraseStructure.AddTokenNode(terminalCounter);
                if (t == null)
                {
                    close();
                    throw new MaltChainedException("Bracket Reader error: could not create a terminal node. ");
                }

                terminalCounter++;
                Edge.Edge e = null;

                if (parent != null)
                {
                    e = phraseStructure.addPhraseStructureEdge(parent, (PhraseStructureNode)t);
                }
                else
                {
                    close();
                    throw new MaltChainedException("Bracket Reader error: could not find the parent node. ");
                }

                int start = begin;

                IEnumerator <string> inputColumnsIterator      = inputColumns.Keys.GetEnumerator();
                IEnumerator <string> edgeLabelsColumnsIterator = edgeLabelColumns.Keys.GetEnumerator();
                bool noneNode   = false;
                bool edgeLabels = false;
                for (int i = begin; i < end; i++)
                {
                    if (input[i] == EDGELABEL_SEPARATOR || (input[i] == INPUT_SEPARATOR && (i == begin || input[i - 1] != '\\')) || i == end - 1)
                    {
                        if (i == begin && input[i] == EDGELABEL_SEPARATOR)
                        {
                            noneNode = true;
                        }
                        else if (start == begin)
                        {
                            if ((noneNode && input[i] != EDGELABEL_SEPARATOR) || !noneNode)
                            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                if (inputColumnsIterator.hasNext())
                                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                    t.addLabel(symbolTables.getSymbolTable(inputColumns[inputColumnsIterator.next()].Name), decodeString((i == end - 1)?input.substring(start, end - start):input.substring(start, i - start)));
                                }
                                start = i + 1;
                                if (input[i] == EDGELABEL_SEPARATOR)
                                {
                                    edgeLabels = true;
                                }
                            }
                        }
                        else if (edgeLabels && e != null)
                        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                            if (edgeLabelsColumnsIterator.hasNext())
                            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                e.addLabel(symbolTables.getSymbolTable(edgeLabelColumns[edgeLabelsColumnsIterator.next()].Name), (i == end - 1)?input.substring(start, end - start):input.substring(start, i - start));
                            }
                            start = i + 1;
                            if (input[i] == INPUT_SEPARATOR && (i == begin || input[i - 1] != '\\'))
                            {
                                edgeLabels = false;
                            }
                        }
                        else if (input[i] == EDGELABEL_SEPARATOR && i != end - 1 && (input[i + 1] != INPUT_SEPARATOR && (i == begin || input[i - 1] != '\\')))
                        {
                        }
                        else
                        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                            if (inputColumnsIterator.hasNext())
                            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                t.addLabel(symbolTables.getSymbolTable(inputColumns[inputColumnsIterator.next()].Name), (i == end - 1)?input.substring(start, end - start):input.substring(start, i - start));
                            }
                            start = i + 1;
                        }
                    }
                }
            }
            else
            {
                PhraseStructureNode nt;
                Edge.Edge           e = null;
                if (parent == null)
                {
                    nt = phraseStructure.PhraseStructureRoot;
                }
                else
                {
                    nt = phraseStructure.addNonTerminalNode(nonTerminalCounter);
                    if (nt == null)
                    {
                        close();
                        throw new MaltChainedException("Bracket Reader error: could not create a nonterminal node. ");
                    }
                    nonTerminalCounter++;

                    e = phraseStructure.addPhraseStructureEdge(parent, nt);
                }
                IEnumerator <string> phraseLabelColumnsIterator = phraseLabelColumns.Keys.GetEnumerator();
                IEnumerator <string> edgeLabelsColumnsIterator  = edgeLabelColumns.Keys.GetEnumerator();
                int newbegin = begin;
                int start    = begin;

                for (int i = begin; i < index; i++)
                {
                    if (input[i] == EDGELABEL_SEPARATOR || i == index - 1)
                    {
                        if (start == newbegin)
                        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                            if (phraseLabelColumnsIterator.hasNext())
                            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                nt.addLabel(symbolTables.getSymbolTable(phraseLabelColumns[phraseLabelColumnsIterator.next()].Name), (i == index - 1)?input.substring(start, index - start):input.substring(start, i - start));
                            }
                            start = i + 1;
                        }
                        else if (e != null)
                        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                            if (edgeLabelsColumnsIterator.hasNext())
                            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                e.addLabel(symbolTables.getSymbolTable(edgeLabelColumns[edgeLabelsColumnsIterator.next()].Name), (i == index - 1)?input.substring(start, index - start):input.substring(start, i - start));
                            }
                            start = i + 1;
                        }
                    }
                    else if (input[i] == BLANK)
                    {
                        start++;
                        newbegin++;
                    }
                }

                bracketing(phraseStructure, index, end, nt);
            }
        }
Пример #30
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void updatePhraseStructureGraph(org.maltparser.core.syntaxgraph.MappablePhraseStructureGraph graph, org.maltparser.core.syntaxgraph.edge.Edge depEdge, boolean attachHeadSpineToRoot) throws org.maltparser.core.exception.MaltChainedException
        public virtual void updatePhraseStructureGraph(MappablePhraseStructureGraph graph, Edge.Edge depEdge, bool attachHeadSpineToRoot)
        {
            PhraseStructureNode dependentSpine = (PhraseStructureNode)depEdge.Target;

            if (((PhraseStructureNode)depEdge.Target).Parent == null)
            {
                // Restore dependent spine
                string phraseSpineLabel = null;
                string edgeSpineLabel   = null;
                int    empty_label      = 0;

                if (depEdge.hasLabel(graph.SymbolTables.getSymbolTable(PHRASE)))
                {
                    phraseSpineLabel = depEdge.getLabelSymbol(graph.SymbolTables.getSymbolTable(PHRASE));
                }
                if (depEdge.hasLabel(graph.SymbolTables.getSymbolTable(HEADREL)))
                {
                    edgeSpineLabel = depEdge.getLabelSymbol(graph.SymbolTables.getSymbolTable(HEADREL));
                }
                if (!ReferenceEquals(phraseSpineLabel, null) && phraseSpineLabel.Length > 0 && phraseSpineLabel[0] != EMPTY_SPINE)
                {
                    int ps = 0, es = 0, i = 0, j = 0, n = phraseSpineLabel.Length - 1, m = edgeSpineLabel.Length - 1;
                    PhraseStructureNode child = (PhraseStructureNode)depEdge.Target;
                    while (true)
                    {
                        while (i <= n && phraseSpineLabel[i] != SPINE_ELEMENT_SEPARATOR)
                        {
                            if (phraseSpineLabel[i] == QUESTIONMARK)
                            {
                                empty_label++;
                            }
                            else
                            {
                                empty_label = 0;
                            }
                            i++;
                        }
                        if (depEdge.Source.Root && i >= n)
                        {
                            dependentSpine = graph.PhraseStructureRoot;
                        }
                        else
                        {
                            dependentSpine = graph.addNonTerminalNode(++nonTerminalCounter);
                        }

                        if (empty_label != 2 && ps != i)
                        {
                            dependentSpine.addLabel(graph.SymbolTables.addSymbolTable(CAT), phraseSpineLabel.Substring(ps, i - ps));
                        }

                        empty_label = 0;
                        if (!ReferenceEquals(edgeSpineLabel, null))
                        {
                            while (j <= m && edgeSpineLabel[j] != SPINE_ELEMENT_SEPARATOR)
                            {
                                if (edgeSpineLabel[j] == QUESTIONMARK)
                                {
                                    empty_label++;
                                }
                                else
                                {
                                    empty_label = 0;
                                }
                                j++;
                            }
                        }
                        lockUpdate = true;
                        Edge.Edge e = graph.addPhraseStructureEdge(dependentSpine, child);
                        if (empty_label != 2 && es != j && !ReferenceEquals(edgeSpineLabel, null) && e != null)
                        {
                            e.addLabel(graph.SymbolTables.addSymbolTable(EDGELABEL), edgeSpineLabel.Substring(es, j - es));
                        }
                        else if (es == j)
                        {
                            e.addLabel(graph.SymbolTables.addSymbolTable(EDGELABEL), EMPTY_LABEL);
                        }

                        lockUpdate = false;
                        child      = dependentSpine;
                        if (i >= n)
                        {
                            break;
                        }
                        empty_label = 0;
                        ps          = i = i + 1;
                        es          = j = j + 1;
                    }
                }

                // Recursively attach the dependent spines to target node.
                DependencyNode target = (DependencyNode)depEdge.Target;
                for (int i = 0; i < target.LeftDependentCount; i++)
                {
                    updatePhraseStructureGraph(graph, target.getLeftDependent(i).HeadEdge, attachHeadSpineToRoot);
                }
                for (int i = target.RightDependentCount - 1; i >= 0; i--)
                {
                    updatePhraseStructureGraph(graph, target.getRightDependent(i).HeadEdge, attachHeadSpineToRoot);
                }
            }
            else
            {
                // If dependent spine already exist, then set dependentSpine to the highest nonterminal
                // of the dependent spine.
                while (dependentSpine.Parent != null && !dependentSpine.Parent.Root)
                {
                    dependentSpine = dependentSpine.Parent;
                }
            }


            PhraseStructureNode headSpine = null;

            if (((PhraseStructureNode)depEdge.Source).Parent != null)
            {
                // If head spine exist, then attach dependent spine to the head spine at the attachment level a.
                int a = 0;
                headSpine = ((PhraseStructureNode)depEdge.Source).Parent;
                if (depEdge.hasLabel(graph.SymbolTables.getSymbolTable(ATTACH)))
                {
                    try
                    {
                        a = int.Parse((depEdge.getLabelSymbol(graph.SymbolTables.getSymbolTable(ATTACH))));
                    }
                    catch (FormatException e)
                    {
                        throw new MaltChainedException(e.Message);
                    }
                }
                for (int i = 0; i < a && headSpine != null; i++)
                {
                    headSpine = headSpine.Parent;
                }

                if ((headSpine == null || headSpine == dependentSpine) && attachHeadSpineToRoot)
                {
                    headSpine = graph.PhraseStructureRoot;
                }
                if (headSpine != null)
                {
                    lockUpdate = true;
                    Edge.Edge e = graph.addPhraseStructureEdge(headSpine, dependentSpine);
                    if (depEdge.hasLabel(graph.SymbolTables.getSymbolTable(DEPREL)) && !depEdge.getLabelSymbol(graph.SymbolTables.getSymbolTable(DEPREL)).Equals(EMPTY_LABEL) & e != null)
                    {
                        e.addLabel(graph.SymbolTables.addSymbolTable(EDGELABEL), depEdge.getLabelSymbol(graph.SymbolTables.getSymbolTable(DEPREL)));
                    }
                    lockUpdate = false;
                }
            }
            else if (depEdge.Source.Root && !depEdge.Labeled)
            {
                headSpine  = graph.PhraseStructureRoot;
                lockUpdate = true;
                Edge.Edge e = graph.addPhraseStructureEdge(headSpine, dependentSpine);
                if (depEdge.hasLabel(graph.SymbolTables.getSymbolTable(DEPREL)) && !depEdge.getLabelSymbol(graph.SymbolTables.getSymbolTable(DEPREL)).Equals(EMPTY_LABEL) & e != null)
                {
                    e.addLabel(graph.SymbolTables.addSymbolTable(EDGELABEL), depEdge.getLabelSymbol(graph.SymbolTables.getSymbolTable(DEPREL)));
                }
                else
                {
                    e.addLabel(graph.SymbolTables.addSymbolTable(EDGELABEL), graph.GetDefaultRootEdgeLabelSymbol(graph.SymbolTables.getSymbolTable(DEPREL)));
                }
                lockUpdate = false;
                // Recursively attach the dependent spines to target node.
                DependencyNode target = (DependencyNode)depEdge.Target;
                for (int i = 0; i < target.LeftDependentCount; i++)
                {
                    updatePhraseStructureGraph(graph, target.getLeftDependent(i).HeadEdge, attachHeadSpineToRoot);
                }
                for (int i = target.RightDependentCount - 1; i >= 0; i--)
                {
                    updatePhraseStructureGraph(graph, target.getRightDependent(i).HeadEdge, attachHeadSpineToRoot);
                }
            }
        }