python-3.x - 如何使用“BigramCollocationFinder”查找“Bigrams”?
问题描述
我正在使用 python 研究编译器构造,我正在尝试创建文本中所有小写单词的列表,然后生成BigramCollocationFinder
,我们可以使用它来查找双词组,它们是词对。
这些二元组是使用包中的关联测量函数找到的nltk.metrics
。
我正在练习“Python 3 Text Processing with NLTK 3 Cookbook”,我发现了这个示例代码:
from nltk.corpus import webtext
from nltk.collocations import BigramCollocationFinder
from nltk.metrics import BigramAssocMeasures
words = [w.lower() for w in webtext.words('grail.txt')]
bcf = BigramCollocationFinder.from_words(words)
bcf.nbest(BigramAssocMeasures.likelihood_ratio, 4)
我被困在:
bcf.nbest(BigramAssocMeasures.likelihood_ratio, 4)
likelihood_ratio, 4
这里它的意思是相似率或者它在这段代码中的含义。
对此问题的任何指导将不胜感激。
解决方案
我相信特定单词的 NLTK 搭配应该可以回答您的问题。它首先计算 PMI 并返回在您的语料库中出现频率最高的 4 个单词。
推荐阅读
- sql-server - 如何使用 python 通过 vpn 连接到远程 SQL Server?
- javascript - 滚动上的淡入淡出标题
- python - gspread - get_all_values() 返回一个空列表
- node.js - Passport CAS认证策略认证失败错误
- html - Angular 7+:将静态 html 文件注入组件视图的中间
- java - 如何实现,只有双击安卓手机中三个按钮中的任何一个才能退出应用程序?
- tsql - 在 TSql 中解析自定义标签
- xcode - GoogleService-Info.plist : 是否复制捆绑资源
- aws-lambda - 如何从另一个触发一个 AWS Lambda 函数,保证第二个只运行一次?
- javascript - 如何将此 Javascript 片段转换为 C#