def marvel_vs_dc(co_1, co_2):
    both = [co_1, co_2]
    avg_score_1 = dict()
    avg_score_2 = dict()
    for co in both:
        count = 0
        for movie in co:
            data = t.search(q="movie", count=50)
            for status in data['statuses']:
                count += 1
                status = str(status)
                score = SentimentIntensityAnalyzer().polarity_scores(status)
                if co == co_1:
                    for key, value in score.items():
                        avg_score_1[key] = (avg_score_1.get(key, 0) + value)
                if co == co_2:
                    for key, value in score.items():
                        avg_score_2[key] = (avg_score_1.get(key, 0) + value)
    count = count
    for key, value in avg_score_1.items():
        avg_score_1[key] = (value / count)
    for key, value in avg_score_2.items():
        avg_score_2[key] = (value / count)
    print("Dc has a score of {}".format(avg_score_1))
    print("Marvel has a score of {}".format(avg_score_2))
    if avg_score_1['pos'] - avg_score_1['neg'] < avg_score_2[
            'pos'] - avg_score_2['neg']:
        print("Marvel Wins!")
    elif avg_score_1['pos'] - avg_score_1['neg'] == avg_score_2[
            'pos'] - avg_score_2['neg']:
        print("They Tie.")
    else:
        print("DC Wins!")
Beispiel #2
0
import argparse
from nltk.sentiment.vader import SentimentIntensityAnalyzer
import operator

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Vader sentiment analyzer')
    parser.add_argument('-s', action='store', type=str)
    args = parser.parse_args()

    if args.s:
        scores = SentimentIntensityAnalyzer().polarity_scores(args.s)
        del (scores['compound'])
        sorted_scores = sorted(scores.items(),
                               key=operator.itemgetter(1),
                               reverse=True)
        print(sorted_scores[0][0])
Beispiel #3
0
#Python model for analyzing the sentiment of our sentences

#Python package that allows us to pass cmd line arguments to our script
import argparse
from nltk.sentiment.vader import SentimentIntensityAnalyzer
import operator

#entry point of python script
if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Vader sentiment analyzer')
    parser.add_argument('-s', action='store', type=str)
    args = parser.parse_args(
    )  #all parameters that we pass to our script wil be here

    if args.s:
        scores = SentimentIntensityAnalyzer().polarity_scores(
            args.s)  #how pos/neg/neutral inputted sentence is
        # {'neg': 0.756, 'neu': 0.244, 'pos': 0.0, 'compound': -0.4767}
        del scores['compound']  #we dont need it
        #sort and take highest value
        sorted_scores = sorted(
            scores.items(), key=operator.itemgetter(1),
            reverse=True)  #itemgetter(1) is value. itemgetter(0) is key, 'neg'
        # sorted_scores = [('neg', 0.756), ('neu', 0.244), ('pos', 0.0)]
        print sorted_scores[0][0]  #it'll return neg, neu or pos
import argparse
from nltk.sentiment.vader import SentimentIntensityAnalyzer
import operator

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Vader sentiment analyzer")
    parser.add_argument("-s",action="store",type=str)
    args = parser.parse_args()

    if args.s:
        scores = SentimentIntensityAnalyzer().polarity_scores(args.s)
        del scores["compound"]
        sorted_scores = sorted(scores.items(), key=operator.itemgetter(1), reverse=True)
        print sorted_scores