我正在尝试做一个计数器,它使用POS trigrams列表来检查一个大的trigrams列表并找到它们的频率。 目前我的代码如下:
from nltk import trigrams
from nltk.tokenize import wordpunct_tokenize
from nltk import bigrams
from collections import Counter
import nltk
text= ["This is an example sentence."]
trigram_top= ['PRP', 'MD', 'VB']
for words in text:
tokens = wordpunct_tokenize (words)
tags = nltk.pos_tag (tokens)
trigram_list=trigrams(tags)
list_tri=Counter (t for t in trigram_list if t in trigram_top)
print list_tri
我的柜台是空的。我怎么修补这个? 在早期的版本中,我确实得到了数据,但是每次迭代都会不断增加(在实际程序中,文本是不同文件的集合)。 有人有主意吗?在
让我们放一些
print
来调试:注意,
list=
部分是多余的,我已经将生成器更改为只接受单词而不是pos标记我们可以看到,没有一个pos标记直接匹配您的trigram_top-您可能需要修改您的比较检查来迎合VB/VBZ。。。在
一种可能是改变路线:
^{pr2}$相关问题 更多 >
编程相关推荐