Skip to content

Commit 0ec2088

Browse files
committed
simplified exception handling code
1 parent a8ed80c commit 0ec2088

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

text_utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,15 @@ def regional_pii(text):
9494
from nltk import word_tokenize, pos_tag, ne_chunk
9595
from nltk.corpus import stopwords
9696

97+
resources = ["punkt", "maxent_ne_chunker", "stopwords", "words", "averaged_perceptron_tagger"]
98+
9799
try:
98100
nltk_resources = ["tokenizers/punkt", "chunkers/maxent_ne_chunker", "corpora/words.zip"]
99101
for resource in nltk_resources:
100102
if not nltk.data.find(resource): raise LookupError()
101103
except LookupError:
102-
nltk.download('punkt')
103-
nltk.download('maxent_ne_chunker')
104-
nltk.download('stopwords')
105-
nltk.download('words')
106-
nltk.download('averaged_perceptron_tagger')
104+
for resource in resources:
105+
nltk.download(resource)
107106

108107
stop_words = set(stopwords.words('english'))
109108

0 commit comments

Comments
 (0)