Emotion from the text (positive, negative) python Example

Install :

$ pip install textblob 
from textblob import TextBlob

feedbacks = ['I dont like this app ', 
             "The experience was bad as hell", 
             "This app is really helpful and ",
             "Damn the app tastes like shit ",
            'Please don\'t download the app you will regret it ']

positive_feedbacks = []
negative_feedbacks = []

for feedback in feedbacks:
  feedback_polarity = TextBlob(feedback).sentiment.polarity
  if feedback_polarity>0:
    positive_feedbacks.append(feedback)
    continue
  negative_feedbacks.append(feedback)
  
print('Positive_feebacks Count : {}'.format(len(positive_feedbacks)))
print('positive ', positive_feedbacks)

print('')

print('Negative_feedback Count : {}'.format(len(negative_feedbacks)))
print('negative ', negative_feedbacks)


Result:
Positive_feebacks Count : 0
positive  []

Negative_feedback Count : 5
negative  ['I dont_heat you ', 'The experience was bad as hell', 'This app is really helpful and bad', 'Damn the app tastes like shit ', "Please don't download the app you will regret it "]
الصورة الرمزية لـ admin

اترك تعليقاً

لن يتم نشر عنوان بريدك الإلكتروني. الحقول الإلزامية مشار إليها بـ *