`
yuanlanxiaup
  • 浏览: 861275 次
文章分类
社区版块
存档分类
最新评论

WordNet介绍和使用

 
阅读更多

Wordnet是一个词典。每个词语(word)可能有多个不同的语义,对应不同的sense。而每个不同的语义(sense)又可能对应多个词,如topicsubject在某些情况下是同义的,一个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中,printpublish都是lemmaSense 1括号内的数字39表示publishsense 1在某外部语料中出现的次数。显然,publish大多数时候以sense 1出现,很少以sense 3出现。

WordNet的具体用法

NLTKpython的一个自然语言处理工具,其中提供了访问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'),

……]

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics