我一直在网上研究不同的来源,并尝试了各种方法,但只能找到如何计算独特单词的频率而不是唯一的短语.我到目前为止的代码如下:
import collections
import re
wanted = set(['inflation', 'gold', 'bank'])
cnt = collections.Counter()
words = re.findall('\w+', open('02.2003.BenBernanke.txt').read().lower())
for word in words:
if word in wanted:
cnt [word] += 1
print (cnt)
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我还想计算本文中使用短语"中央银行"和"高通胀"的次数.我感谢您给出的任何建议或指导.