Ejemplo n.º 1
0
        /// <summary>
        /// Converts an array of tokens to a dependency structure
        /// </summary>
        /// <param name="tokens"> tokens an array of tokens </param>
        /// <param name="dataFormatSpecification"> a data format specification </param>
        /// <returns> a dependency structure </returns>
        /// <exception cref="MaltChainedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.core.syntaxgraph.DependencyStructure toDependencyStructure(String[] tokens, org.maltparser.core.io.dataformat.DataFormatSpecification dataFormatSpecification) throws org.maltparser.core.exception.MaltChainedException
        public virtual IDependencyStructure toDependencyStructure(string[] tokens, DataFormatSpecification dataFormatSpecification)
        {
            // Creates a symbol table handler
            SymbolTableHandler symbolTables = new HashSymbolTableHandler();

            // Initialize data format instance
            DataFormatInstance dataFormatInstance = dataFormatSpecification.createDataFormatInstance(symbolTables, "none");

            // Creates a dependency graph
            if (tokens == null || tokens.Length == 0)
            {
                throw new MaltChainedException("Nothing to convert. ");
            }
            IDependencyStructure outputGraph = new DependencyGraph(symbolTables);

            for (int i = 0; i < tokens.Length; i++)
            {
                IEnumerator <ColumnDescription> columns = dataFormatInstance.GetEnumerator();
                DependencyNode node  = outputGraph.AddDependencyNode(i + 1);
                string[]       items = tokens[i].Split("\t", true);
                Edge           edge  = null;
                for (int j = 0; j < items.Length; j++)
                {
//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:
                        ColumnDescription column = columns.next();
                        if (column.Category == ColumnDescription.INPUT && node != null)
                        {
                            outputGraph.AddLabel(node, column.Name, items[j]);
                        }
                        else if (column.Category == ColumnDescription.HEAD)
                        {
                            if (column.Category != ColumnDescription.IGNORE && !items[j].Equals("_"))
                            {
                                edge = ((IDependencyStructure)outputGraph).AddDependencyEdge(int.Parse(items[j]), i + 1);
                            }
                        }
                        else if (column.Category == ColumnDescription.DEPENDENCY_EDGE_LABEL && edge != null)
                        {
                            outputGraph.AddLabel(edge, column.Name, items[j]);
                        }
                    }
                }
            }
            outputGraph.SetDefaultRootEdgeLabel(outputGraph.SymbolTables.getSymbolTable("DEPREL"), "ROOT");
            return(outputGraph);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts an array of tokens to a dependency structure.
        ///
        /// </summary>
        /// <param name="tokens"> an array of tokens </param>
        /// <returns> a dependency structure </returns>
        /// <exception cref="MaltChainedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.core.syntaxgraph.DependencyStructure toDependencyStructure(String[] tokens) throws org.maltparser.core.exception.MaltChainedException
        public virtual IDependencyStructure toDependencyStructure(string[] tokens)
        {
            if (!initialized)
            {
                throw new MaltChainedException("No parser model has been initialized. Please use the method initializeParserModel() before invoking this method.");
            }
            if (tokens == null || tokens.Length == 0)
            {
                throw new MaltChainedException("Nothing to convert. ");
            }
            IDependencyStructure outputGraph = new DependencyGraph(singleMalt.SymbolTables);

            for (int i = 0; i < tokens.Length; i++)
            {
                IEnumerator <ColumnDescription> columns = dataFormatInstance.GetEnumerator();
                DependencyNode node  = outputGraph.AddDependencyNode(i + 1);
                string[]       items = tokens[i].Split("\t", true);
                Edge           edge  = null;
                for (int j = 0; j < items.Length; j++)
                {
//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:
                        ColumnDescription column = columns.next();
                        if (column.Category == ColumnDescription.INPUT && node != null)
                        {
                            outputGraph.AddLabel(node, column.Name, items[j]);
                        }
                        else if (column.Category == ColumnDescription.HEAD)
                        {
                            if (column.Category != ColumnDescription.IGNORE && !items[j].Equals("_"))
                            {
                                edge = ((IDependencyStructure)outputGraph).AddDependencyEdge(int.Parse(items[j]), i + 1);
                            }
                        }
                        else if (column.Category == ColumnDescription.DEPENDENCY_EDGE_LABEL && edge != null)
                        {
                            outputGraph.AddLabel(edge, column.Name, items[j]);
                        }
                    }
                }
            }
            outputGraph.SetDefaultRootEdgeLabel(outputGraph.SymbolTables.getSymbolTable("DEPREL"), "ROOT");
            return(outputGraph);
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.maltparser.core.syntaxgraph.DependencyStructure getOldDependencyGraph(org.maltparser.concurrent.graph.dataformat.DataFormat dataFormat, org.maltparser.core.symbol.SymbolTableHandler symbolTableHandlers, String[] tokens) throws org.maltparser.core.exception.MaltChainedException
        public static IDependencyStructure getOldDependencyGraph(DataFormat dataFormat, SymbolTableHandler symbolTableHandlers, string[] tokens)
        {
            IDependencyStructure oldGraph = new DependencyGraph(symbolTableHandlers);

            for (int i = 0; i < tokens.Length; i++)
            {
                oldGraph.AddDependencyNode(i + 1);
            }
            for (int i = 0; i < tokens.Length; i++)
            {
                DependencyNode node  = oldGraph.GetDependencyNode(i + 1);
                string[]       items = tokens[i].Split("\t", true);
                Edge           edge  = null;
                for (int j = 0; j < items.Length; j++)
                {
                    ColumnDescription column = dataFormat.GetColumnDescription(j);

                    if (column.Category == ColumnDescription.Input && node != null)
                    {
                        oldGraph.AddLabel(node, column.Name, items[j]);
                    }
                    else if (column.Category == ColumnDescription.Head)
                    {
                        if (column.Category != ColumnDescription.Ignore && !items[j].Equals(IGNORE_COLUMN_SIGN))
                        {
                            edge = oldGraph.AddDependencyEdge(int.Parse(items[j]), i + 1);
                        }
                    }
                    else if (column.Category == ColumnDescription.DependencyEdgeLabel && edge != null)
                    {
                        oldGraph.AddLabel(edge, column.Name, items[j]);
                    }
                }
            }

            oldGraph.SetDefaultRootEdgeLabel(oldGraph.SymbolTables.getSymbolTable("DEPREL"), "ROOT");
            return(oldGraph);
        }