Giter Site home page Giter Site logo

lab-1's Introduction

#Data Structures(CS2302) #Lester Ibarra #Sentiment Analysis #Aguirre, Diego #Nath, Anindita import nltk from nltk.sentiment.vader import SentimentIntensityAnalyzer import praw reddit = praw.Reddit(client_id='HjIibYz3lhgCJg', client_secret='SBMs3bHf_jvEd18IB96Z8kgqVI4', user_agent= 'Llibarra2' )#This allows access to the subreddit nltk.download('vader_lexicon') sid = SentimentIntensityAnalyzer()

def get_text_negative_proba(text): return sid.polarity_scores(text)['neg']#provides a score between 1 and 0, closests to 1 meaning a negative comment

def get_text_neutral_proba(text): return sid.polarity_scores(text)['neu']#provides a score between 1 and 0, closests to 1 meaning a neutral comment

def get_text_positive_proba(text): return sid.polarity_scores(text)['pos']#provides a score between 1 and 0, closests to 1 meaning a positive comment

def get_submission_comments(url):#receives url of subreddit and returns all comments including replies as well submission = reddit.submission(url=url) submission.comments.replace_more(limit=None)

return submission.comments

def comment_processor(text, n):#receives array of all comments and replies as well as an integer with starting value 0 list_neg,list_pos,list_neu = [],[],[] if n==len(text): return list_neg,list_pos,list_neu#returns three list contaning all possible comments with their respective sensitivity comment = text[n].body pos = get_text_positive_proba(comment)#gives value for comment being positive neg = get_text_negative_proba(comment)#gives value for comment being negative neu = get_text_neutral_proba(comment)#gives value for comment being neutral if(pos>neg and pos>neu):#compares values received to see dominating sensitivity list_pos.append(comment) if(neg>pos and neg>neu): list_neg.append(comment) if(neu>pos and neu>neg): list_neu.append(comment) n+=1 comment_processor(text, n)#recursive statement

def main():#code was tested with (https://www.reddit.com/r/politics/comments/9gxu84/donald_trump_is_actively_obstructing_justice/ and #https://www.reddit.com/r/dogs/comments/9h0ela/fluff_i_realized_my_dog_is_a_solid_protector/) #These two subreddits were tested as they involve politics which can be very much contriversial, meaning negative comments would be more precedent #and story of a dog, which would most likely contain positive comments comments = get_submission_comments('https://www.reddit.com/r/learnprogramming/comments/5w50g5/eli5_what_is_recursion/') all_comments_and_replies = comments.list()#able to list all comments and replies from subreddit n = 0 list_neg,list_pos,list_neu = [],[],[] list_neg,list_pos,list_neu = comment_processor(all_comments_and_replies, n)#The returned lists are placed inside new lists

print("Negative Comments")
for i in range(len(list_a)):#Prints all negative comments
    print(list_a[i])

print("Positive Comments")    
for i in range(len(list_b)):#Prints all positive comments
    print(list_b[i])

print("Neutral Comments")
for i in range(len(list_c)):#Prints all neutral comments
    print(list_c[i])

main()

lab-1's People

Contributors

llibarra2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.