Package nltk :: Package wordnet :: Module synset :: 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.senses() or through the index notations synset[0], synset[string], or synset[word]. Synsets participate in lexical relations, which can be accessed via synset.relations().

>>> from nltk.wordnet import *
>>> N['dog'][0]
{noun: dog, domestic_dog, Canis_familiaris}
>>> N['dog'][0][HYPERNYM]
[{noun: canine, canid}, {noun: domestic_animal, domesticated_animal}]
>>> V['think'][0].verbFrameStrings
['Something think something Adjective/Noun', 'Somebody think somebody']
Instance Methods [hide private]
 
__init__(self, pos, offset, line)
Initialize the synset from a line in a WordNet lexicographer file.
source code
 
wordSense(self, word)
Return the WordSense object for the given word in this synset.
source code
 
extractVerbFrameStrings(self, vfTuples)
Return a list of verb frame strings for this synset.
source code
 
relations(self)
Return a dictionary of synsets, one per lexical relation
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
 
__hash__(self)
hash(x)
source code
 
__ne__(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
 
tree(self, rel, depth=-1, cut_mark=None) 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, ic, verbose=False) source code
 
jcn_similarity(self, other, ic, verbose=False) source code
 
lin_similarity(self, other, ic, verbose=False) source code

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

Instance Variables [hide private]
string gloss
A gloss (dictionary definition) for the sense.
int offset
An integer offset into the part-of-speech file.
string pos
The part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB.
list of integer verbFrames
A sequence of integers that index into VERB_FRAME_STRINGS.
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 lexicographer file.

Overrides: object.__init__

relations(self)

source code 

Return a dictionary of synsets, one per lexical relation

Returns:
relations defined on this Synset.

isTagged(self)

source code 
>>> from nltk.wordnet import *
>>> N['dog'][0].isTagged()
True
>>> N['dog'][1].isTagged()
False
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.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)

__hash__(self)
(Hashing function)

source code 

hash(x)

Overrides: object.__hash__
(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.

Instance Variable Details [hide private]

offset

An integer offset into the part-of-speech file. Together with pos, this can be used as a unique id.
Type:
int

verbFrames

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.
Type:
list of integer