コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void bracketing(org.maltparser.core.syntaxgraph.PhraseStructure phraseStructure, int start, int end, org.maltparser.core.syntaxgraph.node.PhraseStructureNode parent) throws org.maltparser.core.exception.MaltChainedException
        private void bracketing(PhraseStructure phraseStructure, int start, int end, PhraseStructureNode parent)
        {
            int bracketsdepth = 0;
            int startpos      = start - 1;

            for (int i = start, n = end; i < n; i++)
            {
                if (input[i] == STARTING_BRACKET && (i == 0 || input[i - 1] != '\\'))
                {
                    if (bracketsdepth == 0)
                    {
                        startpos = i;
                    }
                    bracketsdepth++;
                }
                else if (input[i] == CLOSING_BRACKET && (i == 0 || input[i - 1] != '\\'))
                {
                    bracketsdepth--;
                    if (bracketsdepth == 0)
                    {
                        extract(phraseStructure, startpos + 1, i, parent);
                    }
                }
            }
        }
コード例 #2
0
ファイル: TigerXMLWriter.cs プロジェクト: Sojaner/NMaltParser
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void writeSentence(org.maltparser.core.syntaxgraph.TokenStructure syntaxGraph) throws org.maltparser.core.exception.MaltChainedException
        public virtual void writeSentence(ITokenStructure syntaxGraph)
        {
            if (syntaxGraph == null || dataFormatInstance == null)
            {
                return;
            }
            if (syntaxGraph.HasTokens())
            {
                sentenceCount++;
//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;
                try
                {
                    sentenceID.Length = 0;
                    sentenceID.Append(sentencePrefix);
                    if (phraseStructure.SentenceID != 0)
                    {
                        sentenceID.Append(Convert.ToString(phraseStructure.SentenceID));
                    }
                    else
                    {
                        sentenceID.Append(Convert.ToString(sentenceCount));
                    }
                    writer.Write("    <s id=\"");
                    writer.Write(sentenceID.ToString());
                    writer.Write("\">\n");

                    RootID = phraseStructure;
                    writer.Write("      <graph root=\"");
                    writer.Write(rootID.ToString());
                    writer.Write("\" ");
                    writer.Write("discontinuous=\"");
                    writer.Write(Convert.ToString(!phraseStructure.Continuous));
                    writer.Write("\">\n");

                    writeTerminals(phraseStructure);
                    if (phraseStructure.NTokenNode() != 1 || rootHandling.Equals(RootHandling.TALBANKEN))
                    {
                        writeNonTerminals(phraseStructure);
                    }
                    else
                    {
                        writer.Write("        <nonterminals/>\n");
                    }
                    writer.Write("      </graph>\n");
                    writer.Write("    </s>\n");
                }
                catch (IOException e)
                {
                    throw new DataFormatException("The TigerXML writer could not write to file. ", e);
                }
            }
        }
コード例 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void calculateIndices(org.maltparser.core.syntaxgraph.PhraseStructure phraseStructure) throws org.maltparser.core.exception.MaltChainedException
        private void calculateIndices(PhraseStructure phraseStructure)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.SortedMap<int,int> heights = new java.util.TreeMap<int,int>();
            SortedDictionary <int, int> heights = new SortedDictionary <int, int>();

            foreach (int index in phraseStructure.NonTerminalIndices)
            {
                heights[index] = ((NonTerminalNode)phraseStructure.getNonTerminalNode(index)).Height;
            }

            bool done = false;
            int  h    = 1;
            int  ntid = START_ID_OF_NONTERMINALS;

            nonTerminalIndexMap.clear();
            while (!done)
            {
                done = true;
                foreach (int index in phraseStructure.NonTerminalIndices)
                {
                    if (heights[index] == h)
                    {
                        NonTerminalNode nt = (NonTerminalNode)phraseStructure.getNonTerminalNode(index);
                        nonTerminalIndexMap.put(nt.Index, ntid++);
                        //					nonTerminalIndexMap.put(nt.getIndex(), nt.getIndex()+START_ID_OF_NONTERMINALS-1);
                        done = false;
                    }
                }
                h++;
            }

            //		boolean done = false;
            //		int h = 1;
            ////		int ntid = START_ID_OF_NONTERMINALS;
            ////		nonTerminalIndexMap.clear();
            //		while (!done) {
            //			done = true;
            //			for (int index : phraseStructure.getNonTerminalIndices()) {
            //				if (heights.get(index) == h) {
            //					NonTerminalNode nt = (NonTerminalNode)phraseStructure.getNonTerminalNode(index);
            ////					nonTerminalIndexMap.put(nt.getIndex(), ntid++);
            //					nonTerminalIndexMap.put(nt.getIndex(), nt.getIndex()+START_ID_OF_NONTERMINALS-1);
            //					done = false;
            //				}
            //			}
            //			h++;
            //		}
        }
コード例 #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void writeSentence(org.maltparser.core.syntaxgraph.TokenStructure syntaxGraph) throws org.maltparser.core.exception.MaltChainedException
        public virtual void writeSentence(ITokenStructure syntaxGraph)
        {
            if (syntaxGraph == null || dataFormatInstance == null || !(syntaxGraph is PhraseStructure) || !syntaxGraph.HasTokens())
            {
                return;
            }
            PhraseStructure phraseStructure = (PhraseStructure)syntaxGraph;

            sentenceCount++;
            try
            {
                writer.Write("#BOS ");
                if (phraseStructure.SentenceID != 0)
                {
                    writer.Write(Convert.ToString(phraseStructure.SentenceID));
                }
                else
                {
                    writer.Write(Convert.ToString(sentenceCount));
                }
                writer.BaseStream.WriteByte('\n');

                if (phraseStructure.hasNonTerminals())
                {
                    calculateIndices(phraseStructure);
                    writeTerminals(phraseStructure);
                    writeNonTerminals(phraseStructure);
                }
                else
                {
                    writeTerminals(phraseStructure);
                }
                writer.Write("#EOS ");
                if (phraseStructure.SentenceID != 0)
                {
                    writer.Write(Convert.ToString(phraseStructure.SentenceID));
                }
                else
                {
                    writer.Write(Convert.ToString(sentenceCount));
                }
                writer.BaseStream.WriteByte('\n');
            }
            catch (IOException e)
            {
                throw new DataFormatException("Could not write to the output file. ", e);
            }
        }
コード例 #5
0
ファイル: TigerXMLWriter.cs プロジェクト: Sojaner/NMaltParser
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void writeNonTerminals(org.maltparser.core.syntaxgraph.PhraseStructure phraseStructure) throws org.maltparser.core.exception.MaltChainedException
        public virtual void writeNonTerminals(PhraseStructure phraseStructure)
        {
            try
            {
                SortedDictionary <int, int> heights = new SortedDictionary <int, int>();
                foreach (int index in phraseStructure.NonTerminalIndices)
                {
                    heights[index] = ((NonTerminalNode)phraseStructure.getNonTerminalNode(index)).Height;
                }
                writer.Write("        <nonterminals>\n");
                bool done = false;
                int  h    = 1;
                while (!done)
                {
                    done = true;
                    foreach (int index in phraseStructure.NonTerminalIndices)
                    {
                        if (heights[index] == h)
                        {
                            NonTerminalNode nt = (NonTerminalNode)phraseStructure.getNonTerminalNode(index);
                            tmpID.Length = 0;
                            tmpID.Append(sentenceID);
                            tmpID.Append('_');
                            tmpID.Append(Convert.ToString(nt.Index + START_ID_OF_NONTERMINALS - 1));
                            writeNonTerminal(phraseStructure.SymbolTables, nt, tmpID.ToString());
                            done = false;
                        }
                    }
                    h++;
                }

                writeNonTerminal(phraseStructure.SymbolTables, (NonTerminalNode)phraseStructure.PhraseStructureRoot, rootID.ToString());
                writer.Write("        </nonterminals>\n");
            }
            catch (IOException e)
            {
                throw new DataFormatException("The TigerXML writer is not able to write. ", e);
            }
        }
コード例 #6
0
ファイル: TigerXMLWriter.cs プロジェクト: Sojaner/NMaltParser
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeTerminals(org.maltparser.core.syntaxgraph.PhraseStructure phraseStructure) throws org.maltparser.core.exception.MaltChainedException
        private void writeTerminals(PhraseStructure phraseStructure)
        {
            try
            {
                writer.Write("        <terminals>\n");
                foreach (int index in phraseStructure.TokenIndices)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.PhraseStructureNode t = phraseStructure.getTokenNode(index);
                    PhraseStructureNode t = phraseStructure.GetTokenNode(index);
                    writer.Write("          <t ");
                    if (!labeledTerminalID)
                    {
                        tmpID.Length = 0;
                        tmpID.Append(sentenceID);
                        tmpID.Append('_');
                        tmpID.Append(Convert.ToString(t.Index));
                        writer.Write("id=\"");
                        writer.Write(tmpID.ToString());
                        writer.Write("\" ");
                    }

                    foreach (ColumnDescription column in dataFormatInstance.InputColumnDescriptionSet)
                    {
                        writer.Write(column.Name.ToLower());
                        writer.Write("=\"");
                        writer.Write(Util.xmlEscape(t.getLabelSymbol(phraseStructure.SymbolTables.getSymbolTable(column.Name))));
                        writer.Write("\" ");
                    }
                    writer.Write("/>\n");
                }
                writer.Write("        </terminals>\n");
            }
            catch (IOException e)
            {
                throw new DataFormatException("The TigerXML writer is not able to write. ", e);
            }
        }
コード例 #7
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);
            }
        }
コード例 #8
0
ファイル: NegraReader.cs プロジェクト: Sojaner/NMaltParser
//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);
            }
        }
コード例 #9
0
ファイル: TigerXMLReader.cs プロジェクト: Sojaner/NMaltParser
//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);
            }
        }
コード例 #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeNonTerminals(org.maltparser.core.syntaxgraph.PhraseStructure phraseStructure) throws org.maltparser.core.exception.MaltChainedException
        private void writeNonTerminals(PhraseStructure phraseStructure)
        {
//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;

            foreach (int index in nonTerminalIndexMap.Keys)
            {
                //		for (int index : phraseStructure.getNonTerminalIndices()) {
                NonTerminalNode nonTerminal = (NonTerminalNode)phraseStructure.getNonTerminalNode(index);

                if (nonTerminal == null || nonTerminal.Root)
                {
                    return;
                }
                try
                {
                    writer.BaseStream.WriteByte('#');
                    //				writer.write(Integer.toString(index+START_ID_OF_NONTERMINALS-1));
                    writer.Write(Convert.ToString(nonTerminalIndexMap.get(index)));
                    writer.Write("\t\t\t--\t\t\t");
                    if (nonTerminal.hasLabel(symbolTables.getSymbolTable("CAT")))
                    {
                        writer.BaseStream.WriteByte(nonTerminal.getLabelSymbol(symbolTables.getSymbolTable("CAT")));
                    }
                    else
                    {
                        writer.Write("--");
                    }
                    writer.Write("\t--\t\t");
                    if (nonTerminal.hasParentEdgeLabel(symbolTables.getSymbolTable("LABEL")))
                    {
                        writer.Write(nonTerminal.getParentEdgeLabelSymbol(symbolTables.getSymbolTable("LABEL")));
                    }
                    else
                    {
                        writer.Write("--");
                    }
                    writer.BaseStream.WriteByte('\t');
                    if (nonTerminal.Parent == null || nonTerminal.Parent.Root)
                    {
                        writer.BaseStream.WriteByte('0');
                    }
                    else
                    {
                        //					writer.write(Integer.toString(nonTerminal.getParent().getIndex()+START_ID_OF_NONTERMINALS-1));
                        writer.Write(Convert.ToString(nonTerminalIndexMap.get(nonTerminal.Parent.Index)));
                    }
                    foreach (Edge.Edge e in nonTerminal.IncomingSecondaryEdges)
                    {
                        if (e.hasLabel(symbolTables.getSymbolTable("SECEDGELABEL")))
                        {
                            writer.BaseStream.WriteByte('\t');
                            writer.Write(e.getLabelSymbol(symbolTables.getSymbolTable("SECEDGELABEL")));
                            writer.BaseStream.WriteByte('\t');
                            if (e.Source is NonTerminalNode)
                            {
                                //							writer.write(Integer.toString(e.getSource().getIndex()+START_ID_OF_NONTERMINALS-1));
                                writer.Write(Convert.ToString(nonTerminalIndexMap.get(e.Source.Index)));
                            }
                            else
                            {
                                writer.Write(Convert.ToString(e.Source.Index));
                            }
                        }
                    }
                    writer.Write("\n");
                }
                catch (IOException e)
                {
                    throw new DataFormatException("The Negra writer is not able to write the non-terminals. ", e);
                }
            }
        }
コード例 #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeTerminals(org.maltparser.core.syntaxgraph.PhraseStructure phraseStructure) throws org.maltparser.core.exception.MaltChainedException
        private void writeTerminals(PhraseStructure phraseStructure)
        {
            try
            {
//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;
                foreach (int index in phraseStructure.TokenIndices)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.PhraseStructureNode terminal = phraseStructure.getTokenNode(index);
                    PhraseStructureNode terminal = phraseStructure.GetTokenNode(index);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Iterator<org.maltparser.core.io.dataformat.ColumnDescription> columns = dataFormatInstance.iterator();
                    IEnumerator <ColumnDescription> columns = dataFormatInstance.GetEnumerator();
                    ColumnDescription column = null;
                    int ti = 1;
                    while (columns.MoveNext())
                    {
                        column = columns.Current;
                        if (column.Category == ColumnDescription.INPUT)
                        {
                            SymbolTable table = symbolTables.getSymbolTable(column.Name);
                            writer.Write(terminal.getLabelSymbol(table));
                            int nTabs = 1;
                            if (ti == 1 || ti == 2)
                            {
                                nTabs = 3 - (terminal.getLabelSymbol(table).Length / 8);
                            }
                            else if (ti == 3)
                            {
                                nTabs = 1;
                            }
                            else if (ti == 4)
                            {
                                nTabs = 2 - (terminal.getLabelSymbol(table).Length / 8);
                            }
                            if (nTabs < 1)
                            {
                                nTabs = 1;
                            }
                            for (int j = 0; j < nTabs; j++)
                            {
                                writer.BaseStream.WriteByte('\t');
                            }
                            ti++;
                        }
                        else if (column.Category == ColumnDescription.PHRASE_STRUCTURE_EDGE_LABEL)
                        {
                            SymbolTable table = symbolTables.getSymbolTable(column.Name);
                            if (terminal.Parent != null && terminal.hasParentEdgeLabel(table))
                            {
                                writer.Write(terminal.getParentEdgeLabelSymbol(table));
                                writer.BaseStream.WriteByte('\t');
                            }
                            else
                            {
                                writer.Write("--\t");
                            }
                        }
                        else if (column.Category == ColumnDescription.PHRASE_STRUCTURE_NODE_LABEL)
                        {
                            if (terminal.Parent == null || terminal.Parent == phraseStructure.PhraseStructureRoot)
                            {
                                writer.BaseStream.WriteByte('0');
                            }
                            else
                            {
                                writer.Write(Convert.ToString(nonTerminalIndexMap.get(terminal.Parent.Index)));
                                //							writer.write(Integer.toString(terminal.getParent().getIndex()+START_ID_OF_NONTERMINALS-1));
                            }
                        }
                    }
                    SymbolTable table = symbolTables.getSymbolTable(column.Name);
                    foreach (Edge.Edge e in terminal.IncomingSecondaryEdges)
                    {
                        if (e.hasLabel(table))
                        {
                            writer.BaseStream.WriteByte('\t');
                            writer.Write(e.getLabelSymbol(table));
                            writer.BaseStream.WriteByte('\t');
                            if (e.Source is NonTerminalNode)
                            {
                                writer.Write(Convert.ToString(nonTerminalIndexMap.get(e.Source.Index)));
                                //							writer.write(Integer.toString(e.getSource().getIndex()+START_ID_OF_NONTERMINALS-1));
                            }
                            else
                            {
                                writer.Write(Convert.ToString(e.Source.Index));
                            }
                        }
                    }
                    writer.Write("\n");
                }
            }
            catch (IOException e)
            {
                throw new DataFormatException("The Negra writer is not able to write. ", e);
            }
        }