Skip to content

Commit d6f337a

Browse files
authored
tableau#467 Update SentimentAnalysis.py
Allow to modify the NLTK download path and proxy settings via the tabpy config file.
1 parent 5ba21d0 commit d6f337a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tabpy/models/scripts/SentimentAnalysis.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from textblob import TextBlob
23
import nltk
34
from nltk.sentiment.vader import SentimentIntensityAnalyzer
@@ -10,8 +11,18 @@
1011
ssl._create_default_https_context = _ctx
1112

1213

13-
nltk.download("vader_lexicon")
14-
nltk.download("punkt")
14+
def setup():
15+
file_path = sys.argv[1] if len(sys.argv) > 1 else setup_utils.get_default_config_file_path()
16+
config = setup_utils.get_config(file_path)
17+
download_dir = None
18+
if "nltk" in config:
19+
nltk_config = config["nltk"]
20+
download_dir = nltk_config.get("NLTK_DOWNLOAD_PATH")
21+
if "NLTK_PROXY" in nltk_config:
22+
nltk.set_proxy(nltk_config["NLTK_PROXY"])
23+
24+
nltk.download("vader_lexicon", download_dir=download_dir)
25+
nltk.download("punkt", download_dir=download_dir)
1526

1627

1728
def SentimentAnalysis(_arg1, library="nltk"):
@@ -45,6 +56,7 @@ def SentimentAnalysis(_arg1, library="nltk"):
4556

4657

4758
if __name__ == "__main__":
59+
setup()
4860
setup_utils.deploy_model(
4961
"Sentiment Analysis",
5062
SentimentAnalysis,

0 commit comments

Comments
 (0)