Repository: nltk/nltk

Issue:
nltk 3.7 requires explicit download of omw-1.4 on Linux
Consider the following script:

```
import nltk

nltk.download("wordnet")
nltk.corpus.wordnet.synsets("test")
```

This runs successfully on both Windows and Linux for nltk version 3.5, however for version 3.7 it only succeeds for Windows and produces the following error on Linux:

> [nltk_data] Downloading package wordnet to
> [nltk_data]     [redacted]/nltk_data...
> [nltk_data]   Package wordnet is already up-to-date!
> Traceback (most recent call last):
>   File "[redacted]/.venv/lib/python3.9/site-packages/nltk/corpus/util.py", line 84, in __load
>     root = nltk.data.find(f"{self.subdir}/{zip_name}")
>   File "[redacted]/.venv/lib/python3.9/site-packages/nltk/data.py", line 583, in find
>     raise LookupError(resource_not_found)
> LookupError:
> \**********************************************************************
>   Resource omw-1.4 not found.
>   Please use the NLTK Downloader to obtain the resource:
> 
>   \>\>\> import nltk
>   \>\>\> nltk.download('omw-1.4')
> 



Discussion:
@ekaf Could you have a look at this when you have some time? I know you're familiar with `omw-1.4` and NLTK's wordnet downloading.
Yes, this problem is real. It is caused by the introduction of a "provenances" dictionary (line 1176) to handle the new omw-1.4 directory structure. Building this dictionary requires the presence of the omw-1.4 package, which was not needed in the past. The ideal would be to return to the old situation, where it was possible to load wordnet without omw. I will try to look at how to do this.

Resolving patch:
diff --git a/nltk/corpus/reader/wordnet.py b/nltk/corpus/reader/wordnet.py
--- a/nltk/corpus/reader/wordnet.py
+++ b/nltk/corpus/reader/wordnet.py
@@ -1179,9 +1179,6 @@ def __init__(self, root, omw_reader):
                 "The multilingual functions are not available with this Wordnet version"
             )
             self.omw_langs = set()
-        else:
-            self.add_provs(self._omw_reader)
-            self.omw_langs = set(self.provenances.keys())
 
         # A cache to store the wordnet data of multiple languages
         self._lang_data = defaultdict(list)
@@ -1281,6 +1278,10 @@ def _load_lang_data(self, lang):
         if lang in self._lang_data.keys():
             return
 
+        if self.langs() == ["eng"]:
+            self.add_provs(self._omw_reader)
+            self.omw_langs = set(self.provenances.keys())
+
         if lang not in self.langs():
             raise WordNetError("Language is not supported.")
 


Test patch:
diff --git a/nltk/test/wordnet.doctest b/nltk/test/wordnet.doctest
--- a/nltk/test/wordnet.doctest
+++ b/nltk/test/wordnet.doctest
@@ -45,13 +45,12 @@ A synset is identified with a 3-part name of the form: word.pos.nn:
     Synset('dog.n.01')
 
 The WordNet corpus reader gives access to the Open Multilingual
-WordNet, using ISO-639 language codes.
+WordNet, using ISO-639 language codes. These languages are not
+loaded by default, but only lazily, when needed.
+
+    >>> wn.langs()
+    ['eng']
 
-    >>> sorted(wn.langs())
-    ['als', 'arb', 'bul', 'cat', 'cmn', 'dan', 'ell', 'eng', 'eus',
-    'fin', 'fra', 'glg', 'heb', 'hrv', 'ind', 'isl', 'ita', 'ita_iwn',
-    'jpn', 'lit', 'nld', 'nno', 'nob', 'pol', 'por', 'ron', 'slk',
-    'slv', 'spa', 'swe', 'tha', 'zsm']
     >>> wn.synsets(b'\xe7\x8a\xac'.decode('utf-8'), lang='jpn')
     [Synset('dog.n.01'), Synset('spy.n.01')]
 
@@ -60,6 +59,12 @@ WordNet, using ISO-639 language codes.
     '工作員', '廻し者', '廻者', '探', '探り', '犬', '秘密捜査員',
     '諜報員', '諜者', '間者', '間諜', '隠密']
 
+    >>> sorted(wn.langs())
+    ['als', 'arb', 'bul', 'cat', 'cmn', 'dan', 'ell', 'eng', 'eus',
+    'fin', 'fra', 'glg', 'heb', 'hrv', 'ind', 'isl', 'ita', 'ita_iwn',
+    'jpn', 'lit', 'nld', 'nno', 'nob', 'pol', 'por', 'ron', 'slk',
+    'slv', 'spa', 'swe', 'tha', 'zsm']
+
     >>> wn.synset('dog.n.01').lemma_names('ita')
     ['Canis_familiaris', 'cane']
     >>> wn.lemmas('cane', lang='ita')