我正在尝试使用引理来计算每个说话者的整个词汇中的Capitol Words语料库的TTR。
我也试图通过defaultdict
随机播放每个条目,然后为每个发言者提供TTR百分比。到目前为止,我有上面的代码,但不知道如何解决它,所以它的工作原理......
import nltk
cw = ReadCorpus(root)
from collections import defaultdict
speaker_TTR = defaultdict(int)
for record in cw:
total_words = set([])
N = 0
text = record['text']
processed = nlp(text)
textw = [t.lemma_ for t in processed]
N += len(textw)
total_words |= set(textw)
V = len(total_types)
TTR = float(V)/float(N)
speaker_TTR[record['speaker_name']] += 1
print "V = ",V
print "N = ",N
print "TTR = ",TTR