zoukankan      html  css  js  c++  java
  • 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')'
    
  • 相关阅读:
    MSSQL 基础知识001
    MSSQL 数据库性能优化
    MVC4 AspNet MVC下的Ajax / 使用微软提供的Ajax请求脚本 [jquery.unobtrusive-ajax.min.js]
    MVC4 AspNet MVC下的Ajax / 使用JQuery做相关的Ajax请求
    java8 list统计(求和、最大、最小、平均)
    ideaVim
    FastJson
    linux自定义快捷键
    使用自定义注解和策略模式去掉if-else
    责任链模式
  • 原文地址:https://www.cnblogs.com/peng8098/p/nlp_13.html
Copyright © 2011-2022 走看看