INNER CODE UNIT · Python
_get_analyzer
meetbryce/open-source-slack-ai · ossai/sentiment.py:10
def _get_analyzer():
"""Lazy initialization of VADER sentiment analyzer with error handling"""
global _sia
if _sia is None:
with _lock:
if _sia is None: # Double-check lock
try:
# Try to initialize the analyzer
_sia = SentimentIntensityAnalyzer()
except LookupError:
# If VADER lexicon is not found, download it
logger.info("VADER lexicon not found, downloading...")
try:
nltk.download("vader_lexicon", quiet=True)
_sia = SentimentIntensityAnalyzer()
logger.info("VADER lexicon downloaded successfully")
except Exception as e:
logger.error(f"Failed to download VADER lexicon: {e}")