标签:
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
标签:
原文地址:http://www.cnblogs.com/itdyb/p/5914522.html