简体   繁体   中英

Sentiment analysis with python

I am trying to do sentiment analysis with python.I have gone through various tutorials and have used libraries like nltk, textblob etc for it.

But what I want is bit different and I am not able figure out any material for that

Suppose I have a statement like

apples are tasty but they are very expensive

The above statement can be classified in to two classes/labels like taste and money

My aim is to get sentiment of the statement with respect to these two labels

My expected result would be positive sentiment for taste but negative sentiment for money

How this can be achieved

With textblob

def calculate_sentiment_textblob(current_comment):
current_comment = str(current_comment)

comment_sentiment_calculation = TextBlob(current_comment)

comment_sentiment = ""

if comment_sentiment_calculation.sentiment.polarity < 0:
    comment_sentiment = "Negative"
elif comment_sentiment_calculation.sentiment.polarity > 0:
    comment_sentiment = "Positive"
else:
    comment_sentiment = "Neutral"

print(current_comment)
print(comment_sentiment)
sentiment_list.append(current_comment +" "+comment_sentiment)
comments_scraped.loc[comments_scraped.reviews== current_comment,'sentiment_textblob'] = comment_sentiment

With vader

def calculate_sentiment_vader(current_comment):
    current_comment = str(current_comment)

    comment_sentiment_calculation = sid.polarity_scores(current_comment)

    comment_sentiment = ""

    if comment_sentiment_calculation['compound'] < 0:
        comment_sentiment = "Negative"
    elif comment_sentiment_calculation['compound'] > 0:
        comment_sentiment = "Positive"
    else:
        comment_sentiment = "Neutral"

    comments_scraped.loc[comments_scraped.reviews== current_comment,'sentiment_vader'] = comment_sentiment

I kindly suggest you investigate on aspect-based sentiment analysis. It does not focus sentiment on only an entity but an entity's attributes. There have been SemEval challenges to investigate this problem on attributes of entities, for example laptops and restaurants.

There were many participants, their papers are published and the organizers published explanatory papers as well.

You can reach them here:

Hope these help, cheers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM