小写化
您正在分析某旅游网站的用户评论。这些评论常常大小写不一致,如 "TRAVEL" 和 "travel"。为便于后续情感分析和主题提取,您将先把所有词转换为小写,然后进行分词,并清理掉停用词和标点符号。
已为您提供 word_tokenize() 函数和 stop_words 列表。NLTK 资源已下载完成。
本练习是课程的一部分
Python 中的自然语言处理(NLP)
练习说明
- 将提供的
review转换为小写。 - 将
lower_text按词进行分词。 - 使用列表推导式结合
stop_words和string.punctuation列表移除停用词和标点符号。
交互式实操练习
通过完成这段示例代码来试试这个练习。
review = "I have been FLYING a lot lately and the Flights just keep getting DELAYED. Honestly, traveling for WORK gets exhausting with endless delays, but every trip teaches you something new!"
# Lowercase the review
lower_text = ____
# Tokenize the lower_text into words
tokens = ____
# Remove stop words and punctuation
clean_tokens = [____ if word ____ and word ____]
print(clean_tokens)