Skip to content

Commit 537f814

Browse files
committed
Document how to reproduce old Wordnet studies
1 parent 40eceae commit 537f814

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

nltk/corpus/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,14 @@
395395
WordNetCorpusReader,
396396
LazyCorpusLoader("omw-1.4", CorpusReader, r".*/wn-data-.*\.tab", encoding="utf8"),
397397
)
398+
## Use the following template to add a custom Wordnet package.
399+
## Just uncomment, and replace the identifier (my_wordnet) in two places:
400+
##
401+
# my_wordnet: WordNetCorpusReader = LazyCorpusLoader(
402+
# "my_wordnet",
403+
# WordNetCorpusReader,
404+
# LazyCorpusLoader("omw-1.4", CorpusReader, r".*/wn-data-.*\.tab", encoding="utf8"),
405+
# )
398406
wordnet31: WordNetCorpusReader = LazyCorpusLoader(
399407
"wordnet31",
400408
WordNetCorpusReader,

nltk/test/wordnet.doctest

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,48 @@ Loading alternative Wordnet versions
816816
[Synset('baffle.v.03'), Synset('confine.v.02'), Synset('control.v.02'), Synset('hold.v.36'), Synset('rule.v.07'), Synset('swallow.v.06'), Synset('wink.v.04')]
817817

818818

819+
-------------------------------------------
820+
Reproduce old Wordnet results (issue #3377)
821+
-------------------------------------------
822+
823+
Normally, only small edits are necessary for NLTK to load any
824+
Wordnet in the original Princeton WordNet wndb format. This could
825+
for ex. be a Princeton WordNet from the 1.x or 2.x series, which
826+
were never included in NLTK, or any Open English Wordnet version.
827+
However, some older versions have problems that require more effort.
828+
829+
Let's illustrate the process with Edition 2023 of the Open English
830+
Wordnet, since nltk_data does not include it.
831+
832+
1. Get the data package. The 2023 Edition is at
833+
https://en-word.net/static/english-wordnet-2023.zip
834+
835+
2. Rename the package to oewn2023.zip and copy it to the corpora
836+
subdirectory of your nltk_data directory.
837+
838+
Renaming the package is necessary because english-wordnet-2023.zip
839+
creates an oewn2023 subdirectory, while NLTK expects the data package
840+
to have the same name as the subdirectory. Alternatively, you can
841+
eliminate the need for renaming the package, by just unzipping it
842+
so that you have a nltk_data/corpora/oewn2023 directory.
843+
844+
3. Add an entry in nltk/corpus/\_\_init\_\_.py. That file includes
845+
a commented template showing how to do it easily: you just copy one
846+
of the existing Wordnet entries, and edit the name in two places:
847+
848+
oewn2023: WordNetCorpusReader = LazyCorpusLoader(
849+
"oewn2023",
850+
WordNetCorpusReader,
851+
LazyCorpusLoader("omw-1.4", CorpusReader, r".*/wn-data-.*\.tab", encoding="utf8"),
852+
)
853+
854+
4. Enjoy:
855+
856+
from nltk.corpus import oewn2023 as ewn
857+
print(ewn.get_version())
858+
print(ewn.lemmas('book')[0])
859+
860+
819861
-------------
820862
Teardown test
821863
-------------

0 commit comments

Comments
 (0)