2015-04-02 97 views
4

我只是關注NLTK書的第5章,tagged_words()中的'simplify_tags'參數似乎是意想不到的。我使用Python 3.4,PyCharm和標準的NLTK包。NLTK - TypeError:tagged_words()得到了一個意想不到的關鍵字參數'simplify_tags'

In[4]: nltk.corpus.brown.tagged_words() 
Out[4]: [('The', 'AT'), ('Fulton', 'NP-TL'), ...] 
In[5]: nltk.corpus.brown.tagged_words(simplify_tags = True) 
Traceback (most recent call last): 
    File "C:\Python34\lib\site-packages\IPython\core\interactiveshell.py", line 2883, in run_code 
    exec(code_obj, self.user_global_ns, self.user_ns) 
    File "<ipython-input-5-c4f914e3e846>", line 1, in <module> 
    nltk.corpus.brown.tagged_words(simplify_tags = True) 
TypeError: tagged_words() got an unexpected keyword argument 'simplify_tags' 

沒有simplify_tags,運行此函數沒有問題。我讚賞任何建議或意見。謝謝!

+0

你認爲這是一個有效的命名參數?您是否正在使用nltk書的[最新版本](http://www.nltk.org/book/)? – 2015-04-02 18:01:47

+0

@DavidKelley謝謝!我正在關注最新版本(現在仍在更新)。 – 2015-04-02 19:43:05

回答

2

問題已解決。我現在正在跟蹤本書的latest version,它仍在更新中,它使用tagset ='universal'參數。

5

是的,如上所述,最新版本的簡化標籤是將它們映射到通用標記集(https://code.google.com/p/universal-pos-tags/)。

>>> from nltk.corpus import brown 
>>> brown.tagged_words(tagset='universal') 
[(u'The', u'DET'), (u'Fulton', u'NOUN'), ...] 
>>> brown.tagged_words(tagset='universal')[:10] 
[(u'The', u'DET'), (u'Fulton', u'NOUN'), (u'County', u'NOUN'), (u'Grand', u'ADJ'), (u'Jury', u'NOUN'), (u'said', u'VERB'), (u'Friday', u'NOUN'), (u'an', u'DET'), (u'investigation', u'NOUN'), (u'of', u'ADP')] 

但是做筆記仍存在有simplify_tags參數的一個文集的讀者,看到https://github.com/nltk/nltk/blob/develop/nltk/corpus/reader/ipipan.py#L23

可能是在管道的ipipan語料閱讀器移動到通用標記集。另外,請注意並非所有語料庫閱讀器都能夠映射到unviersal標記集,有些在TODO列表中,例如, https://github.com/nltk/nltk/blob/develop/nltk/corpus/reader/tagged.py#L260

相關問題