Question: Python SentimentAnalysis.py import nltk from nltk.sentiment.vader import SentimentIntensityAnalyzer import praw reddit = praw.Reddit(client_id='copy and paste your client id here', client_secret='copy and paste your secret here',

Python

SentimentAnalysis.py

import nltk from nltk.sentiment.vader import SentimentIntensityAnalyzer import praw

reddit = praw.Reddit(client_id='copy and paste your client id here', client_secret='copy and paste your secret here', user_agent='my user agent' ) nltk.download('vader_lexicon') sid = SentimentIntensityAnalyzer()

def get_text_negative_proba(text): return sid.polarity_scores(text)['neg']

def get_text_neutral_proba(text): return sid.polarity_scores(text)['neu']

def get_text_positive_proba(text): return sid.polarity_scores(text)['pos']

def get_submission_comments(url): submission = reddit.submission(url=url) submission.comments.replace_more()

return submission.comments

def main(): comments = get_submission_comments('https://www.reddit.com/r/learnprogramming/comments/5w50g5/eli5_what_is_recursion/') print(comments[0].body) print(comments[0].replies[0].body)

neg = get_text_negative_proba(comments[0].replies[0].body)

print(neg)

main()

Tired of seeing this, you and a group of friends decide to create an extension for your favorite web browser that automatically hides negative comments when you visit Reddit. As a first step to tackle this NLP problem, one of your team members decides to build a machine learning model to classify comments. She implements a method called get_text_negative_proba that receives a string containing the comment to be analyzed and outputs a number between 0 and 1. The closer the number is to 1, the more likely it is to be a negative comment. She also implemented two other methods: get_text_neutral_proba and get_text_positive_proba that do the same thing as get_text_negative_proba, but for neutral and positive sentiments.

She also writes the code to communicate with Reddit programmatically using their API. She writes a method called get_submission_comments that receives the URL of a Reddit submission as input (check the source code to see an example) and returns all the submissions replies.

She asks you if you can implement the process_comments method she left blank. The purpose of this method is to traverse the replies tree of a given submission,and return three lists: negative_comments_list, neutral_comments_list and positive_comments_list . In other words, you need to traverse all of the replies in the submission, which are structured in a tree-like format.(Recursion)

When you call get_submission_comments, you get the submissions top replies (as a list). Each of these replies might have its own replies. To access a reply replies, you can type .replies. This is how you access the list of replies of . Those replies might have their own replies (and those replies more replies). There is a recursion pattern. Example of a reddit submission and its comments:

Python SentimentAnalysis.py import nltk from nltk.sentiment.vader import SentimentIntensityAnalyzer import praw reddit =

This involves using Anaconda(Python 3.6), NLTK, and PRAW. Using Reddits API

Implement the process_comments method that she left blank. The purpose of this method is to traverse the replies tree of a given submission,and return three lists: negative_comments_list, neutral_comments_list and positive_comments_list . In other words, you need to traverse all of the replies in the submission, which are structured in a tree-like format.(Recursion)

MY SUBREDDITS FRONT . ALL . RANDOM FUNNY-ADVICEANIMALS . PICS . AWW . WTF . TODAY!EARNED PROGRAMMING comments related other discussion SQL Joins Explained (x-post r/SQL) (i.imgur.com) submitted 7 months ago by deadman87 409 comments share save hide give gold report 3470 top 200 comments show all 409 sorted by: best caadbury 513 points 7 months ago Something more verbose that I printed and hung on my cubicle wall permalink save dont, ban-me-please 59 points 7 months ago" Hrm. I was like "I've never seen this before, I better bookmark it" then see it was bookmarked several times. I gotta use my bookmarks more often. permalink save parent -1 nixle 11 points 7 months ago Lol, I read your comment thinking "yeah I should probably bookmark it too" quess what... permalink save parent -1 Rudy69 111 points 7 months ago Looked at the original....thought to myself "this is why I'll never understand joins" Looked at yours for sec "Ooooohhhh that's how it works" MY SUBREDDITS FRONT . ALL . RANDOM FUNNY-ADVICEANIMALS . PICS . AWW . WTF . TODAY!EARNED PROGRAMMING comments related other discussion SQL Joins Explained (x-post r/SQL) (i.imgur.com) submitted 7 months ago by deadman87 409 comments share save hide give gold report 3470 top 200 comments show all 409 sorted by: best caadbury 513 points 7 months ago Something more verbose that I printed and hung on my cubicle wall permalink save dont, ban-me-please 59 points 7 months ago" Hrm. I was like "I've never seen this before, I better bookmark it" then see it was bookmarked several times. I gotta use my bookmarks more often. permalink save parent -1 nixle 11 points 7 months ago Lol, I read your comment thinking "yeah I should probably bookmark it too" quess what... permalink save parent -1 Rudy69 111 points 7 months ago Looked at the original....thought to myself "this is why I'll never understand joins" Looked at yours for sec "Ooooohhhh that's how it works

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!