原文链接:http://www.one2know.cn/nlp13/

  • 一个词可能有多个词义
例句 解释
She is my date date: 约会,日期
You have taken too many leaves to skip cleaning leaves in the garden leave:休息,树叶
用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')'

相关文章:

  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2021-04-09
  • 2021-05-27
  • 2021-08-02
  • 2021-06-12
  • 2022-12-23
猜你喜欢
  • 2019-09-25
  • 2021-10-11
  • 2021-11-01
  • 2021-10-03
  • 2021-10-15
  • 2022-01-14
相关资源
相似解决方案