• WordNet介绍和使用


    Wordnet是一个词典。每个词语(word)可能有多个不同的语义,对应不同的sense。而每个不同的语义(sense)又可能对应多个词,如topic和subject在某些情况下是同义的,一个sense中的多个消除了多义性的词语叫做lemma。例如,“publish”是一个word,它可能有多个sense:

    1. (39) print, publish -- (put into print; "The newspaper published the news of the royal couple's divorce"; "These news should not be printed")

    2. (14) publish, bring out, put out, issue, release -- (prepare and issue for public distribution or sale; "publish a magazine or newspaper")

    3. (4) publish, write -- (have (one's written work) issued for publication; "How many books did Georges Simenon write?"; "She published 25 books during her long career")

    在第一个sense中,print和publish都是lemma。Sense 1括号内的数字39表示publish以sense 1在某外部语料中出现的次数。显然,publish大多数时候以sense 1出现,很少以sense 3出现。

    WordNet的具体用法

    NLTK是python的一个自然语言处理工具,其中提供了访问wordnet各种功能的函数。下面简单列举一些常用功能:

    得到wordnet本身:

    from nltk.corpus import wordnet

    获得一个词的所有sense,包括词语的各种变形的sense:

    wordnet.synsets('published')

    [Synset('print.v.01'),

     Synset('publish.v.02'),

     Synset('publish.v.03'),

     Synset('published.a.01'),

     Synset('promulgated.s.01')]

    得到synset的词性:

    >>> related.pos

    's'

    得到一个sense的所有lemma:

    >>> wordnet.synsets('publish')[0].lemmas

    [Lemma('print.v.01.print'), Lemma('print.v.01.publish')]

    得到Lemma出现的次数:

    >>> wordnet.synsets('publish')[0].lemmas[1].count()

    39

    在wordnet中,名词和动词被组织成了完整的层次式分类体系,因此可以通过计算两个sense在分类树中的距离,这个距离反应了它们的语义相似度:

    >>> x = wordnet.synsets('recommended')[-1]

    >>> y = wordnet.synsets('suggested')[-1]

    >>> x.shortest_path_distance(y)

    0

    形容词和副词的相似度计算方法:

    形容词和副词没有被组织成分类体系,所以不能用path_distance。

    >>> a = wordnet.synsets('beautiful')[0]

    >>> b = wordnet.synsets('good')[0]

    >>> a.shortest_path_distance(b)

    -1

    形容词和副词最有用的关系是similar to。

    >>> a = wordnet.synsets('glorious')[0]

    >>> a.similar_tos()

    [Synset('incandescent.s.02'),

     Synset('divine.s.06'),

    ……]

  • 相关阅读:
    3+1>4 第十次作业:Beta冲刺 Scrum meeting 4
    3+1>4 第十次作业:Beta冲刺 Scrum meeting 3
    3+1>4 第十次作业:Beta冲刺 Scrum meeting 2
    3+1>4 第十次作业:Beta冲刺 Scrum meeting 1
    实验九 团队作业5:团队项目编码与Alpha冲刺
    3+1>4 第九次作业:Alpha冲刺 Scrum meeting 7
    3+1>4 第九次作业:Alpha冲刺 Scrum meeting 6
    3+1>4 第九次作业:Alpha冲刺 Scrum meeting 5
    3+1>4 第九次作业:Alpha冲刺 Scrum meeting 4
    个人作业——软件工程实践总结&个人技术博客
  • 原文地址:https://www.cnblogs.com/wycg1984/p/1567247.html
Copyright © 2020-2023  润新知