preprocess function order changed

This commit is contained in:
Grégoire Mureau 2025-07-16 11:47:34 +02:00
parent 4e23a08f74
commit a47fe40b78

View file

@ -65,6 +65,9 @@ def preprocess_tweet(tweet):
if not isinstance(tweet, str): if not isinstance(tweet, str):
return "" return ""
# Decode HTML entities (e.g., & to &)
tweet = html.unescape(tweet)
# Convert to lowercase # Convert to lowercase
tweet = tweet.lower() tweet = tweet.lower()
@ -77,9 +80,6 @@ def preprocess_tweet(tweet):
# Separate hashtags from words to facilitate tokenization # Separate hashtags from words to facilitate tokenization
tweet = re.sub(r'#(\w+)', r'# \1', tweet) tweet = re.sub(r'#(\w+)', r'# \1', tweet)
# Decode HTML entities (e.g., & to &)
tweet = html.unescape(tweet)
# Remove unwanted punctuation and special characters except some useful ones # Remove unwanted punctuation and special characters except some useful ones
tweet = re.sub(r'[^\w\s<>@#!?]', '', tweet) tweet = re.sub(r'[^\w\s<>@#!?]', '', tweet)