示例#1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static String[] toStringArray(org.maltparser.core.syntaxgraph.DependencyGraph graph, org.maltparser.core.io.dataformat.DataFormatInstance dataFormatInstance, org.maltparser.core.symbol.SymbolTableHandler symbolTables) throws org.maltparser.core.exception.MaltChainedException
        public static string[] toStringArray(DependencyGraph graph, DataFormatInstance dataFormatInstance, SymbolTableHandler symbolTables)
        {
            string[]      tokens = new string[graph.NTokenNode()];
            StringBuilder sb     = new StringBuilder();
            IEnumerator <ColumnDescription> columns = dataFormatInstance.GetEnumerator();

            foreach (int?index in graph.TokenIndices)
            {
                sb.Length = 0;
                if (index <= tokens.Length)
                {
                    ColumnDescription column = null;
                    TokenNode         node   = graph.GetTokenNode(index.Value);
                    while (columns.MoveNext())
                    {
                        column = columns.Current;
                        if (column.Category == ColumnDescription.INPUT)
                        {
                            if (!column.Name.Equals("ID"))
                            {
                                if (node.hasLabel(symbolTables.getSymbolTable(column.Name)) && node.getLabelSymbol(symbolTables.getSymbolTable(column.Name)).Length > 0)
                                {
                                    sb.Append(node.getLabelSymbol(symbolTables.getSymbolTable(column.Name)));
                                }
                                else
                                {
                                    sb.Append('_');
                                }
                            }
                            else
                            {
                                sb.Append(index.ToString());
                            }
                            sb.Append('\t');
                        }
                    }
                    sb.Length         = sb.Length - 1;
                    tokens[index - 1] = sb.ToString();
                    columns           = dataFormatInstance.GetEnumerator();
                }
            }
            return(tokens);
        }
示例#2
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.HasTokens())
            {
                return;
            }
            IEnumerator <ColumnDescription> columns = dataFormatInstance.GetEnumerator();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.symbol.SymbolTableHandler symbolTables = syntaxGraph.getSymbolTables();
            SymbolTableHandler symbolTables = syntaxGraph.SymbolTables;

            foreach (int i in syntaxGraph.TokenIndices)
            {
                writeComments(syntaxGraph, i);
                try
                {
                    ColumnDescription column = null;
                    while (columns.MoveNext())
                    {
                        column = columns.Current;

                        if (column.Category == ColumnDescription.INPUT)
                        {                         // && column.getType() != ColumnDescription.IGNORE) {
                            TokenNode node = syntaxGraph.GetTokenNode(i);
                            if (!column.Name.Equals("ID"))
                            {
                                if (node.hasLabel(symbolTables.getSymbolTable(column.Name)))
                                {
                                    output.Append(node.getLabelSymbol(symbolTables.getSymbolTable(column.Name)));
                                    if (output.Length != 0)
                                    {
                                        writer.Write(output.ToString());
                                    }
                                    else
                                    {
                                        writer.BaseStream.WriteByte('_');
                                    }
                                }
                                else
                                {
                                    writer.BaseStream.WriteByte('_');
                                }
                            }
                            else
                            {
                                writer.Write(Convert.ToString(i));
                            }
                        }
                        else if (column.Category == ColumnDescription.HEAD && syntaxGraph is IDependencyStructure)
                        {
                            if (((IDependencyStructure)syntaxGraph).GetDependencyNode(i).hasHead())
                            {
                                writer.Write(Convert.ToString(((IDependencyStructure)syntaxGraph).GetDependencyNode(i).Head.Index));
                            }
                            else
                            {
                                writer.Write(Convert.ToString(0));
                            }
                        }
                        else if (column.Category == ColumnDescription.DEPENDENCY_EDGE_LABEL && syntaxGraph is IDependencyStructure)
                        {
                            if (((IDependencyStructure)syntaxGraph).GetDependencyNode(i).hasHead() && ((IDependencyStructure)syntaxGraph).GetDependencyNode(i).hasHeadEdgeLabel(symbolTables.getSymbolTable(column.Name)))
                            {
                                output.Append(((IDependencyStructure)syntaxGraph).GetDependencyNode(i).getHeadEdgeLabelSymbol(symbolTables.getSymbolTable(column.Name)));
                            }
                            else
                            {
                                output.Append(((IDependencyStructure)syntaxGraph).GetDefaultRootEdgeLabelSymbol(symbolTables.getSymbolTable(column.Name)));
                            }

                            if (output.Length != 0)
                            {
                                writer.Write(output.ToString());
                            }
                        }
                        else
                        {
                            writer.Write(column.DefaultOutput);
                        }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                        if (columns.hasNext())
                        {
                            writer.BaseStream.WriteByte(TAB);
                        }
                        output.Length = 0;
                    }
                    writer.BaseStream.WriteByte(NEWLINE);
                    columns = dataFormatInstance.GetEnumerator();
                }
                catch (IOException e)
                {
                    close();
                    throw new DataFormatException("Could not write to the output file. ", e);
                }
            }
            writeComments(syntaxGraph, syntaxGraph.NTokenNode() + 1);
            try
            {
                writer.BaseStream.WriteByte('\n');
                writer.Flush();
            }
            catch (IOException e)
            {
                close();
                throw new DataFormatException("Could not write to the output file. ", e);
            }
        }