小编Zub*_*air的帖子

使用python从NLTK中提取名词短语

我是python和nltk的新手.我已将代码从https://gist.github.com/alexbowe/879414转换为下面给出的代码,以使其运行许多文档/文本块.但是我得到了以下错误

 Traceback (most recent call last):
 File "E:/NLP/PythonProgrames/NPExtractor/AdvanceMain.py", line 16, in    <module>
  result = np_extractor.extract()
 File "E:\NLP\PythonProgrames\NPExtractor\NPExtractorAdvanced.py", line 67,   in extract
 for term in terms:
File "E:\NLP\PythonProgrames\NPExtractor\NPExtractorAdvanced.py", line 60, in get_terms
 for leaf in self.leaves(tree):
 TypeError: leaves() takes 1 positional argument but 2 were given
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我解决这个问题.我必须从数百万的产品评论中提取名词短语.我使用Java使用Standford NLP工具包,但它非常慢,所以我认为在python中使用nltk会更好.如果有更好的解决方案,请同时推荐.

import nltk
from nltk.corpus import stopwords
stopwords = stopwords.words('english')
grammar = r"""
 NBAR:
    {<NN.*|JJ>*<NN.*>}  # Nouns and Adjectives, terminated with Nouns
 NP:
    {<NBAR>}
    {<NBAR><IN><NBAR>}  # Above, connected with in/of/etc...
"""
   lemmatizer …
Run Code Online (Sandbox Code Playgroud)

python nltk

6
推荐指数
1
解决办法
4914
查看次数

标签 统计

nltk ×1

python ×1