WordNet介紹和使用

來源:互聯網
上載者:User

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'),……]

轉載:http://blog.csdn.net/ictextr9/article/details/4008703

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.