NLP(十三) 词义消歧

  • 一个词可能有多个词义
例句解释
She is my datedate: 约会,日期
You have taken too many leaves to skip cleaning leaves in the gardenleave:休息,树叶

用Lesk算法

  • 代码
import nltk

def understandWordSenseExamples():
    words = ['wind','date','left']
    print('-- examples --')
    for word in words:
        syns = nltk.corpus.wordnet.synsets(word)
        for syn in syns[:2]:
            for example in syn.examples()[:2]:
                print('{} -> {} -> {}'.format(word,syn.name(),example))
                # 打印 : 单词 -> 同义词集 -> 例句

def understandBuiltinWSD():
    print('-- built-in wsd --')
    maps = [
        ('It is the fish net that you are using to catch fish ?','fish','n'),
        ('Please dont point your finger at others.','point','n'),
        ('I went to the river bank to see the sun rise','bank','n'),
    ]
    for m in maps:
        print("Sense '{}' for '{}' -> '{}'".format(m[0],m[1],nltk.wsd.lesk(m[0],m[1],m[2])))

if __name__ == "__main__":
    understandWordSenseExamples()
    understandBuiltinWSD()

输出:

-- examples --
wind -> wind.n.01 -> trees bent under the fierce winds
wind -> wind.n.01 -> when there is no wind, row
wind -> wind.n.02 -> the winds of change
date -> date.n.01 -> what is the date today?
date -> date.n.02 -> his date never stopped talking
left -> left.n.01 -> she stood on the left
-- built-in wsd --
Sense 'It is the fish net that you are using to catch fish ?' for 'fish' -> 'Synset('pisces.n.02')'
Sense 'Please dont point your finger at others.' for 'point' -> 'Synset('point.n.25')'
Sense 'I went to the river bank to see the sun rise' for 'bank' -> 'Synset('savings_bank.n.02')'

转载于:https://www.cnblogs.com/peng8098/p/nlp_13.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值