码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-09-27 23:10:56      阅读:388      评论:0      收藏:0      [点我收藏+]

标签:

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 自然语言处理第二章 部分习题

标签:

原文地址:http://www.cnblogs.com/itdyb/p/5914522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!