Esempio n. 1
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
            {
                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);
            }
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void writeNonTerminal(org.maltparser.core.symbol.SymbolTableHandler symbolTables, org.maltparser.core.syntaxgraph.node.NonTerminalNode nt, String id) throws org.maltparser.core.exception.MaltChainedException
        public virtual void writeNonTerminal(SymbolTableHandler symbolTables, NonTerminalNode nt, string id)
        {
            try
            {
                writer.Write("          <nt");
                writer.Write(" id=\"");
                writer.Write(id);
                writer.Write("\" ");
                foreach (ColumnDescription column in dataFormatInstance.PhraseStructureNodeLabelColumnDescriptionSet)
                {
                    if (nt.hasLabel(symbolTables.getSymbolTable(column.Name)))
                    {
                        writer.Write(column.Name.ToLower());
                        writer.Write("=");
                        writer.Write("\"");
                        writer.Write(Util.xmlEscape(nt.getLabelSymbol(symbolTables.getSymbolTable(column.Name))));
                        writer.Write("\" ");
                    }
                }
                writer.Write(">\n");

                for (int i = 0, n = nt.nChildren(); i < n; i++)
                {
                    PhraseStructureNode child = nt.getChild(i);
                    writer.Write("            <edge ");

                    foreach (ColumnDescription column in dataFormatInstance.PhraseStructureEdgeLabelColumnDescriptionSet)
                    {
                        if (child.hasParentEdgeLabel(symbolTables.getSymbolTable(column.Name)))
                        {
                            writer.Write(column.Name.ToLower());
                            writer.Write("=\"");
                            writer.Write(Util.xmlEscape(child.getParentEdgeLabelSymbol(symbolTables.getSymbolTable(column.Name))));
                            writer.Write("\" ");
                        }
                    }
                    if (child is TokenNode)
                    {
                        if (!labeledTerminalID)
                        {
                            tmpID.Length = 0;
                            tmpID.Append(sentenceID);
                            tmpID.Append('_');
                            tmpID.Append(Convert.ToString(child.Index));
                            writer.Write(" idref=\"");
                            writer.Write(tmpID.ToString());
                            writer.Write("\"");
                        }
                        else
                        {
                            writer.Write(" idref=\"");
                            writer.Write(child.getLabelSymbol(symbolTables.getSymbolTable("ID")));
                            writer.Write("\"");
                        }
                    }
                    else
                    {
                        tmpID.Length = 0;
                        tmpID.Append(sentenceID);
                        tmpID.Append('_');
                        tmpID.Append(Convert.ToString(child.Index + START_ID_OF_NONTERMINALS - 1));
                        writer.Write(" idref=\"");
                        writer.Write(tmpID.ToString());
                        writer.Write("\"");
                    }
                    writer.Write(" />\n");
                }
                writer.Write("          </nt>\n");
            }
            catch (IOException e)
            {
                throw new DataFormatException("The TigerXML writer is not able to write. ", e);
            }
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeElement(org.maltparser.core.symbol.SymbolTableHandler symbolTables, org.maltparser.core.syntaxgraph.node.PhraseStructureNode element, int depth) throws org.maltparser.core.exception.MaltChainedException
        private void writeElement(SymbolTableHandler symbolTables, PhraseStructureNode element, int depth)
        {
            try
            {
                if (element is TokenNode)
                {
                    PhraseStructureNode t     = (PhraseStructureNode)element;
                    SymbolTable         table = null;
                    writer.Write("\n" + getIndentation(depth) + STARTING_BRACKET);
                    int i = 0;
                    foreach (string inputColumn in inputColumns.Keys)
                    {
                        if (i != 0)
                        {
                            writer.BaseStream.WriteByte(INPUT_SEPARATOR);
                        }
                        table = symbolTables.getSymbolTable(inputColumns[inputColumn].Name);
                        if (t.hasLabel(table))
                        {
                            writer.Write(encodeString(t.getLabelSymbol(table)));
                        }
                        if (i == 0)
                        {
                            foreach (string edgeLabelColumn in edgeLabelColumns.Keys)
                            {
                                table = symbolTables.getSymbolTable(edgeLabelColumns[edgeLabelColumn].Name);
                                if (t.hasParentEdgeLabel(table) && !t.Parent.Root && !t.getParentEdgeLabelSymbol(table).Equals(EMPTY_EDGELABEL))
                                {
                                    writer.BaseStream.WriteByte(EDGELABEL_SEPARATOR);
                                    writer.Write(t.getParentEdgeLabelSymbol(table));
                                }
                            }
                        }
                        i++;
                    }
                    writer.BaseStream.WriteByte(CLOSING_BRACKET);
                }
                else
                {
                    NonTerminalNode nt = (NonTerminalNode)element;
                    writer.Write("\n" + getIndentation(depth) + STARTING_BRACKET);
                    SymbolTable table = null;
                    int         i     = 0;
                    foreach (string phraseLabelColumn in phraseLabelColumns.Keys)
                    {
                        if (i != 0)
                        {
                            writer.BaseStream.WriteByte(INPUT_SEPARATOR);
                        }
                        table = symbolTables.getSymbolTable(phraseLabelColumns[phraseLabelColumn].Name);
                        if (nt.hasLabel(table))
                        {
                            writer.BaseStream.WriteByte(nt.getLabelSymbol(table));
                        }
                        if (i == 0)
                        {
                            foreach (string edgeLabelColumn in edgeLabelColumns.Keys)
                            {
                                table = symbolTables.getSymbolTable(edgeLabelColumns[edgeLabelColumn].Name);
                                if (nt.hasParentEdgeLabel(table) && !nt.Parent.Root && !nt.getParentEdgeLabelSymbol(table).Equals(EMPTY_EDGELABEL))
                                {
                                    writer.BaseStream.WriteByte(EDGELABEL_SEPARATOR);
                                    writer.Write(nt.getParentEdgeLabelSymbol(table));
                                }
                            }
                        }
                        i++;
                    }
                    foreach (PhraseStructureNode node in ((NonTerminalNode)element).Children)
                    {
                        writeElement(symbolTables, node, depth + 1);
                    }
                    writer.Write("\n" + getIndentation(depth) + CLOSING_BRACKET);
                }
            }
            catch (IOException e)
            {
                throw new DataFormatException("Could not write to the output file. ", e);
            }
        }
Esempio n. 4
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);
            }
        }