NLP process for combining common collocations

只愿长相守 提交于 2019-12-05 12:06:46
Sylvia

I recently had a similar question and played around with collocations

This was the solution I chose to identify pairs of collocated words:

from nltk import word_tokenize
from nltk.collocations import *

text = <a long text read in as string string>

tokenized_text = word_tokenize(text)

bigram_measures = nltk.collocations.BigramAssocMeasures(tokenized_text)
finder = BigramCollocationFinder.from_words()
scored = finder.score_ngrams(bigram_measures.raw_freq)

sorted(scored, key=lambda s: s[1], reverse=True)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!