diff --git a/summarize.py b/summarize.py index a5b56fe..d8c3a4c 100644 --- a/summarize.py +++ b/summarize.py @@ -94,7 +94,11 @@ def _content_words(sentence): """ words = [] for raw in sentence.split(): - token = _TOKEN_STRIP_RE.sub("", raw).lower() + # Optimization: bypass the heavy regex for strictly alphanumeric words + if raw.isalnum(): + token = raw.lower() + else: + token = _TOKEN_STRIP_RE.sub("", raw).lower() if token and token not in _STOPWORDS: words.append(token) return words