parse()只需要2个参数(给出3个)

时间:2014-06-10 06:17:41

标签: python nltk

运行此代码时:

import nltk
parser = nltk.parse.malt.MaltParser(working_dir="c:\maltparser-1.7.2",mco="engmalt.linear-   1.7", additional_java_args=['-Xmx512m'])
tree=parser.raw_parse("Hi,I am Kruthika");

我收到以下错误:

Traceback (most recent call last):
  File "<pyshell#14>", line 1, in <module>
   tree=parser.raw_parse("Hi,I am Kruthika");
  File "C:\Python27\lib\site-packages\nltk-3.0a3-py2.7.egg\nltk\parse\malt.py", line 127, in raw_parse
return self.parse(words, verbose)
TypeError: parse() takes exactly 2 arguments (3 given)

我只给了一个论点 我试图在Python(Windows操作系统)中使用MaltParser ..

1 个答案:

答案 0 :(得分:0)

我会尝试升级到NLTK的最新版本(3.0a4)。从您的路径(&#34; C:\ Python27 \ lib \ site-packages \ nltk-3.0a3-py2.7.egg \ nltk \ parse \ malt.py&#34;),您似乎有3.0a3。< / p>

问题出在raw_parse。函数的最后一行调用self.parse

def raw_parse(self, sentence, verbose=False):
    """
    Use MaltParser to parse a sentence. Takes a sentence as a string;
    before parsing, it will be automatically tokenized and tagged with this
    MaltParser instance's tagger.

    :param sentence: Input sentence to parse
    :type sentence: str
    :return: ``DependencyGraph`` the dependency graph representation of the sentence
    """
    words = word_tokenize(sentence)
    return self.parse(words, verbose)

当前版本中的签名是MaltParser.parse(self, words, verbose=False),它确实需要3个参数(&#34; self&#34;会自动传递),但在你的情况下它会抱怨解析需要只有2个参数。

您可以查看help(parser.parse)以查看您所拥有的版本中的签名,但这可能是个错误。