parse()只接受2个参数(给定3个)

2024-04-29 20:33:40 发布

您现在位置:Python中文网/ 问答频道 /正文

运行此代码时:

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");

我收到以下错误:

^{pr2}$

我只提出一个论点 我正在尝试在Python(Windows操作系统)中使用MaltParser。。在


Tags: 代码importparserparsedirjavaworkingadditional
1条回答
网友
1楼 · 发布于 2024-04-29 20:33:40

我会尝试升级到NLTK的最新版本(3.0a4)。从您的路径(“C:\Python27\lib\site packages\nltk-3.0a3-py2.7.egg\nltk\parse\麦芽糖.py“),您似乎有3.0a3。在

问题在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个参数(“self”是自动传递的),但是在您的例子中,它抱怨parse只接受2个参数。在

您可以查看help(parser.parse),看看您所拥有的版本中的签名是什么,但它可能是一个bug。在

相关问题 更多 >