Skip to content

Commit

Permalink
Move nltk resources download code to Extractor class
Browse files Browse the repository at this point in the history
  • Loading branch information
somnathrakshit committed May 31, 2022
1 parent decff64 commit d9c626d
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions geograpy/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ def __init__(self, text=None, url=None, debug=False):
self.text = text
self.url = url
self.places = []
nltk_packages = ['maxent_ne_chunker',
'words',
'treebank',
'maxent_treebank_pos_tagger',
'punkt',
'averaged_perceptron_tagger'
]
for nltk_package in nltk_packages:
try:
import nltk
nltk.data.find(nltk_package)
except LookupError:
nltk.downloader.download(nltk_package, quiet=True)
import nltk

def set_text(self):
'''
Expand Down Expand Up @@ -63,20 +77,6 @@ def find_entities(self,labels=Labels.default):
list:
List of places
'''
nltk_packages = ['maxent_ne_chunker',
'words',
'treebank',
'maxent_treebank_pos_tagger',
'punkt',
'averaged_perceptron_tagger'
]
for nltk_package in nltk_packages:
try:
nltk.data.find(nltk_packages)
except LookupError:
nltk.download(nltk_package)
import nltk

self.set_text()

text = nltk.word_tokenize(self.text)
Expand Down

0 comments on commit d9c626d

Please sign in to comment.