New to Dream to Learn? Check out our Quick Start guide!  

0COMMENTS1RECOMMENDS

IBM Watson - Tone Analyzer - Code Snippet

17
POSTED IN: Building Bridges from R to IBM Watson

######################################################
### Experimental Code.  Experimental R Interface for IBM Watson Services -
### Focus: IBM Watson Tone Analyzer is a service that helps people comprehend, consume, and revise the language tone of their writing for more efficient communications
### https://tone-analyzer-demo.mybluemix.net/
### http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/tone-analyzer/
### http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/apis/tone-analyzer-apis.html
######################################################

library(RCurl) # install.packages("RCurl") # if the package is not already installed
library(httr)
library(XML)
library(data.table)
library(reshape2)
library(tidyr)
library(dplyr)


#  Ryans' Service - active Jan 26 2016
username = "6a2fce6e-f961-4fe7-ba8e-YOURUSERNAME"
password = "YOURPASSWORD"
username_password = paste(username,":",password)

######### Housekeeping And Authentication
setwd("/Users/ryan/Documents/Service - Tone Analyzer")
getwd()
base_url = "https://gateway.watsonplatform.net/tone-analyzer-experimental/api/v1/tone"
getURL(base_url,userpwd = username_password )


# testing
getURL("https://gateway.watsonplatform.net/tone-analyzer-experimental/api/v1/tone?text=hello",userpwd = username_password )
# works


response <- POST(url="https://gateway.watsonplatform.net/tone-analyzer-experimental/api/v1/tone",
     authenticate(username,password),
     add_headers("Content-Type"="text/plain","charset"="utf-8"),
     body="happy" )

response <- content(response, "text")
response

# works!!! More to come

Before you can comment, you need to sign-up or login

About the Author

Ryan Anderson

Ryan Anderson

Hi! I like to play with data, analytics and hack around with robots and gadgets in my garage. Lately I've been learning about machine learning.

About this blog

This is an informal blog that explores tools, code and tricks that group members have developed to engage IBM Watson cognitive computing services - from the R Programming Language. Packages include RCURL to access Watson APIs - for services that include Natural Language Classifier and Speech to Text. THIS IS MY PERSONAL BLOG - it does not represent the views of my employer. Code is presented as 'use at your own risk' (it has lots of bugs)

Created: September 13, 2015

English

Up Next