NLTK之搜索文本的相关入门函数(一)

·搜索文本用到的相关函数

1.concordance() 函数;利用函数concordance可以显示指定单词在文本中出现情况,并显示上下文。

如下例中,查找单词monstrous

>>>from nltk.book import*
....
>>>text1.concordance("monstrous")
Building index...
Displaying 11 of 11matches:ong of former,one of a most monstrous size...This came towards us,ON OF THE PSALMS."Touching that monstrous bulk of the...."
...

2.similar()函数; 可以用来查找与指定单词意义,用法相似的词,可以 可以用在搜索引擎中的相关度识别 功能中

>>>text1.similar("monstrous")
Building word-context index...
subtly impalpable pitiable curious imperrial perilous trustworthy abundant untoward singular lamentable few maddens horrible loving lazy mystifying christan exasperate puzzled

3.common_contexts()函数 ;可以用来研究共用两个或两个以上词汇的上下文

>>>text2.common_contexts(["monstrous","very"])
be_gald am_glad a_pretty a_lucky
>>>
注:有时monstrous和very一样,作强调作用。

4.generate()函数;用于随机生成文本

>>>text3.generate()
In the beginning of his brother is a hairyman,whose top may reach  unto heaven...
>>>




注:本文中所有代码均来自《Python自然语言处理》(Steven bird,Ewan Klein&Edward Loper)


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值