ntlk入门函数

#from nltk.book import *; #导入NTLK包中book中的所有的例子模型

#print(text1); #输出book中text1的相关信息

#text1.concordance(“monstrous”); #在text1中找到特定单词并显示出上下文
#print(“monstrous in text1 similar to”);
#text1.similar(“monstrous”); #在text1找到用法、意义与该单词相似的词
#print();

#print(“monstrous in text2 similar to”);
#text2.similar(“monstrous”); #在text2找到用法、意义与该单词相似的词
#print();

#text2.common_contexts([“monstrous”, “very”]); #在text2找到用法、意义与该单词集合相似的词
#print();

#print(len(text3)); #显示text3长度
#print();

#print(sorted(set(text3))); #筛选出text3中所有单词和字符(不重复)并按照字母顺序排序
#print(len(set(text3))); #测定text3中出现的单词和字符数(不重复)

‘’’
from future import division;
from nltk.book import text3;
a = 1.0 * len(text3) / len(set(text3));
print(a);
‘’’

from future import division;
from nltk.book import *;

def lexical_diversity(text):
return len(text) / len(set(text)); #建立函数测算某个文本中所有单词出现的平均次数

def percentage(count, total):
return 100 * count / total; #建立函数测算某个单词在某个文本中所占的百分比

print(lexical_diversity(text3));
print(percentage(text4.count(“a”), len(text4)));

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值