Package nltk :: Package wordnet
[hide private]
[frames] | no frames]

Package wordnet

source code

Wordnet interface, based on Oliver Steele's Pywordnet, together with an implementation of Ted Pedersen's Wordnet::Similarity package.

Usage

>>> from nltk.wordnet import *

Retrieve words from the database

>>> N['dog']
dog (noun)
>>> V['dog']
dog (verb)
>>> ADJ['clear']
clear (adj)
>>> ADV['clearly']
clearly (adv)

Examine a word's senses and pointers:

>>> N['dog'].synsets()
[{noun: dog, domestic_dog, Canis_familiaris}, {noun: frump, dog}, {noun: dog}, {noun: cad, bounder, blackguard, dog, hound, heel}, {noun: frank, frankfurter, hotdog, hot_dog, dog, wiener, wienerwurst, weenie}, {noun: pawl, detent, click, dog}, {noun: andiron, firedog, dog, dog-iron}]
('dog' in {noun: dog, domestic dog, Canis familiaris}, 'dog' in {noun: frump, dog}, 'dog' in {noun: dog}, 'dog' in {noun: cad, bounder, blackguard, dog, hound, heel}, 'dog' in {noun: frank, frankfurter, hotdog, hot dog, dog, wiener, wienerwurst, weenie}, 'dog' in {noun: pawl, detent, click, dog}, 'dog' in {noun: andiron, firedog, dog, dog-iron})

Extract the first sense:

>>> N['dog'][0]
{noun: dog, domestic_dog, Canis_familiaris}

Get the first five pointers (relationships) from dog to other synsets:

>>> N['dog'][0].relations()
{'hypernym': [('noun', 2083346, 0), ('noun', 1317541, 0)],
 'part holonym': [('noun', 2158846, 0)],
 'member meronym': [('noun', 2083863, 0), ('noun', 7994941, 0)],
 'hyponym': [('noun', 1322604, 0), ('noun', 2084732, 0), ...]}

Get those synsets of which 'dog' is a member meronym:

>>> N['dog'][0][MEMBER_MERONYM]
[{noun: Canis, genus Canis}, {noun: pack}]
Submodules [hide private]

Variables [hide private]
  abbreviations = 'adverb adv adv. r'
  pos = 'adv'
  token = 'r'
  tokens = ['adverb', 'adv', 'adv.', 'r']