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

Class Synset

source code

object --+
         |
        Synset

A set of synonyms.

Each synset contains one or more Senses, which represent a specific sense of a specific word. Senses can be retrieved via synset.getSenses() or through the index notations synset[0], synset[string], or synset[word]. Synsets also originate zero or more typed pointers, which can be accessed via synset.getPointers() or synset.getPointers(pointerType). The targets of a synset pointer can be retrieved via synset.getPointerTargets() or synset.getPointerTargets(pointerType), which are equivalent to map(Pointer.getTarget(), synset.getPointerTargets(...)).

>>> from nltk_lite.wordnet import *
>>> V['think'][0].synset.verbFrames
(5, 9)
Instance Methods [hide private]
 
__init__(self, pos, offset, line)
Initialize the Synset from a line in a WordNet synset file.
source code
 
extractVerbFrameStrings(self, vfTuples)
Return a list of verb frame strings for this synset.
source code
 
relations(self)
Return a dictionary of synsets
source code
 
relation(self, rel) source code
 
isTagged(self) source code
 
__str__(self)
Return a human-readable representation.
source code
 
__repr__(self)
repr(x)
source code
 
__cmp__(self, other) source code
 
__eq__(self, other) source code
 
__getitem__(self, idx) source code
 
__iter__(self) source code
 
__contains__(self, item) source code
 
__getslice__(self, i, j) source code
 
__nonzero__(self) source code
 
__len__(self) source code
 
max_depth(self)
Returns: The length of the longest hypernym path from this synset to the root.
source code
 
min_depth(self)
Returns: The length of the shortest hypernym path from this synset to the root.
source code
 
closure(self, rel, depth=-1)
Return the transitive closure of source under the rel relationship, breadth-first
source code
 
hypernym_paths(self)
Get the path(s) from this synset to the root, where each path is a list of the synset nodes traversed on the way to the root.
source code
 
hypernym_distances(self, distance, verbose=False)
Get the path(s) from this synset to the root, counting the distance of each node from the initial node on the way.
source code
 
shortest_path_distance(self, other)
Returns the distance of the shortest path linking the two synsets (if one exists).
source code
 
information_content(self, freq_data)
Get the Information Content value of this Synset, using the supplied dict 'freq_data'.
source code
 
tree(self, rel, depth=-1) source code
 
path_similarity(self, other, verbose=False) source code
 
lch_similarity(self, other, verbose=False) source code
 
wup_similarity(self, other, verbose=False) source code
 
res_similarity(self, other, datafile="", verbose=False) source code
 
jcn_similarity(self, other, datafile="", verbose=False) source code
 
lin_similarity(self, other, datafile="", verbose=False) source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, pos, offset, line)
(Constructor)

source code 

Initialize the Synset from a line in a WordNet synset file.

Parameters:
  • pos (string) - The part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB.
  • offset (int) - An integer offset into the part-of-speech file. Together with pos, this can be used as a unique id.
  • gloss (string) - A gloss (dictionary definition) for the sense.
  • verbFrames (list of integer) - A sequence of integers that index into VERB_FRAME_STRINGS. These list the verb frames that any Sense in this synset participates in. (See also Sense.verbFrames.) Defined only for verbs.
Overrides: object.__init__

relations(self)

source code 

Return a dictionary of synsets

If pointerType is specified, only pointers of that type are returned. In this case, pointerType should be an element of POINTER_TYPES.

Returns:
relations defined on this Synset.

isTagged(self)

source code 
>>> from nltk_lite.wordnet import *
>>> N['dog'][0].isTagged()
1
>>> N['dog'][1].isTagged()
0
Returns:
True/false (1/0) if one of this Word's senses is tagged.

__str__(self)
(Informal representation operator)

source code 

Return a human-readable representation.

>>> from nltk_lite.wordnet import *
>>> str(N['dog'][0].synset)
'{noun: dog, domestic dog, Canis familiaris}'
Overrides: object.__str__

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

max_depth(self)

source code 
Returns:
The length of the longest hypernym path from this synset to the root.

min_depth(self)

source code 
Returns:
The length of the shortest hypernym path from this synset to the root.

closure(self, rel, depth=-1)

source code 

Return the transitive closure of source under the rel relationship, breadth-first

>>> dog = N['dog'][0]
>>> dog.closure(HYPERNYM)
[{noun: dog, domestic dog, Canis familiaris}, {noun: canine, canid}, {noun: carnivore}, {noun: placental, placental mammal, eutherian, eutherian mammal}, {noun: mammal, mammalian}, {noun: vertebrate, craniate}, {noun: chordate}, {noun: animal, animate being, beast, brute, creature, fauna}, {noun: organism, being}, {noun: living thing, animate thing}, {noun: object, physical object}, {noun: physical entity}, {noun: entity}]

hypernym_paths(self)

source code 

Get the path(s) from this synset to the root, where each path is a list of the synset nodes traversed on the way to the root.

Returns:
A list of lists, where each list gives the node sequence connecting the initial Synset node and a root node.

hypernym_distances(self, distance, verbose=False)

source code 

Get the path(s) from this synset to the root, counting the distance of each node from the initial node on the way. A list of (synset, distance) tuples is returned.

Parameters:
  • distance (int) - the distance (number of edges) from this hypernym to the original hypernym Synset on which this method was called.
Returns:
A list of (Synset, int) tuples where each Synset is a hypernym of the first Synset.

shortest_path_distance(self, other)

source code 

Returns the distance of the shortest path linking the two synsets (if one exists). For each synset, all the ancestor nodes and their distances are recorded and compared. The ancestor node common to both synsets that can be reached with the minimum number of traversals is used. If no ancestor nodes are common, -1 is returned. If a node is compared with itself 0 is returned.

Parameters:
  • other (Synset) - The Synset to which the shortest path will be found.
Returns:
The number of edges in the shortest path connecting the two nodes, or -1 if no path exists.

information_content(self, freq_data)

source code 

Get the Information Content value of this Synset, using the supplied dict 'freq_data'.

Parameters:
  • freq_data (dict) - Dictionary mapping synset identifiers (offsets) to a tuple containing the frequency count of the synset, and the frequency count of the root synset.
Returns:
The IC value of this Synset, or -1 if no IC value can be computed.