nltk/nltk — Issue #52: Alter synset.tree to handle potential cycles.
Author: alexrudnick
Created: 2012-01-17 06:24:54+00:00
State: open

In nltk.corpus.wordnet the Synset class implements a method called tree
that can take a function that helps generate a tree given a synset.

This is used by the WordNet Browser to create hypernym inheritance trees,
however the wordnet data may contain cycles. Cycles may also be present if
a user passes some function that may result in cycles.

Migrated from http://code.google.com/p/nltk/issues/detail?id=257

earlier comments

StevenBird1 said, at 2009-02-05T01:47:07.000Z:

cf issue 99

steven.bethard said, at 2011-04-04T09:14:38.000Z:

Can you give an example of where this is failing? For example, I know there's a restrain.v.01 -> inhibit.v.04 -> restrain.v.01 cycle in the online Wordnet 3.0, but I don't see any problem currently with that:

>>> from nltk.corpus import wordnet as wn
>>> wn.synset('restrain.v.01').tree(lambda s: s.hypernyms())
[Synset('restrain.v.01'), [Synset('inhibit.v.04'), [Synset('suppress.v.04'), [Synset('forget.v.01')]]]]

I also tried running through all the WordNet synsets, but it didn't seem to get stuck in an infinite loop or anything:

>>> for s in wn.all_synsets():
>>> s.tree(lambda s: s.hypernyms())

Perhaps this was fixed when r6952 was reverted?