python 自然语言处理第二章 部分习题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 自然语言处理第二章 部分习题相关的知识,希望对你有一定的参考价值。

T4:使用state_union预料库,访问《国情咨文报告》文本。统计women,men,people随时间推移变化情况

# # from nltk.corpus import brown as bn 
# # from nltk.corpus import state_union as su 
# # cfd=nltk.ConditionalFreqDist((target,fileid[:4]) for fileid in su.fileids() for w in su.words(fileid) 
# # 							for target in [‘men‘,‘women‘,‘people‘] if w.lower().startswith(target))

# # cfd.plot()

 

T13。没有下位词的名词在同义词集中所占的百分比是多少?你可以使用wn.all_synsets(‘n‘)来得到所有名字的同义词

import nltk
from nltk.corpus import wordnet as wn
alln=wn.all_synsets(‘n‘)
total=0;sum1=0
for i in alln:
    total+=1
    hp=i.hyponyms() ###下位词
    if len(hp)==0:
           sum1+=1
print(sum1/total)

结果:0.7967119283931072

T15

以上是关于python 自然语言处理第二章 部分习题的主要内容,如果未能解决你的问题,请参考以下文章