我发现一些词在布朗语料库的不同类型中的频率分布。
我的守则:
import nltk
from nltk.corpus import brown
cfd = nltk.ConditionalFreqDist(
(genre, word)
for genre in brown.categories()
for word in brown.words(categories = genre))
genres = ['news', 'religion', 'hobbies', 'science_fiction', 'romance', 'humor']
modals = ['can', 'could', 'may', 'might', 'must', 'will']
cfd.tabulate(conditions = genres, samples = modals)上述代码的输出:
can could may might must will
news 93 86 66 38 50 389
religion 82 59 78 12 54 71
hobbies 268 58 131 22 83 264
science_fiction 16 49 4 12 8 16
romance 74 193 11 51 45 43
humor 16 30 8 8 9 13 但是,当我在上面代码的最后一行中用'sample‘替换’sample‘时。它为语料库中的每个单词提供FreqDist。
我不知道“样本”和“样本”有什么区别?
谢谢你。
发布于 2016-05-23 07:07:00
cfd.tabulate()只是忽略了它的实现中没有引用的任何关键字参数。这就是为什么sample=models仍然为FreqDist生成一个完整的表的原因。如果你完全忽略了它,效果应该是一样的。
这种行为不是特定于NLTK的,但是对于任何接受任意参数列表的Python函数/方法都适用。关于这一点,我建议阅读Python教程部分,我发现它非常清楚。
https://stackoverflow.com/questions/37323594
复制相似问题