Esempio n. 1
0
        /// <summary>
        /// Reads the data format specification file
        /// </summary>
        /// <param name="dataFormatFileName"> the path to the data format specification file </param>
        /// <returns> a data format specification </returns>
        /// <exception cref="MaltChainedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.core.io.dataformat.DataFormatSpecification readDataFormatSpecification(String dataFormatFileName) throws org.maltparser.core.exception.MaltChainedException
        public virtual DataFormatSpecification readDataFormatSpecification(string dataFormatFileName)
        {
            DataFormatSpecification dataFormat = new DataFormatSpecification();

            dataFormat.parseDataFormatXMLfile(dataFormatFileName);
            return(dataFormat);
        }
Esempio n. 2
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);
        }