Migrating from the NLTK¶
This guide is for users of the NLTK's
nltk.corpus.wordnet
module who are migrating to Wn. It is not
guaranteed that Wn will produce the same results as the NLTK's module,
but with some care its behavior can be very similar.
Overview¶
One important thing to note is that Wn will search all wordnets in the database by default where the NLTK would only search the English.
>>> from nltk.corpus import wordnet as nltk_wn
>>> nltk_wn.synsets('chat') # only English
>>> nltk_wn.synsets('chat', lang='fra') # only French
>>> import wn
>>> wn.synsets('chat') # all wordnets
>>> wn.synsets('chat', lang='fr') # only French
With Wn it helps to create a wn.Wordnet
object to pre-filter
the results by language or lexicon.
>>> en = wn.Wordnet('omw-en:1.4')
>>> en.synsets('chat') # only the OMW English Wordnet
Equivalent Operations¶
The following table lists equivalent API calls for the NLTK's wordnet module and Wn assuming the respective modules have been instantiated (in separate Python sessions) as follows:
NLTK:
>>> from nltk.corpus import wordnet as wn
>>> ss = wn.synsets("chat", pos="v")[0]
Wn:
>>> import wn
>>> en = wn.Wordnet('omw-en:1.4')
>>> ss = en.synsets("chat", pos="v")[0]
Primary Queries¶
NLTK |
Wn |
---|---|
|
|
|
– |
– |
|
– |
|
|
|
|
|
|
|
|
|
Synsets – Basic¶
NLTK |
Wn |
---|---|
|
– |
– |
|
– |
|
|
|
|
|
|
|
|
|
Synsets – Relations¶
NLTK |
Wn |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Synsets – Taxonomic Structure¶
NLTK |
Wn |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
(these tables are incomplete)