我正在尝试使用每个说话者的整个词汇表上的引理来计算 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