コード例 #1
0
        /// <summary>
        /// Same as parse(String[] tokens), but instead it returns an array of tokens with a head index and a dependency type at the end of string
        /// </summary>
        /// <param name="tokens"> an array of tokens to parse </param>
        /// <returns> an array of tokens with a head index and a dependency type at the end of string </returns>
        /// <exception cref="MaltChainedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public String[] parseTokens(String[] tokens) throws org.maltparser.core.exception.MaltChainedException
        public virtual string[] parseTokens(string[] tokens)
        {
            IDependencyStructure outputGraph = parse(tokens);
            StringBuilder        sb          = new StringBuilder();

            string[]    outputTokens = new string[tokens.Length];
            SymbolTable deprelTable  = outputGraph.SymbolTables.getSymbolTable("DEPREL");

            foreach (int?index in outputGraph.TokenIndices)
            {
                sb.Length = 0;
                if (index <= tokens.Length)
                {
                    DependencyNode node = outputGraph.GetDependencyNode(index.Value);
                    sb.Append(tokens[index - 1]);
                    sb.Append('\t');
                    sb.Append(node.Head.Index);
                    sb.Append('\t');
                    if (node.HeadEdge.hasLabel(deprelTable))
                    {
                        sb.Append(node.HeadEdge.getLabelSymbol(deprelTable));
                    }
                    else
                    {
                        sb.Append(outputGraph.GetDefaultRootEdgeLabelSymbol(deprelTable));
                    }
                    outputTokens[index - 1] = sb.ToString();
                }
            }
            return(outputTokens);
        }