相关疑难解决方法(0)

针对特定单词的NLTK搭配

我知道如何使用NLTK获得bigram和trigram搭配,并将它们应用到我自己的语料库中.代码如下.

然而,我不确定(1)如何获得特定单词的搭配?(2)NLTK是否具有基于对数似然比的配置度量?

import nltk
from nltk.collocations import *
from nltk.tokenize import word_tokenize

text = "this is a foo bar bar black sheep  foo bar bar black sheep foo bar bar black  sheep shep bar bar black sentence"

trigram_measures = nltk.collocations.TrigramAssocMeasures()
finder = TrigramCollocationFinder.from_words(word_tokenize(text))

for i in finder.score_ngrams(trigram_measures.pmi):
    print i
Run Code Online (Sandbox Code Playgroud)

python nltk collocation

12
推荐指数
1
解决办法
8121
查看次数

标签 统计

collocation ×1

nltk ×1

python ×1