fix: [SentimentAnalysis] download nltk punkt

This commit is contained in:
Terrtia 2020-02-10 11:04:24 +01:00
parent cf24c59e1d
commit 4097d95237
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0

View file

@ -30,7 +30,7 @@ sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib/'))
import ConfigLoader import ConfigLoader
from nltk.sentiment.vader import SentimentIntensityAnalyzer from nltk.sentiment.vader import SentimentIntensityAnalyzer
from nltk import tokenize from nltk import tokenize, download
# Config Variables # Config Variables
accepted_Mime_type = ['text/plain'] accepted_Mime_type = ['text/plain']
@ -62,6 +62,11 @@ def Analyse(message, server):
combined_datetime = datetime.datetime.combine(the_date, the_time) combined_datetime = datetime.datetime.combine(the_date, the_time)
timestamp = calendar.timegm(combined_datetime.timetuple()) timestamp = calendar.timegm(combined_datetime.timetuple())
try:
sentences = tokenize.sent_tokenize(p_content)
except Exception as e:
# use the NLTK Downloader to obtain the resource
download('punkt')
sentences = tokenize.sent_tokenize(p_content) sentences = tokenize.sent_tokenize(p_content)
if len(sentences) > 0: if len(sentences) > 0: