2014-06-10 90 views
0

運行此代碼:解析()到底需要2個參數(3給出)

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 ..

+0

你爲什麼說這只是一個參數?!我看到這些:1. working_dir =「c:\ maltparser-1.7.2」'2.'mco =「engmalt.linear- 1.7」'和3.'additional_java_args = [' - Xmx512m']' – Mehraban

+0

1 for parser .raw_parse ..我有3個用於nltk.parse.malt.MaltParser – ksved

+0

你只給'raw_parse()'一個參數(除了隱式'self'外),但是它調用'parse()'有三個:'self '(隱含在任何方法調用中),'單詞'和'verbose'。 –

回答

0

我會嘗試升級到NLTK的最新版本(3.0a4)。從你的路徑(「C:\ Python27 \ lib \ site-packages \ nltk-3.0a3-py2.7.egg \ nltk \ parse \ malt.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個參數(「自我」自動傳遞),但在你的情況下,它抱怨解析只需要2個參數。

您可以在help(parser.parse)看看看簽名是你有什麼版本,但它可能是一個錯誤。

相關問題