我有一个客户评论列表,我必须使用正则表达式(regex)将它们分类为正面或负面。
这是一个客户评论的例子,一个积极关键词和消极关键词的列表。
review="I absolutely loved this product! Loving it!"
positive_keyword= ['loved','outstanding', 'exceeded']
negative_keyword= ['hated','not good', 'bad']
上面的示例评论将被分类为积极的,因为出现了“loved”,它存在于positive_keyword列表中。我希望定义一个函数,它将根据列表中任何关键字的出现,使用正则表达式将评论分类为正面或负面。
def sentiment(review, positive_keyword, negative_keyword):
我该怎么做?
2条答案
按热度按时间mfpqipee1#
你可以试试这样的东西:
ia2d9nvy2#