fix: replace bare excepts in NLTK initialization (#896)

This commit is contained in:
KOTHA-SRIVIBHU 2026-05-11 19:41:30 +05:30 committed by GitHub
parent c2f1759bdf
commit ab02c02b33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,24 +18,26 @@ try:
except LookupError:
try:
nltk.download('punkt_tab', quiet=True)
except:
except Exception as e:
logger.warning(f"Failed to download punkt_tab: {e}. Attempting fallback to punkt.")
# Fallback to older punkt if punkt_tab not available
try:
nltk.download('punkt', quiet=True)
except:
pass
except Exception as e:
logger.error(f"Failed to download fallback punkt: {e}. NLTK data is missing.")
try:
nltk.data.find('taggers/averaged_perceptron_tagger_eng')
except LookupError:
try:
nltk.download('averaged_perceptron_tagger_eng', quiet=True)
except:
except Exception as e:
logger.warning(f"Failed to download averaged_perceptron_tagger_eng: {e}. Attempting fallback.")
# Fallback to older name
try:
nltk.download('averaged_perceptron_tagger', quiet=True)
except:
pass
except Exception as e:
logger.error(f"Failed to download fallback averaged_perceptron_tagger: {e}. NLTK data is missing.")
try:
nltk.data.find('corpora/stopwords')