Introduction and use of WordNet

Source: Internet
Author: User
Tags nltk

WordNet is a dictionary. Each word may have multiple different semantics, corresponding to different sense. Different meanings may correspond to multiple words, such as topic and subject, which are synonymous in some cases. Multiple words in a sense that eliminate ambiguity are called lemma. For example, "publish" is a word, which may have multiple sense:

1. (39) print, publish -- (put into print; "the newspaper published the news of the royal couple's divorce"; "these news shocould 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 ")

In the first sense, both print and publish are lemma. The number 39 in the brackets of sense 1 indicates the number of times that publish appears in an external corpus with sense 1. Obviously, publish usually appears with sense 1 and rarely with sense 3.

WordNet usage

Nltk is a natural language processing tool for python, which provides functions to access various WordNet functions. The following lists some common functions:

Get WordNet itself:

From nltk. Corpus import WordNet

Get all the sense of a word, including the various variants of the word:

wordnet.synsets('published')[Synset('print.v.01'), Synset('publish.v.02'), Synset('publish.v.03'), Synset('published.a.01'), Synset('promulgated.s.01')]

Get the synset part of speech:

>>> related.pos's'

Get all lemma of a sense:

>>> wordnet.synsets('publish')[0].lemmas[Lemma('print.v.01.print'), Lemma('print.v.01.publish')] 

The number of times lemma appears:

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

In WordNet, nouns and verbs are organized into a complete hierarchical classification system. Therefore, we can calculate the distance between two senses in the classification tree, which reflects their semantic similarity:

>>> x = wordnet.synsets('recommended')[-1]>>> y = wordnet.synsets('suggested')[-1]>>> x.shortest_path_distance(y)0

Calculation of similarity between adjectives and adverbs:

Adjectives and adverbs are not organized into classification systems, so path_distance cannot be used.

>>> a = wordnet.synsets('beautiful')[0]>>> b = wordnet.synsets('good')[0]>>> a.shortest_path_distance(b)-1

The most useful relationship between adjectives and adverbs is similar.

>>> a = wordnet.synsets('glorious')[0]>>> a.similar_tos()[Synset('incandescent.s.02'), Synset('divine.s.06'),……]

Reprinted: http://blog.csdn.net/ictextr9/article/details/4008703

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.