Package nltk :: Package wordnet :: Module dictionary :: Class Dictionary
[hide private]
[frames] | no frames]

Class Dictionary

source code

object --+
         |
        Dictionary

A Dictionary contains all the Words in a given part of speech. Four dictionaries, bound to N, V, ADJ, and ADV, are bound by default in __init.py__.

Indexing a dictionary by a string retrieves the word named by that string, e.g. dict['dog']. Indexing by an integer n retrieves the nth word, e.g. dict[0]. Access by an arbitrary integer is very slow except in the special case where the words are accessed sequentially; this is to support the use of dictionaries as the range of a for statement and as the sequence argument to map and filter.

>>> N['dog']
dog(n.)
Instance Methods [hide private]
 
__init__(self, pos, filenameroot)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
load(self) source code
 
__repr__(self)
repr(x)
source code
 
getWord(*args, **kwargs) source code
 
word(self, form, line=None)
Returns: The Word object with the supplied form, if present.
source code
 
getSynset(*args, **kwargs) source code
 
synset(self, offset)
Returns: The relevant Synset, if present.
source code
 
_buildIndexCacheFile(self) source code
 
__nonzero__(self) source code
 
__len__(self)
Return the number of index entries.
source code
 
__getslice__(self, a, b) source code
 
__getitem__(self, index)
If index is a String, return the Word whose form is index.
source code
 
__iter__(self) source code
 
__contains__(self, item) source code
 
get(self, key, default=None)
Return the Word whose form is key, or default.
source code
 
keys(self)
Returns: A sorted list of strings that index words in this dictionary.
source code
 
has_key(self, form)
Checks if the supplied argument is an index into this dictionary.
source code
 
_testKeys(self) source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, pos, filenameroot)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Parameters:
  • pos (string) - This Dictionary's part of speech ('noun', 'verb' etc.)
  • filenameroot (string) - filename of the relevant Wordnet dictionary file
Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

getWord(*args, **kwargs)

source code 
Decorators:
  • @deprecated("Use Dictionary.word() instead.")

Deprecated: Use Dictionary.word() instead.

word(self, form, line=None)

source code 
Parameters:
  • form (string) - word string e.g, 'dog'
  • line (string) - appropriate line sourced from the index file (optional)
Returns:
The Word object with the supplied form, if present.

getSynset(*args, **kwargs)

source code 
Decorators:
  • @deprecated("Use Dictionary.word() instead.")

Deprecated: Use Dictionary.word() instead.

synset(self, offset)

source code 
Parameters:
  • offset (int) - integer offset into a Wordnet file, at which the desired Synset can be found.
Returns:
The relevant Synset, if present.

__len__(self)
(Length operator)

source code 

Return the number of index entries.

>>> len(ADJ)
21435

__getitem__(self, index)
(Indexing operator)

source code 

If index is a String, return the Word whose form is index. If index is an integer n, return the Word indexed by the n'th Word in the Index file.

>>> N['dog']
dog(n.)
>>> N[0]
'hood(n.)

get(self, key, default=None)

source code 

Return the Word whose form is key, or default.

>>> N.get('dog')
dog(n.)
Parameters:
  • key (string) - the string form of a Word e.g. 'dog'
  • default (Word) - An optional Word to return if no entry can be found with the supplied key.
Returns:
The Word whose form is given by 'key'

keys(self)

source code 
Returns:
A sorted list of strings that index words in this dictionary.

has_key(self, form)

source code 

Checks if the supplied argument is an index into this dictionary.

>>> N.has_key('dog')
1
>>> N.has_key('inu')
0
Parameters:
  • form (string) - a word string e.g. 'dog'
Returns:
true iff the argument indexes a word in this dictionary.