• NLP(十三) 词义消歧


    原文链接: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')'
    
  • 相关阅读:
    sql FLOAT字段使用like查询
    关于sql--时间范围查询重叠
    关于java时间类型比较
    前端-搜索无结果时,怎么把“暂无数据“显示出来?
    v-for动态赋值给不同的下拉框input
    Java的优先队列PriorityQueue详解
    软件体系架构阅读笔记八
    字符数组和字符串之间的转换
    Java快速输入输出
    软件体系架构阅读笔记七
  • 原文地址:https://www.cnblogs.com/peng8098/p/nlp_13.html
Copyright © 2020-2023  润新知