SentimentAnalysisInSE / code_review_analysis

0 stars 0 forks source link

Run Sentiment Analysis with IBM Tone Analyzer #6

Open bcdasilv opened 5 years ago

bcdasilv commented 5 years ago

Read the IBM Tone Analyzer documentation (https://www.ibm.com/watson/services/tone-analyzer/)

Create an IBM free account to allow you to use their REST API.

Make your first API requests with dummy data and interpret the results to make sure you have the environment ready.

Then, consume their API to classify the code review comments from our work dataset (oracle.xlsx)

steven19992017 commented 5 years ago

I registered an account on IBM cloud and tried to use the request module of node.js to complete the http request call for their api. The example they gave was a curl command which I don't think it's the best way of making api calls for our purpose. But I wasn't quite able to get the api calls to work. I think this might be due to China's internet censorship so i can't make http requests to cites like google on the command prompt. I will look into how to get around that. I currently only have VPN set up for my browsers. Also, I was wondering if you are familiar with curl commands and converting that to javascript code?

steven19992017 commented 5 years ago

hours log: 12 hours

bcdasilv commented 5 years ago

The curl commands are just for running examples and try out requests and responses before you actually code them. It is just a simple way to send requests and get responses without having to run a program or an entire application.

Why have you tried to use node.js for that? Nothing against... Just wanted to understand your rationale.

Another possible tool to try out API calls is Postman (https://www.getpostman.com/) Or you can try in python by using the lib 'requests' (https://2.python-requests.org/en/master/).

In any of those cases, if your requests are being blocked at network level, that won't work. Let's talk about it in our meeting.

steven19992017 commented 5 years ago

The reason why I used javascript is because I used it before for api calls and I thought javascript is the standard way to do it. Well anyways I was able to set a global proxy for command prompt so I was able to make api calls. I tried the following python code but I got a code 401, access unauthorized reply from IBM here is my python code:

import requests import json

apikey = 'zTUNh3TNOi_BvgK-grAMn4mgQsiPYYIMvDGsRGoSdZNw' payload = {'text': 'i am very happy today'} headers = {'Content-Type':'application/json', 'Authorization': 'Bearer {}'.format(apikey)} url = "https://gateway.watsonplatform.net/tone-analyzer/api/v3/tone?version=2017-09-21" r = requests.post(url, json=payload, headers=headers) print(r.text)

I am not sure if my request call is correctly formatted

steven19992017 commented 5 years ago

Hours log: 8 Hours

bcdasilv commented 5 years ago

Ok. You can use javascript/node.js if you feel more comfortable with that. However, Python code for that purpose is much simpler.

In addition, I tried to reproduce the error here. First, I tried also with curl and I got the same http 401 error. Then I search a bit on Google and found this GH org: https://github.com/watson-developer-cloud

There you can find SDKs for IBM Watson services in several languages such as Python (https://github.com/watson-developer-cloud/python-sdk) or Javascript https://github.com/watson-developer-cloud/node-sdk. They all have examples. So, I tried the python one and worked well! I installed the python sdk following instructions in their readme. Then I downloaded the example file "...examples/tone_analyzer_v3.py" and ran only example1 (commented our the rest) and worked well without the 401 error.