Package nltk_lite :: Package wordnet :: Module wordnet
[hide private]
[frames] | no frames]

Module wordnet

source code

Classes [hide private]
  Word
  Synset
A set of synonyms.
  Dictionary
A Dictionary contains all the Words in a given part of speech.
Functions [hide private]
 
dictionaryFor(pos)
Return the dictionary for the supplied part of speech.
source code
 
getWord(form, pos=NOUN)
Return a word with the given lexical form and pos.
source code
 
getSense(form, pos=NOUN, senseno=0)
Lookup a sense by its sense number.
source code
 
getSynset(pos, offset)
Lookup a synset by its offset.
source code
 
_check_datafile(datafile) source code
 
_load_ic_data(filename)
Load in some precomputed frequency distribution data from a file.
source code
 
_index(key, sequence, testfn=None, keyfn=None)
Return the index of key within sequence, using testfn for comparison and transforming items of sequence by keyfn first.
source code
 
_partition(sequence, size, count)
Partition sequence into count subsequences of length size, and a remainder.
source code
 
_compareInstances(a, b, fields)
Return -1, 0, or 1 according to a comparison first by type, then by class, and finally by each of fields.
source code
 
_equalsIgnoreCase(a, b)
Return true iff a and b have the same lowercase representation.
source code
 
demo() source code
Variables [hide private]
  N = Dictionary(NOUN, NOUN)
  V = Dictionary(VERB, VERB)
  ADJ = Dictionary(ADJECTIVE, ADJECTIVE)
  ADV = Dictionary(ADVERB, ADVERB)
  Dictionaries = {NOUN: N, VERB: V, ADJECTIVE: ADJ, ADVERB: ADV}
  _RELATION_TABLE = {'!': ANTONYM, '@': HYPERNYM, '~': HYPONYM, ...
Function Details [hide private]

dictionaryFor(pos)

source code 

Return the dictionary for the supplied part of speech.

Parameters:
  • pos (string) - The part of speech of the desired dictionary.
Returns:
The desired dictionary.

getWord(form, pos=NOUN)

source code 

Return a word with the given lexical form and pos.

Parameters:
  • form (string) - the sought-after word string e.g. 'dog'
  • pos (string) - the desired part of speech. Defaults to 'noun'.
Returns:
the Word object corresponding to form and pos, if it exists.

getSense(form, pos=NOUN, senseno=0)

source code 

Lookup a sense by its sense number. Used by repr(sense).

Parameters:
  • form (string) - the sought-after word string e.g. 'dog'
  • pos (string) - the desired part of speech. Defaults to 'noun'.
  • senseno (int) - the id of the desired word sense. Defaults to 0.
Returns:
the Sense object corresponding to form, pos and senseno, if it exists.

getSynset(pos, offset)

source code 

Lookup a synset by its offset.

Parameters:
  • pos (string) - the desired part of speech.
  • offset (int) - the offset into the relevant Wordnet dictionary file.
Returns:
the Synset object extracted from the Wordnet dictionary file.

_load_ic_data(filename)

source code 

Load in some precomputed frequency distribution data from a file. It is expected that this data has been stored as two pickled dicts.

TODO: Possibly place the dicts into a global variable or something so that they don't have to be repeatedly loaded from disk.

_index(key, sequence, testfn=None, keyfn=None)

source code 

Return the index of key within sequence, using testfn for comparison and transforming items of sequence by keyfn first.

>>> _index('e', 'hello')
1
>>> _index('E', 'hello', testfn=_equalsIgnoreCase)
1
>>> _index('x', 'hello')

_partition(sequence, size, count)

source code 

Partition sequence into count subsequences of length size, and a remainder.

Return (partitions, remainder), where partitions is a sequence of count subsequences of cardinality size, and apply(append, partitions) + remainder == sequence.

_compareInstances(a, b, fields)

source code 

Return -1, 0, or 1 according to a comparison first by type, then by class, and finally by each of fields. Used when comparing two Wordnet objects (Synsets, Words, or Senses) to each other.

_equalsIgnoreCase(a, b)

source code 

Return true iff a and b have the same lowercase representation.

>>> _equalsIgnoreCase('dog', 'Dog')
1
>>> _equalsIgnoreCase('dOg', 'DOG')
1

Variables Details [hide private]

_RELATION_TABLE

Value:
{'!': ANTONYM, '@': HYPERNYM, '~': HYPONYM, '=': ATTRIBUTE, '^': ALSO_\
SEE, '*': ENTAILMENT, '>': CAUSE, '$': VERB_GROUP, '#m': MEMBER_MERONY\
M, '#s': SUBSTANCE_MERONYM, '#p': PART_MERONYM, '%m': MEMBER_HOLONYM, \
'%s': SUBSTANCE_HOLONYM, '%p': PART_HOLONYM, '&': SIMILAR, '<': PARTIC\
IPLE_OF, '\\': PERTAINYM, '+': FRAMES, ';c': CLASSIF_CATEGORY, ';u': C\
LASSIF_USAGE, ';r': CLASSIF_REGIONAL, '-c': CLASS_CATEGORY, '-u': CLAS\
S_USAGE, '-r': CLASS_REGIONAL, '@i': INSTANCE_HYPERNYM, '~i': INSTANCE\
_HYPONYM,}