diff --git a/rake_nltk/rake.py b/rake_nltk/rake.py index 53f5b9d..8a36c8b 100644 --- a/rake_nltk/rake.py +++ b/rake_nltk/rake.py @@ -53,7 +53,11 @@ def __init__( # If stopwords not provided we use language stopwords by default. self.stopwords = stopwords if self.stopwords is None: - self.stopwords = nltk.corpus.stopwords.words(language) + try: + self.stopwords = nltk.corpus.stopwords.words(language) + except LookupError: + nltk.download('stopwords') + self.stopwords = nltk.corpus.stopwords.words(language) # If punctuations are not provided we ignore all punctuation symbols. self.punctuations = punctuations @@ -78,7 +82,11 @@ def extract_keywords_from_text(self, text): :param text: Text to extract keywords from, provided as a string. """ - sentences = nltk.tokenize.sent_tokenize(text) + try: + sentences = nltk.tokenize.sent_tokenize(text) + except LookupError: + nltk.download('punkt') + sentences = nltk.tokenize.sent_tokenize(text) self.extract_keywords_from_sentences(sentences) def extract_keywords_from_sentences(self, sentences): diff --git a/setup.py b/setup.py index 8d24245..e3b4a30 100644 --- a/setup.py +++ b/setup.py @@ -12,30 +12,6 @@ long_description = f.read() -def _post_install(): - """Post installation nltk corpus downloads.""" - import nltk - - nltk.download("punkt") - nltk.download("stopwords") - - -class PostDevelop(develop): - """Post-installation for development mode.""" - - def run(self): - develop.run(self) - self.execute(_post_install, [], msg="Running post installation tasks") - - -class PostInstall(install): - """Post-installation for production mode.""" - - def run(self): - install.run(self) - self.execute(_post_install, [], msg="Running post installation tasks") - - # Get package and author details. about = {} with open(path.join(here, "rake_nltk", "__version__.py")) as f: @@ -77,6 +53,5 @@ def run(self): "Topic :: Software Development :: Build Tools", "Topic :: Software Development :: Libraries :: Python Modules", ], - install_requires=["nltk"], - cmdclass={"develop": PostDevelop, "install": PostInstall}, + install_requires=["nltk"] )