├── man ├── .Rapp.history ├── watson.keys.display.Rd ├── watson.tone.analyze.Rd ├── watson.tone.demo.Rd ├── watson.keys.enter.Rd ├── watson.keys.load.Rd ├── watson.demo.Rd ├── watson.stt.test.Rd ├── watson.tts.demovoices.Rd ├── watson.stt.process.Rd ├── watson.tts.listvoices.Rd ├── watson.alchemy.test.Rd ├── watson.pi.demo.Rd ├── watson.pi.analyze.Rd ├── watson.nlc.listallclassifiers.Rd ├── watson.tts.process.Rd ├── watson.nlc.deleteclassifier.Rd ├── watson.alchemy.combined.Rd ├── watson.nlc.checkclassifierstatus.Rd ├── watson.nlc.processtext.Rd └── watson.nlc.createnewclassifier.Rd ├── .Rbuildignore ├── .gitignore ├── media ├── audio_file.wav ├── STT_speech_test.wav └── ryan_raspberry_pi_test.wav ├── WatsonR.Rproj ├── NAMESPACE ├── DESCRIPTION ├── R ├── keys.R ├── watson.alchemy.R ├── watson.tone.R ├── watson.stt.R ├── watson.pi.R ├── watson.keys.R ├── watson.nlc.R ├── watson.demo.R └── watson.tts.R ├── data ├── ronald_reagan_speech.txt └── nlc_sortinghat.csv └── README.md /man/.Rapp.history: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /media/audio_file.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rustyoldrake/WatsonR/HEAD/media/audio_file.wav -------------------------------------------------------------------------------- /media/STT_speech_test.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rustyoldrake/WatsonR/HEAD/media/STT_speech_test.wav -------------------------------------------------------------------------------- /media/ryan_raspberry_pi_test.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rustyoldrake/WatsonR/HEAD/media/ryan_raspberry_pi_test.wav -------------------------------------------------------------------------------- /man/watson.keys.display.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.keys.R 3 | \name{watson.keys.display} 4 | \alias{watson.keys.display} 5 | \title{WatsonR - Display API Key Info} 6 | \usage{ 7 | watson.keys.display() 8 | } 9 | \value{ 10 | NOTHING 11 | } 12 | \description{ 13 | Displays API Keys - Empty Slots and Full Slots 14 | } 15 | -------------------------------------------------------------------------------- /man/watson.tone.analyze.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.tone.R 3 | \name{watson.tone.analyze} 4 | \alias{watson.tone.analyze} 5 | \title{WatsonR - Tone Analyzer} 6 | \usage{ 7 | watson.tone.analyze(utterance) 8 | } 9 | \value{ 10 | NOTHING 11 | } 12 | \description{ 13 | Tone Analysis receives an utterance and returns 14 | } 15 | -------------------------------------------------------------------------------- /man/watson.tone.demo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.tone.R 3 | \name{watson.tone.demo} 4 | \alias{watson.tone.demo} 5 | \title{WatsonR - Tone Analyzer - Demo} 6 | \usage{ 7 | watson.tone.demo() 8 | } 9 | \arguments{ 10 | \item{Demo}{String} 11 | } 12 | \value{ 13 | NOTHING 14 | } 15 | \description{ 16 | Tone Analysis Demo 17 | } 18 | -------------------------------------------------------------------------------- /man/watson.keys.enter.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.keys.R 3 | \name{watson.keys.enter} 4 | \alias{watson.keys.enter} 5 | \title{WatsonR - Enter API Keys Info Manually} 6 | \usage{ 7 | watson.keys.enter() 8 | } 9 | \value{ 10 | NOTHING 11 | } 12 | \description{ 13 | Prompts User to Enter in Keys. 14 | KEYS.R FILE load with watson.keys.load is alternate method 15 | } 16 | -------------------------------------------------------------------------------- /man/watson.keys.load.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.keys.R 3 | \name{watson.keys.load} 4 | \alias{watson.keys.load} 5 | \title{WatsonR - Load API Keys from KEYS.R file} 6 | \usage{ 7 | watson.keys.load() 8 | } 9 | \value{ 10 | NOTHING 11 | } 12 | \description{ 13 | This Function will Load your API keys from KEYS.R file if it is in working directory 14 | You can create / edit this file yourself 15 | } 16 | -------------------------------------------------------------------------------- /man/watson.demo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.demo.R 3 | \name{watson.demo} 4 | \alias{watson.demo} 5 | \title{WatsonR - Demonstration of Alchemy, Personality Insights, Tone Analyzer and Natural Language Classifier} 6 | \usage{ 7 | watson.demo() 8 | } 9 | \value{ 10 | NOTHING 11 | } 12 | \description{ 13 | Demonstrates WatsonR - Multiple APIs. Note NLC Natural Language Classifier takes time to complete training 14 | } 15 | -------------------------------------------------------------------------------- /man/watson.stt.test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.stt.R 3 | \name{watson.stt.test} 4 | \alias{watson.stt.test} 5 | \title{WatsonR - Speech to Text (STT) TEST - WAV to Transcript} 6 | \usage{ 7 | watson.stt.test() 8 | } 9 | \arguments{ 10 | \item{NONE}{- WAV file test is part of package} 11 | } 12 | \value{ 13 | Transcript (Vanilla) of WAV file; omits all other data 14 | } 15 | \description{ 16 | Speech to Text 17 | } 18 | -------------------------------------------------------------------------------- /WatsonR.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | -------------------------------------------------------------------------------- /man/watson.tts.demovoices.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.tts.R 3 | \name{watson.tts.demovoices} 4 | \alias{watson.tts.demovoices} 5 | \title{WatsonR - Text to Speech (TTS) - Round The World Introductions -} 6 | \usage{ 7 | watson.tts.demovoices(creds) 8 | } 9 | \arguments{ 10 | \item{creds}{the name of the credentials file in json format} 11 | } 12 | \value{ 13 | Everyone Talks 14 | } 15 | \description{ 16 | Text to Speech - LIst of Voices 17 | } 18 | -------------------------------------------------------------------------------- /man/watson.stt.process.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.stt.R 3 | \name{watson.stt.process} 4 | \alias{watson.stt.process} 5 | \title{WatsonR - Speech to Text (STT) PROCESS - receives WAV File} 6 | \usage{ 7 | watson.stt.process(filename) 8 | } 9 | \arguments{ 10 | \item{Receives}{WAV File - rather a pointer to where FILE.WAV is} 11 | } 12 | \value{ 13 | Transcript (Vanilla) of WAV file; omits all other data 14 | } 15 | \description{ 16 | Speech to Text 17 | } 18 | -------------------------------------------------------------------------------- /man/watson.tts.listvoices.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.tts.R 3 | \name{watson.tts.listvoices} 4 | \alias{watson.tts.listvoices} 5 | \title{WatsonR - Text to Speech (TTS) - List Voices Available From services} 6 | \usage{ 7 | watson.tts.listvoices(creds) 8 | } 9 | \arguments{ 10 | \item{creds}{the name of the credentials file in json format} 11 | } 12 | \value{ 13 | list of voices from the TTS service 14 | } 15 | \description{ 16 | Text to Speech - LIst of Voices 17 | } 18 | -------------------------------------------------------------------------------- /man/watson.alchemy.test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.alchemy.R 3 | \name{watson.alchemy.test} 4 | \alias{watson.alchemy.test} 5 | \title{WatsonR - Alchemy Language Test} 6 | \usage{ 7 | watson.alchemy.test(creds) 8 | } 9 | \arguments{ 10 | \item{creds}{json file containing the alchemy api key to use for this call} 11 | } 12 | \value{ 13 | NOTHING - just prints the response (hopefully 200 & API response) on screen 14 | } 15 | \description{ 16 | Alchemy Language Functions - Light Test 17 | } 18 | -------------------------------------------------------------------------------- /man/watson.pi.demo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.pi.R 3 | \name{watson.pi.demo} 4 | \alias{watson.pi.demo} 5 | \title{WatsonR - Personality Insights (PI) - DEMO} 6 | \usage{ 7 | watson.pi.demo(creds) 8 | } 9 | \arguments{ 10 | \item{creds}{the name of the credentials file in json format} 11 | 12 | \item{Pulls}{Ronald Reagan speech that is included in the library} 13 | } 14 | \value{ 15 | 52 Psychometric traits - big 5, needs, values, personalit 16 | } 17 | \description{ 18 | Personality Insights - Demo using a Ronald Reagan Speech # 19 | } 20 | -------------------------------------------------------------------------------- /man/watson.pi.analyze.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.pi.R 3 | \name{watson.pi.analyze} 4 | \alias{watson.pi.analyze} 5 | \title{WatsonR - Personality Insights (PI) - Analyze} 6 | \usage{ 7 | watson.pi.analyze(creds, text_passage) 8 | } 9 | \arguments{ 10 | \item{creds}{the name of the credentials file in json format} 11 | 12 | \item{text_passage}{Long text passage to analyze - has to be more than 100 words, better if more than 2500} 13 | } 14 | \value{ 15 | 52 Psychometric traits - big 5, needs, values, personalit 16 | } 17 | \description{ 18 | Personality Insights 19 | } 20 | -------------------------------------------------------------------------------- /man/watson.nlc.listallclassifiers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.nlc.R 3 | \name{watson.nlc.listallclassifiers} 4 | \alias{watson.nlc.listallclassifiers} 5 | \title{WatsonR - Natural Language Classifier (NLC) - LIST 6 | LIST ALL CLASSIFIERS AND RETURN NEAT LIST 7 | NLC2} 8 | \usage{ 9 | watson.nlc.listallclassifiers(creds) 10 | } 11 | \arguments{ 12 | \item{creds}{the name of the credentials file in json format} 13 | } 14 | \value{ 15 | LIST OF CLASSIFIERS 16 | } 17 | \description{ 18 | WatsonR - Natural Language Classifier (NLC) - LIST 19 | LIST ALL CLASSIFIERS AND RETURN NEAT LIST 20 | NLC2 21 | } 22 | -------------------------------------------------------------------------------- /man/watson.tts.process.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.tts.R 3 | \name{watson.tts.process} 4 | \alias{watson.tts.process} 5 | \title{WatsonR - Text to Speech (TTS) - Speechify the Transcript; demand the voice you want} 6 | \usage{ 7 | watson.tts.process(creds, transcript, voice_number) 8 | } 9 | \arguments{ 10 | \item{creds}{the name of the credentials file in json format} 11 | 12 | \item{transcript}{TEXT to be made into audio;} 13 | 14 | \item{voice_number}{Index 1-12 of Voice (see watson.tts.listvoices() for list)} 15 | } 16 | \value{ 17 | NOTHING 18 | } 19 | \description{ 20 | Text to Speech 21 | } 22 | -------------------------------------------------------------------------------- /man/watson.nlc.deleteclassifier.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.nlc.R 3 | \name{watson.nlc.deleteclassifier} 4 | \alias{watson.nlc.deleteclassifier} 5 | \title{WatsonR - Natural Language Classifier (NLC) - DELETE Classifier 6 | Receives name of Classifier to delete; May not be able to do this until training complete} 7 | \usage{ 8 | watson.nlc.deleteclassifier(creds, kill_classifier) 9 | } 10 | \arguments{ 11 | \item{creds}{the name of the credentials file in json format} 12 | 13 | \item{kill_classifier}{Classifier ID} 14 | } 15 | \value{ 16 | Message that you've killed the classifier (but not the service) 17 | } 18 | \description{ 19 | NLC5 20 | } 21 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(watson.alchemy.combined) 4 | export(watson.alchemy.test) 5 | export(watson.demo) 6 | export(watson.keys.display) 7 | export(watson.keys.enter) 8 | export(watson.keys.load) 9 | export(watson.nlc.checkclassifierstatus) 10 | export(watson.nlc.createnewclassifier) 11 | export(watson.nlc.deleteclassifier) 12 | export(watson.nlc.listallclassifiers) 13 | export(watson.nlc.processtext) 14 | export(watson.pi.analyze) 15 | export(watson.pi.demo) 16 | export(watson.stt.process) 17 | export(watson.stt.test) 18 | export(watson.tone.analyze) 19 | export(watson.tone.demo) 20 | export(watson.tts.demovoices) 21 | export(watson.tts.listvoices) 22 | export(watson.tts.process) 23 | -------------------------------------------------------------------------------- /man/watson.alchemy.combined.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.alchemy.R 3 | \name{watson.alchemy.combined} 4 | \alias{watson.alchemy.combined} 5 | \title{WatsonR - Alchemy Language COMBINED Calles} 6 | \usage{ 7 | watson.alchemy.combined(creds, utterance) 8 | } 9 | \arguments{ 10 | \item{creds}{json file containing the alchemy api key to use for this call} 11 | 12 | \item{utterance}{String to be Analyzed by Alchemy's combined call} 13 | } 14 | \value{ 15 | JSON formatted like this http://www.alchemyapi.com/api/combined/textc.html 16 | } 17 | \description{ 18 | Alchemy Language Functions -- Receives text and returns MULTPLE Features like keyword, entity, sentiment, tone 19 | } 20 | -------------------------------------------------------------------------------- /man/watson.nlc.checkclassifierstatus.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.nlc.R 3 | \name{watson.nlc.checkclassifierstatus} 4 | \alias{watson.nlc.checkclassifierstatus} 5 | \title{WatsonR - Natural Language Classifier (NLC) - STATUS Check} 6 | \usage{ 7 | watson.nlc.checkclassifierstatus(creds, classifier_id) 8 | } 9 | \arguments{ 10 | \item{creds}{the name of the credentials file in json format} 11 | 12 | \item{classifier_id}{Classifier ID} 13 | } 14 | \value{ 15 | Classifier Status 16 | } 17 | \description{ 18 | CHECK CLASSIFIER STATUS 19 | IF YOU GET MESSAGE BELOW - YOU NEED TO WAIT! 20 | Can take 15m for some medium size classifers (longer for larger ones) 21 | "The classifier instance is in its training phase, 22 | not yet ready to accept classify requests" 23 | } 24 | -------------------------------------------------------------------------------- /man/watson.nlc.processtext.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.nlc.R 3 | \name{watson.nlc.processtext} 4 | \alias{watson.nlc.processtext} 5 | \title{WatsonR - Natural Language Classifier (NLC) - PROCESS TEXT 6 | ACCEPT QUERY & RETURN RESULT: classifier and confidence score from text input} 7 | \usage{ 8 | watson.nlc.processtext(creds, classifier_id, query_text) 9 | } 10 | \arguments{ 11 | \item{creds}{the name of the credentials file in json format} 12 | 13 | \item{classifier_id}{the classifier identification uuid} 14 | 15 | \item{query_text}{to Pass to Classifier} 16 | } 17 | \value{ 18 | Classifiers, with confidence 19 | } 20 | \description{ 21 | WatsonR - Natural Language Classifier (NLC) - PROCESS TEXT 22 | ACCEPT QUERY & RETURN RESULT: classifier and confidence score from text input 23 | } 24 | -------------------------------------------------------------------------------- /man/watson.nlc.createnewclassifier.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/watson.nlc.R 3 | \name{watson.nlc.createnewclassifier} 4 | \alias{watson.nlc.createnewclassifier} 5 | \title{WatsonR - Natural Language Classifier (NLC) - CREATE 6 | CREATE NEW CLASSIFIER - post /v1/classifiers - 7 | Creates a classifier with CSV data ## URL below no "/" after base url} 8 | \usage{ 9 | watson.nlc.createnewclassifier(creds, csvfile, classifiername, lang) 10 | } 11 | \arguments{ 12 | \item{creds}{the name of the credentials file in json format} 13 | 14 | \item{csvfile}{File of Ground Truth to Train; Name of the New Classifier} 15 | 16 | \item{classifiername}{The name to assign to the new classifier} 17 | 18 | \item{lang}{ISO standard 639 language code for classifier} 19 | } 20 | \value{ 21 | initial status 22 | } 23 | \description{ 24 | NLC1 25 | } 26 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: WatsonR 2 | Type: Package 3 | Title: R Interface to IBM Watson Developer Cloud Services 4 | Version: 0.0.1.2 5 | Author: Ryan Anderson [aut,cre] 6 | Maintainer: Ryan Anderson 7 | Description: This package permits R users to send unstructured data to IBM Watson. IBM Watson Watson Developer Cloud (WDC) services are (REST) Application Programming Interfaces (APIs) These WDC services (API) keys are free trial but require a key via BLUEMIX for EACH service. FREE TRIAL Register: https://console.ng.bluemix.net/ IBM Bluemix is the IBM open cloud platform (PaaS) built on Cloud Foundry open source technology. 8 | Depends: R (>= 3.0.2), 9 | httr, 10 | rjson, 11 | audio 12 | Encoding: UTF-8 13 | Imports: RCurl, 14 | XML, 15 | plyr, 16 | stringr, 17 | splitstackshape, 18 | data.table, 19 | curl 20 | Note: Experimental package WatsonR is my own, not my employer's, and presented without warranty. It may contain errors so use at your own risk :) - Also, this is my first crack at building a package - so I've probably made a few errors. 21 | License: MIT 22 | LazyData: TRUE 23 | RoxygenNote: 5.0.1.9000 24 | -------------------------------------------------------------------------------- /R/keys.R: -------------------------------------------------------------------------------- 1 | # keys.R -- YOUR PRIVATE KEYS - DO NOT SHARE 2 | # this is not the 'pro' way to store keys, but it's low barrier to entry for many newbs http://blog.revolutionanalytics.com/2015/11/how-to-store-and-use-authentication-details-with-r.html 3 | # The watson.keys.load will let you modify this if you like 4 | 5 | # NOT TESTED YET - How many services you can stand up at one time on a FREE / 30 Day Trial 6 | # NEEDS WORK # 7 | 8 | # ALCHEMY Language - AUTHENTICATION / CREDENTIALS - Platinum 9 | username_password_ALCH = "xxxxf30440aaa160dd1da4d8126c6b285" 10 | 11 | # TONE ANALYZER - AUTHENTICATION AND CREDENTIALS - GA 12 | username_TON = "xxxx-7454-4721-b829-bcd051ef7d2d" 13 | password_TON = "xxxx" 14 | username_password_TON = paste(username_TON,":",password_TON,sep="") 15 | 16 | # PERSONALITY INSIGHTS (PI) - AUTHENTICATION AND CREDENTIALS - Platinum 17 | username_PI = "db1272c1-e3d8-4dfb-86aa-d6ab31ee2d2c" 18 | password_PI = "ijWbMi5kHHGb" 19 | username_password_PI = paste(username_PI,":",password_PI,sep="") 20 | 21 | # NLC CREDENTIALS - AUTHENTICATION AND CREDENTIALS - Platinum 22 | username_NLC = "xxxxx-e8cd-4dbf-816b-6a7ac1f2dd71" 23 | password_NLC = "xxxxx" 24 | username_password_NLC = paste(username_NLC,":",password_NLC,sep="") 25 | 26 | # STT - Speech-To-Text (STT) - RED - AUTHENTICATION AND CREDENTIALS 27 | username_STT <-"xxxxx-b5bb-406c-9cc3-7cb964fb614f" 28 | password_STT <- "xxxxxxx" 29 | username_password_STT = paste(username_STT,":",password_STT,sep="") 30 | 31 | # TTS - TEXT TO SPEECH (TTS) - RED - AUTHENTICATION AND CREDENTIALS 32 | username_TTS <-"xxxxx-48c4-486e-98de-174388b22b17" 33 | password_TTS <- "xxxxxx" 34 | username_password_TTS = paste(username_TTS,":",password_TTS,sep="") 35 | 36 | 37 | -------------------------------------------------------------------------------- /R/watson.alchemy.R: -------------------------------------------------------------------------------- 1 | #' WatsonR - Alchemy Language Test 2 | #' 3 | #' Alchemy Language Functions - Light Test 4 | #' @param creds json file containing the alchemy api key to use for this call 5 | #' @return NOTHING - just prints the response (hopefully 200 & API response) on screen 6 | #' @export 7 | 8 | 9 | watson.alchemy.test <- function(creds) { 10 | print("Short Test of Alchemy - Hitting Endpoint; Checking Credentials OK and Transactions Consumed ") 11 | # httr::GET(url=paste("http://gateway-a.watsonplatform.net/calls/info/GetAPIKeyInfo?apikey=",username_password_ALCH,"&outputMode=json",sep="")) 12 | apikey <- fromJSON(, creds)$apikey 13 | httr::GET(url=paste("http://gateway-a.watsonplatform.net/calls/info/GetAPIKeyInfo?apikey=",apikey,"&outputMode=json",sep="")) 14 | } 15 | 16 | 17 | #' WatsonR - Alchemy Language COMBINED Calles 18 | #' 19 | #' Alchemy Language Functions -- Receives text and returns MULTPLE Features like keyword, entity, sentiment, tone 20 | #' @param utterance String to be Analyzed by Alchemy's combined call 21 | #' @param creds json file containing the alchemy api key to use for this call 22 | #' @return JSON formatted like this http://www.alchemyapi.com/api/combined/textc.html 23 | #' @export 24 | 25 | watson.alchemy.combined <- function(creds, utterance) { 26 | print("Alchemy combined call- running multiple Alchemy Language calls") 27 | 28 | alchemy_url <- "http://gateway-a.watsonplatform.net/calls/text/" 29 | api_feature <- "TextGetCombinedData" 30 | output_mode <- "json" 31 | utterance <- URLencode(utterance) #in case we have spaces, we need %20 32 | 33 | apikey <- fromJSON(, creds)$apikey 34 | query <- paste(alchemy_url,api_feature,"?extract=keyword,entity,taxonomy,concept,doc-sentiment,doc-emotion&apikey=",apikey,"&text=",utterance,"&outputMode=",output_mode, sep="") 35 | query 36 | response <- httr::POST(query) 37 | print(response) 38 | return(httr::content(response)) 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /R/watson.tone.R: -------------------------------------------------------------------------------- 1 | #' WatsonR - Tone Analyzer 2 | #' 3 | #' Tone Analysis receives an utterance and returns 4 | #' @param NONE 5 | #' @return NOTHING 6 | #' @export 7 | 8 | watson.tone.analyze <- function(utterance) { 9 | 10 | # library(RCurl) # to talk to Watson - REST APIS # install.packages("RCurl") # if the package is not already installed 11 | # library(httr) # comms 12 | # library(XML) # comms and data 13 | # library(data.table) # data shaping 14 | # library(reshape2) # data shaping 15 | # library(tidyr) # data cleaning 16 | # library(dplyr) # data cleaning 17 | 18 | print("Tone Analyzer - Analyzing...") 19 | utterance <- URLencode(utterance) 20 | data <- RCurl::getURL(paste("https://gateway.watsonplatform.net/tone-analyzer/api/v3/tone?version=2016-05-19&text=",utterance,sep=""),userpwd = username_password_TON ) 21 | data <- as.data.frame(strsplit(as.character(data),"\"score\"")) 22 | data <- data[-c(1), ] # remove dud first row 23 | data <- gsub("\"tone_id\":","",data) 24 | data <- gsub(":","",data) 25 | data <- gsub("\"","",data) 26 | data <- gsub("_big5","",data) 27 | data <- data.frame(data) 28 | data <- data.frame(do.call('rbind', strsplit(as.character(data$data),',',fixed=TRUE))) 29 | data <- data[,-c(3:6), ] # remove dud columns 30 | data <- data[c(1:13), ] # just top 13 (not sure why we have it repeating) 31 | data <- data[c("X2", "X1")] 32 | data$X1 <- as.character.numeric_version(data$X1) # not sure why, but coercing to numbers requires this 33 | data$X1 <- as.numeric(data$X1) 34 | data$X1 <- round((data$X1),2) 35 | data.table::setnames(data,c("trait","signal")) 36 | data 37 | return(data) 38 | } 39 | 40 | 41 | #' WatsonR - Tone Analyzer - Demo 42 | #' 43 | #' Tone Analysis Demo 44 | #' @param Demo String 45 | #' @return NOTHING 46 | #' @export 47 | 48 | watson.tone.demo <- function() { 49 | print("EXAMPLE: Angry and Confident person:") 50 | print("I am so angry that I got a speeding ticket. I'm certain it's the last time!") 51 | watson.tone.analyze("I am so angry that I got a speeding ticket. I'm certain it's the last time!") 52 | } 53 | 54 | 55 | # 56 | -------------------------------------------------------------------------------- /R/watson.stt.R: -------------------------------------------------------------------------------- 1 | #' WatsonR - Speech to Text (STT) PROCESS - receives WAV File 2 | #' 3 | #' Speech to Text 4 | #' @param Receives WAV File - rather a pointer to where FILE.WAV is 5 | #' @return Transcript (Vanilla) of WAV file; omits all other data 6 | #' @export 7 | 8 | watson.stt.process <- function(filename) { 9 | print("Speech to text - processing WAV file that is passd to us ") 10 | print("Sending Test WAV file to Speech to Text service for processing... ") 11 | data <- httr::POST(url="https://stream.watsonplatform.net/speech-to-text/api/v1/recognize", 12 | authenticate(username_STT,password_STT), 13 | add_headers("Content-Type"="audio/wav"), 14 | body = (file = upload_file(filename)) 15 | ) 16 | 17 | print(data$status_code) # print a 200 if all is well 18 | data <- httr::content(data,"text") # just text from JSON 19 | data <- as.data.frame(strsplit(as.character(data),"\\n")) 20 | data <- data[c(7), ] # for now, grab just what we want 21 | data <- paste(data) # kill levels, - fyi this nukes confidence % info (may want later) 22 | data <- gsub(" ","",data) # remove excessive whitespace 0 cannot use ALL [[punct]] here 23 | data <- gsub("\\\\","",data) # remove punct we dont like 24 | data <- gsub("\"","",data) # remove punct we dont like 25 | data <- gsub("transcript","",data) # remove excessive whitespace 26 | data <- gsub(":","",data) # remove excessive whitespace - later: Improve this tidy step. 27 | return(data) 28 | } 29 | 30 | 31 | #' WatsonR - Speech to Text (STT) TEST - WAV to Transcript 32 | #' 33 | #' Speech to Text 34 | #' @param NONE - WAV file test is part of package 35 | #' @return Transcript (Vanilla) of WAV file; omits all other data 36 | #' @export 37 | 38 | watson.stt.test <- function() { 39 | print("Speech to text Test using the speech_test.WAV Test file in the ") 40 | print("Sending Test WAV file to Speech to Text service for processing... ") 41 | data <- httr::POST(url="https://stream.watsonplatform.net/speech-to-text/api/v1/recognize", 42 | authenticate(username_STT,password_STT), 43 | add_headers("Content-Type"="audio/wav"), 44 | body = (file = upload_file("media/STT_speech_test.wav")) 45 | ) 46 | 47 | print(data$status_code) # print a 200 if all is well 48 | data <- httr::content(data,"text") # just text from JSON 49 | data <- as.data.frame(strsplit(as.character(data),"\\n")) 50 | data <- data[c(7), ] # for now, grab just what we want 51 | data <- paste(data) # kill levels, - fyi this nukes confidence % info (may want later) 52 | data <- gsub(" ","",data) # remove excessive whitespace 0 cannot use ALL [[punct]] here 53 | data <- gsub("\\\\","",data) # remove punct we dont like 54 | data <- gsub("\"","",data) # remove punct we dont like 55 | data <- gsub("transcript","",data) # remove excessive whitespace 56 | data <- gsub(":","",data) # remove excessive whitespace - later: Improve this tidy step. 57 | return(data) 58 | } 59 | 60 | # 61 | -------------------------------------------------------------------------------- /R/watson.pi.R: -------------------------------------------------------------------------------- 1 | #' WatsonR - Personality Insights (PI) - Analyze 2 | #' 3 | #' Personality Insights 4 | #' @param creds the name of the credentials file in json format 5 | #' @param text_passage Long text passage to analyze - has to be more than 100 words, better if more than 2500 6 | #' @return 52 Psychometric traits - big 5, needs, values, personalit 7 | #' @export 8 | 9 | watson.pi.analyze <- function(creds, text_passage) { 10 | print("Personality Insights") 11 | ##text_passage <- URLencode(text_passage) ## NO NO NO - no URL encode here (need to resarch why ) 12 | pi_url="https://gateway.watsonplatform.net/personality-insights/api/v3/profile" 13 | credentials = rjson::fromJSON(,creds) 14 | 15 | data <- httr::POST(url=pi_url, 16 | httr::authenticate(credentials$username, credentials$password), 17 | # httr::add_headers("Content-Type"="text/plain","charset"="utf-8"), 18 | body = paste("--data-binary",text_passage, sep=" ")) 19 | ##data 20 | ##return(response) 21 | # content(data,"text") 22 | ## 400 erros come sometimes if not enough words 23 | # data <- as.data.frame(strsplit(as.character(data),"\"id\":\"")) 24 | # data <- data[-c(1:5), ] # remove dud first row 25 | # data <- data.frame(matrix(data)) 26 | # data[,1] <- gsub("\"","",data[,1] ) 27 | # data <- data.frame(do.call('rbind', strsplit(as.character(data$matrix.data),',',fixed=TRUE))) 28 | # data <- data[!grepl('name:',data$X5),] 29 | # data <- data[!grepl('children:',data$X5),] 30 | # data <- data[,-c(2,6), ] # remove columns we dont need - duplicates or dont care for SAMPLING ERROR (now) but mght later 31 | # data.table::setnames(data,c("trait","category","percentage","error")) 32 | # data$percentage <- gsub("percentage:","",data$percentage) 33 | # data$category <- gsub("category:","",data$category) 34 | # data$error <- gsub("sampling_error:","",data$error) 35 | # data$error <- gsub("}","",data$error) # crude but effective 36 | # data$error <- gsub("]","",data$error) # crude but effective 37 | # data$percentage <- round((as.numeric(data$percentage)),4) # if you prefer % format like this 38 | # data$error <- round((as.numeric(data$error)),4) # if you prefer % format like this 39 | # rownames(data) <- NULL # resets row names to remove 'gaps' 40 | # data$row <- as.numeric(rownames(data)) 41 | return(data) 42 | } 43 | 44 | #' WatsonR - Personality Insights (PI) - DEMO 45 | #' 46 | #' Personality Insights - Demo using a Ronald Reagan Speech # 47 | #' @param creds the name of the credentials file in json format 48 | #' @param Pulls Ronald Reagan speech that is included in the library 49 | #' @return 52 Psychometric traits - big 5, needs, values, personalit 50 | #' @export 51 | 52 | watson.pi.demo <- function(creds) { 53 | print("Loading Text for Ronald Reagan Speech 1986 - Space Shuttle Challenger") 54 | text <- read.table("data/ronald_reagan_speech.txt", fill=TRUE, header=FALSE) 55 | ##I Think this is erroing out on my build - may be issue here 56 | watson.pi.analyze(creds, text[1,]) 57 | } 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /data/ronald_reagan_speech.txt: -------------------------------------------------------------------------------- 1 | Ronald Reagan -- Address to the Nation on The Space Shuttle Challenger Disaster Ronald Reagan The Space Shuttle Challenger Tragedy Address delivered 28 January 1986 Ladies and Gentlemen, I'd planned to speak to you tonight to report on the state of the Union, but the events of earlier today have led me to change those plans. Today is a day for mourning and remembering. Nancy and I are pained to the core by the tragedy of the shuttle Challenger. We know we share this pain with all of the people of our country. This is truly a national loss. Nineteen years ago, almost to the day, we lost three astronauts in a terrible accident on the ground. But we've never lost an astronaut in flight. We've never had a tragedy like this. And perhaps we've forgotten the courage it took for the crew of the shuttle. But they, the Challenger Seven, were aware of the dangers, but overcame them and did their jobs brilliantly. We mourn seven heroes: Michael Smith, Dick Scobee, Judith Resnik, Ronald McNair, Ellison Onizuka, Gregory Jarvis, and Christa McAuliffe. We mourn their loss as a nation together. For the families of the seven, we cannot bear, as you do, the full impact of this tragedy. But we feel the loss, and we're thinking about you so very much. Your loved ones were daring and brave, and they had that special grace, that special spirit that says, Give me a challenge, and I'll meet it with joy. They had a hunger to explore the universe and discover its truths. They wished to serve, and they did. They served all of us. We've grown used to wonders in this century. It's hard to dazzle us. But for twenty-five years the United States space program has been doing just that. We've grown used to the idea of space, and, perhaps we forget that we've only just begun. We're still pioneers. They, the members of the Challenger crew, were pioneers. And I want to say something to the schoolchildren of America who were watching the live coverage of the shuttle's take-off. I know it's hard to understand, but sometimes painful things like this happen. It's all part of the process of exploration and discovery. It's all part of taking a chance and expanding man's horizons. The future doesn't belong to the fainthearted; it belongs to the brave. The Challenger crew was pulling us into the future, and we'll continue to follow them. I've always had great faith in and respect for our space program. And what happened today does nothing to diminish it. We don't hide our space program. We don't keep secrets and cover things up. We do it all up front and in public. That's the way freedom is, and we wouldn't change it for a minute. We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue. I want to add that I wish I could talk to every man and woman who works for NASA, or who worked on this mission and tell them: Your dedication and professionalism have moved and impressed us for decades. And we know of your anguish. We share it. There's a coincidence today. On this day three hundred and ninety years ago, the great explorer Sir Francis Drake died aboard ship off the coast of Panama. In his lifetime the great frontiers were the oceans, and a historian later said, He lived by the sea, died on it, and was buried in it. Well, today, we can say of the Challenger crew: Their dedication was, like Drake's, complete. The crew of the space shuttle Challenger honored us by the manner in which they lived their lives. We will never forget them, nor the last time we saw them, this morning, as they prepared for their journey and waved goodbye and slipped the surly bonds of earth to touch the face of God. Thank you. Source: The Ronald Reagan Presidential Foundation 2 | -------------------------------------------------------------------------------- /R/watson.keys.R: -------------------------------------------------------------------------------- 1 | #' WatsonR - Load API Keys from KEYS.R file 2 | #' 3 | #' This Function will Load your API keys from KEYS.R file if it is in working directory 4 | #' You can create / edit this file yourself 5 | #' 6 | #' @param NONE 7 | #' @return NOTHING 8 | #' @export 9 | 10 | watson.keys.load <- function() { 11 | library(RCurl) # install.packages("RCurl") # if the package is not already installed 12 | library(httr) 13 | library(audio) 14 | library(data.table) 15 | library(dplyr) 16 | library(reshape2) 17 | library(Rtts) 18 | library(splitstackshape) 19 | library(seewave) # need to play wav back? 20 | library(stringr) 21 | library(splitstackshape) 22 | library(tidyr) 23 | library(XML) 24 | library(png) 25 | print("This Function will Load your API keys from KEYS.R file if it is in working directory here:") 26 | print(getwd()) 27 | source("R/keys.R") # this files is where you put your Access Credentials from Bluemix (username and password) 28 | # now print them to screen 29 | watson.keys.display() 30 | } 31 | 32 | 33 | #' WatsonR - Display API Key Info 34 | #' 35 | #' Displays API Keys - Empty Slots and Full Slots 36 | #' @param NONE 37 | #' @return NOTHING 38 | #' @export 39 | 40 | watson.keys.display <- function() { 41 | print("This Function Displays your Existing API Keys for the IBM Watson Services") 42 | # ALCHEMY Language -- AUTHENTICATION / CREDENTIALS - Platinum 43 | print(paste("1 - Alchemy Key: " , username_password_ALCH)) 44 | print(paste("2 - Tone Key: " , username_password_TON)) 45 | print(paste("3 - Personality Insight Key: " , username_password_PI)) 46 | print(paste("4 - NLC Key: " , username_password_NLC)) 47 | print(paste("5 - Speech to Text Key: " , username_password_STT)) 48 | print(paste("6 - Text to Speech Key: " , username_password_TTS)) 49 | print("If any are NULL or Error, you will not have luck hitting services - edit keys.R file and LOAD - or modify") 50 | } 51 | 52 | 53 | #' WatsonR - Enter API Keys Info Manually 54 | #' 55 | #' Prompts User to Enter in Keys. 56 | #' KEYS.R FILE load with watson.keys.load is alternate method 57 | #' 58 | #' @param NONE 59 | #' @return NOTHING 60 | #' @export 61 | 62 | watson.keys.enter <- function() { 63 | print("This Funtcion Helps you enter API Keys Manually for the IBM Watson Services") 64 | print("SELECT #1-6 - Which API Key TO ENTER? (Zero '0' Exits) ") 65 | 66 | print("1 - Alchemy Key") 67 | print("2 - Tone Analysis") 68 | print("3 - Personality Insight (PI)") 69 | print("4 - Natural Language Classifier (NLC)") 70 | print("5 - Speech to Text (STT)") 71 | print("6 - Text to Speech (TTS)") 72 | print("7 - Exit / Cancel") 73 | 74 | selection <- readline(prompt="Enter Selection 1-9: ") 75 | selection <- as.integer(selection) 76 | 77 | switch(selection, 78 | {username_password_ALCH <<- readline(prompt="Enter Alchemy Key: ")}, 79 | {username_TON <<- readline(prompt="Enter Tone Username: "); 80 | password_TON <<- readline(prompt="Enter Tone Password: "); 81 | username_password_TON <<- paste(username_TON,":",password_TON,sep="")}, 82 | {username_PI <<- readline(prompt="Enter PI Username: "); 83 | password_PI <<- readline(prompt="Enter PI Password: "); 84 | username_password_PI <<- paste(username_PI,":",password_PI,sep="")}, 85 | {username_NLC <<- readline(prompt="Enter NLC Username: "); 86 | password_NLC <<- readline(prompt="Enter NLC Password: "); 87 | username_password_NLC <<- paste(username_NLC,":",password_NLC,sep="")}, 88 | {username_STT <<- readline(prompt="Enter Speech to Text (STT) Username: "); 89 | password_STT <<- readline(prompt="Enter Speech to Text (STT) Password: "); 90 | username_password_STT <<- paste(username_STT,":",password_STT,sep="")}, 91 | {username_TTS <<- readline(prompt="Enter Text to Speech (TTS) Username: "); 92 | password_TTS <<- readline(prompt="Enter Text to Speech (TTS) Password: "); 93 | username_password_TTS <<- paste(username_TTS,":",password_TTS,sep="")}, 94 | {print("Exit")}) 95 | 96 | watson.keys.display() 97 | 98 | # prompt for missing keys- then write over keys.R 99 | } 100 | -------------------------------------------------------------------------------- /R/watson.nlc.R: -------------------------------------------------------------------------------- 1 | #' WatsonR - Natural Language Classifier (NLC) - CREATE 2 | #' CREATE NEW CLASSIFIER - post /v1/classifiers - 3 | #' Creates a classifier with CSV data ## URL below no "/" after base url 4 | #' 5 | #' NLC1 6 | #' @param creds the name of the credentials file in json format 7 | #' @param csvfile File of Ground Truth to Train; Name of the New Classifier 8 | #' @param classifiername The name to assign to the new classifier 9 | #' @param lang ISO standard 639 language code for classifier 10 | #' @return initial status 11 | #' @export 12 | #' 13 | watson.nlc.createnewclassifier <- function(creds, csvfile,classifiername, lang) { 14 | credentials = rjson::fromJSON(,creds) 15 | data = httr::POST(url="https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers", 16 | httr::authenticate(credentials$username,credentials$password), 17 | body = list(training_data = upload_file(csvfile), 18 | training_metadata = paste("{\"language\":\"",lang,"\",\"name\":\"",classifiername,"\"}",sep=""))) 19 | return(rjson::fromJSON(httr::content(data, "text", encoding = "UTF-8"))) 20 | } 21 | 22 | 23 | #' WatsonR - Natural Language Classifier (NLC) - LIST 24 | #' LIST ALL CLASSIFIERS AND RETURN NEAT LIST 25 | #' NLC2 26 | #' @param creds the name of the credentials file in json format 27 | #' @return LIST OF CLASSIFIERS 28 | #' @export 29 | #' 30 | watson.nlc.listallclassifiers <- function(creds){ 31 | credentials = rjson::fromJSON(,creds) 32 | username_password = paste(credentials$username,credentials$password,sep=":") 33 | base_url_nlc = "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/" 34 | data <- RCurl::getURL(base_url_nlc,userpwd = username_password ) 35 | return(rjson::fromJSON(data)) 36 | } 37 | 38 | #' WatsonR - Natural Language Classifier (NLC) - STATUS Check 39 | #' 40 | #' CHECK CLASSIFIER STATUS 41 | #' IF YOU GET MESSAGE BELOW - YOU NEED TO WAIT! 42 | #' Can take 15m for some medium size classifers (longer for larger ones) 43 | #' "The classifier instance is in its training phase, 44 | #' not yet ready to accept classify requests" 45 | #' @param creds the name of the credentials file in json format 46 | #' @param classifier_id Classifier ID 47 | #' @return Classifier Status 48 | #' @export 49 | #' 50 | watson.nlc.checkclassifierstatus <- function(creds, classifier_id) { 51 | credentials = rjson::fromJSON(,creds) 52 | username_password = paste(credentials$username,credentials$password,sep=":") 53 | 54 | base_url_nlc = "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/" 55 | data = RCurl::getURL(paste(base_url_nlc,classifier_id,sep=""),userpwd = username_password) 56 | return(rjson::fromJSON(data)) 57 | } 58 | 59 | #' WatsonR - Natural Language Classifier (NLC) - PROCESS TEXT 60 | #' ACCEPT QUERY & RETURN RESULT: classifier and confidence score from text input 61 | #' 62 | #' @param creds the name of the credentials file in json format 63 | #' @param classifier_id the classifier identification uuid 64 | #' @param query_text to Pass to Classifier 65 | #' @return Classifiers, with confidence 66 | #' @export 67 | #' 68 | watson.nlc.processtext <- function(creds, classifier_id, query_text){ 69 | credentials = rjson::fromJSON(,creds) 70 | username_password = paste(credentials$username,credentials$password,sep=":") 71 | 72 | base_url_nlc = "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/" 73 | query_text <- utils::URLencode(query_text) 74 | data <- RCurl::getURL(paste(base_url_nlc,classifier_id,"/classify","?text=", query_text,sep=""), 75 | userpwd = username_password, .encoding = 'UTF-8', .mapUnicode = TRUE) 76 | return(rjson::fromJSON(data)) 77 | } 78 | ### end of function 79 | 80 | #' WatsonR - Natural Language Classifier (NLC) - DELETE Classifier 81 | #' Receives name of Classifier to delete; May not be able to do this until training complete 82 | #' 83 | #' NLC5 84 | #' @param creds the name of the credentials file in json format 85 | #' @param kill_classifier Classifier ID 86 | #' @return Message that you've killed the classifier (but not the service) 87 | #' @export 88 | watson.nlc.deleteclassifier <- function(creds, kill_classifier) { 89 | credentials = rjson::fromJSON(,creds) 90 | base_url_nlc = "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/" 91 | httr::DELETE(url=paste(base_url_nlc,kill_classifier,sep=""), 92 | httr::authenticate(credentials$username, credentials$password)) 93 | } 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /R/watson.demo.R: -------------------------------------------------------------------------------- 1 | #' WatsonR - Demonstration of Alchemy, Personality Insights, Tone Analyzer and Natural Language Classifier 2 | #' 3 | #' Demonstrates WatsonR - Multiple APIs. Note NLC Natural Language Classifier takes time to complete training 4 | #' @param NONE 5 | #' @return NOTHING 6 | #' @export 7 | 8 | watson.demo <- function() { 9 | print("FULL Demo that will do all available services - and also train NLC with Ground truth ") 10 | 11 | ## DEMO #1 - YOUTUBE - WatsonR Package - August 17,2016 12 | 13 | #library(devtools) 14 | #load_all() 15 | #library(WatsonR) 16 | 17 | # WATSON KEYS 18 | # watson.keys.load() # pulls keys an also hammers library - consider renaming INITIALIZE 19 | # watson.keys.display() # Show What's Available with KEYS 20 | # watson.keys.enter() # Manual Entry Option 21 | 22 | # WATSON.ALCHEMY 23 | watson.alchemy.test() # Ping the service - OK? 24 | watson.alchemy.combined("I like hamburgers Kokanee beer in Raglan New Zealand") 25 | 26 | # WATSON.TONE 27 | watson.tone.demo() # speeding ticket, with optimism 28 | watson.tone.analyze("I am happy here, but not sure about next week.") # happy but tentative 29 | 30 | # WATSON.PI 31 | watson.pi.demo() # Ronald Reagan speech example 32 | suppressWarnings(watson.pi.analyze("GANDHI Says: For more than twenty years past I have been paying special attention to the question of Health. While in England, I had to make my own arrangements for food and drink, and I can say, therefore, that my experience is quite reliable. I have arrived at certain definite conclusions from that experience, and I now set them down for the benefit of my readers. As the familiar saying goes, ‘Prevention is better than cure.’ It is far easier and safer to prevent illness by the observance of the laws of health than to set about curing the illness which has been brought on by our own ignorance and carelessness. Hence it is the duty of all thoughtful men to understand aright the laws of health, and the object of the following pages is to give an account of these laws. We shall also consider the best methods of cure for some of the most common diseases.As Milton says, the mind can make a hell of heaven or a heaven of hell. So heaven is not somewhere above the clouds, and hell somewhere [Pg 2] underneath the earth! We have this same idea expressed in the Sanskrit saying, Mana êva Manushayanâm Kâranam Bandha Mokshayoh—man’s captivity or freedom is dependant on the state of his mind. From this it follows that whether a man is healthy or unhealthy depends on himself. Illness is the result not only of our actions but also of our thoughts. As has been said by a famous doctor, more people die for fear of diseases like small-pox, cholera and plague than out of those diseases themselves.Ignorance is one of the root-causes of disease. Very often we get bewildered at the most ordinary diseases out of sheer ignorance, and in our anxiety to get better, we simply make matters worse. Our ignorance of the most elementary laws of health leads us to adopt wrong remedies or drives us into the hands of the veriest quacks. How strange (and yet how true) it is that we know much less about things near at hand than things at a distance. We know hardly anything of our own village, but we can give by rote the names of the rivers and mountains of England! We take so much trouble to learn the names of the stars in the sky, while we hardly think it worth while to know the things that are in our own homes! We never care a jot for the splendid pageantry of Nature before our very eyes, while we are so anxious to witness the [Pg 3] puerile mummeries of the theatre! And in the same way, we are not ashamed to be ignorant of the structure of our body, of the way in which the bones and muscles, grow, how the blood circulates and is rendered impure, how we are affected by evil thoughts and passions, how our mind travels over illimitable spaces and times while the body is at rest, and so on. There is nothing so closely connected with us as our body, but there is also nothing perhaps of which our ignorance is so profound, or our indifference so complete.")) 33 | 34 | # WATSON.NLC 35 | NLC_name <- paste("sorting_hat_",sample(1:1000,1),sep="") 36 | watson.nlc.createnewclassifier("data/nlc_sortinghat.csv",NLC_name) 37 | watson.nlc.listallclassifiers() 38 | watson.nlc.checkclassifierstatus("7ace87x92-nlc-1514") # 39 | watson.nlc.processtextreturnclass("33fffex86-nlc-1350","nasty jerk who screams at kids") 40 | watson.nlc.deleteclassifier("33fffex86-nlc-1350") 41 | 42 | # WATSON.STT 43 | watson.stt.test() # takes FOX.WAV file STT_speech_test.wav and sends to STT for transcript 44 | watson.stt.process("media/ryan_raspberry_pi_test.wav") # bigger sample 45 | 46 | # WATSON.TTS 47 | watson.tts.listvoices() 48 | watson.tts.demovoices() 49 | watson.tts.process("My name is Julia. Cambridge is better than Oxford. Do you agree?",1) 50 | } 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /R/watson.tts.R: -------------------------------------------------------------------------------- 1 | #' WatsonR - Text to Speech (TTS) - Speechify the Transcript; demand the voice you want 2 | #' 3 | #' Text to Speech 4 | #' @param creds the name of the credentials file in json format 5 | #' @param transcript TEXT to be made into audio; 6 | #' @param voice_number Index 1-12 of Voice (see watson.tts.listvoices() for list) 7 | #' @return NOTHING 8 | #' @export 9 | 10 | watson.tts.process <- function(creds, transcript, voice_number) { 11 | credentials = rjson::fromJSON(file=creds) 12 | voice_list <- watson.tts.listvoices(creds) 13 | print("Text to Speech - Sending Transcript to TTS service....") 14 | url <- "https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize" 15 | ## transcript <- URLencode("The quick brown fox jumped over the lazy crazy dog that barked") 16 | transcript <- URLencode(transcript) 17 | voice <- "en-GB_KateVoice" # or en-US_LisaVoice 18 | filename <- "media/audio_file.wav" 19 | 20 | the_audio = RCurl::CFILE(filename, mode="wb") 21 | RCurl::curlPerform(url = paste(url,"?text=",transcript,"&voice=",voice_list[voice_number,],sep=""), 22 | userpwd = paste(credentials$username,credentials$password,sep=":"), 23 | httpheader=c(accept="audio/wav"), 24 | writedata = the_audio@ref) 25 | RCurl::close(the_audio) 26 | 27 | print("now playing the WAV file on your computer... open filename.WAV....") 28 | system(paste("open",filename,"-a vlc")) 29 | 30 | #close(the_audio) # would rather close earlier - but errored out 31 | closeAllConnections() 32 | } 33 | 34 | 35 | 36 | #' WatsonR - Text to Speech (TTS) - List Voices Available From services 37 | #' 38 | #' Text to Speech - LIst of Voices 39 | #' @param creds the name of the credentials file in json format 40 | #' @return list of voices from the TTS service 41 | #' @export 42 | 43 | watson.tts.listvoices <- function(creds) 44 | { 45 | credentials = rjson::fromJSON(file=creds) 46 | voices <- httr::GET(url=paste("https://stream.watsonplatform.net/text-to-speech/api/v1/voices"), 47 | authenticate(credentials$username,credentials$password)) 48 | data <- httr::content(voices,"text") 49 | data <- as.data.frame(strsplit(as.character(data),"name")) 50 | data <- data[-c(1:2), ] # remove dud first row 51 | data <- strsplit(as.character(data),",") 52 | data <- data.frame(matrix(data)) 53 | colnames(data) <- "V1" 54 | data <- splitstackshape::cSplit(data, 'V1', sep="\"", type.convert=FALSE) 55 | data <- data.frame(data$V1_04) 56 | data[,1] <- gsub("\\\\","",data[,1] ) 57 | return(data) 58 | } 59 | 60 | # VOICES 61 | # 1 en-GB_KateVoice 62 | # 2 ja-JP_EmiVoice 63 | # 3 en-US_AllisonVoice 64 | # 4 fr-FR_ReneeVoice 65 | # 5 it-IT_FrancescaVoice 66 | # 6 es-ES_LauraVoice 67 | # 7 de-DE_BirgitVoice 68 | # 8 es-ES_EnriqueVoice 69 | # 9 de-DE_DieterVoice 70 | # 10 en-US_LisaVoice 71 | # 11 en-US_MichaelVoice 72 | # 12 es-US_SofiaVoice 73 | 74 | 75 | #' WatsonR - Text to Speech (TTS) - Round The World Introductions - 76 | #' 77 | #' Text to Speech - LIst of Voices 78 | #' @param creds the name of the credentials file in json format 79 | #' @return Everyone Talks 80 | #' @export 81 | 82 | watson.tts.demovoices <- function(creds) 83 | { 84 | credentials = rjson::fromJSON(file=creds) 85 | t <- 3 # time delay 86 | print("en-GB_KateVoice - UK") 87 | watson.tts.process(creds,"I am Kate from the United Kingdom",1) 88 | Sys.sleep(t) 89 | print("ja-JP_EmiVoice - Japan") 90 | watson.tts.process(creds,"ho Japan. Em i",2) 91 | Sys.sleep(t) 92 | print("en-US_AllisonVoice - USA") 93 | watson.tts.process(creds,"I am Allison from Boise, Idaho",3) 94 | Sys.sleep(t) 95 | print("fr-FR_ReneeVoice - France") 96 | watson.tts.process(creds,"Bonjour! Vive la France",4) 97 | Sys.sleep(t) 98 | print("it-IT_FrancescaVoice - Italy") 99 | watson.tts.process(creds,"Ciao! Io parlo Italiano.",5) 100 | Sys.sleep(t) 101 | print("es-ES_LauraVoice - Spain") 102 | watson.tts.process(creds,"Hola, Soy Laura, Espana",6) 103 | Sys.sleep(t) 104 | print("de-DE_BirgitVoice - Germany") 105 | watson.tts.process(creds,"Deutchland. Danka. Angela Merkel",7) 106 | Sys.sleep(t) 107 | print("es-ES_EnriqueVoice - Spain") 108 | watson.tts.process(creds,"Hola, Soy Enrique. Futbol",8) 109 | Sys.sleep(t) 110 | print("de-DE_DieterVoice - Germany") 111 | watson.tts.process(creds,"Deutchland. Danka David Hasselhoff",9) 112 | Sys.sleep(t) 113 | print("en-US_LisaVoice - USA") 114 | watson.tts.process(creds,"Good Afternoon. I'm your Boss Lisa from New York City",10) 115 | Sys.sleep(t) 116 | print("en-US_MichaelVoice - USA") 117 | watson.tts.process(creds,"Hello. I am Michael the Robot, From USA",12) 118 | Sys.sleep(t) 119 | print("es-US_SofiaVoice - US Spanish") 120 | watson.tts.process(creds,"Ola! Soy Sofia. Espanol",12) 121 | Sys.sleep(t) 122 | } 123 | 124 | -------------------------------------------------------------------------------- /data/nlc_sortinghat.csv: -------------------------------------------------------------------------------- 1 | I am brave,Gryffindor, 2 | I have courage,Gryffindor, 3 | The founder of my house was Godric Gryffindor,Gryffindor, 4 | house element is fire,Gryffindor, 5 | Gryffindor values courage bravery nerve and chivalry,Gryffindor, 6 | Colors= Scarlet and Gold,Gryffindor, 7 | Lion,Gryffindor, 8 | I am bold and good,Gryffindor, 9 | Bold and good,Gryffindor, 10 | Brave and bold,Gryffindor, 11 | Chivalry,Gryffindor, 12 | Honor,Gryffindor, 13 | Bravery and courage,Gryffindor, 14 | I am loyal,Hufflepuff, 15 | I am a good friend,Hufflepuff, 16 | The founder of my house was Helga Hufflepuff,Hufflepuff, 17 | house element is earth,Hufflepuff, 18 | Hufflepuffs value hard work patience justice and loyalty,Hufflepuff, 19 | Yellow and Black,Hufflepuff, 20 | Badger,Hufflepuff, 21 | Loyal friend and helpful,Hufflepuff, 22 | Friendship,Hufflepuff, 23 | Loyalty,Hufflepuff, 24 | Hard work and patience,Hufflepuff, 25 | I am very clever,Ravenclaw, 26 | Smarts,Ravenclaw, 27 | I have a big brain,Ravenclaw, 28 | The founder of my house was Rowena Ravenclaw,Ravenclaw, 29 | house element is air,Ravenclaw, 30 | Ravenclaw values intelligence creativity learning and wit,Ravenclaw, 31 | Blue and Bronze,Ravenclaw, 32 | Eagle,Ravenclaw, 33 | Clever,Ravenclaw, 34 | Good at riddles and solving problems,Ravenclaw, 35 | Intellect,Ravenclaw, 36 | Knowledge,Ravenclaw, 37 | Big IQ,Ravenclaw, 38 | Witty,Ravenclaw, 39 | I am hungry for power,Slytherin, 40 | You-Know-Who / Voldelmort was in this house,Slytherin, 41 | The founder of my house was Salazar Slytherin ,Slytherin, 42 | element is water,Slytherin, 43 | Slytherin house values ambition and cunning,Slytherin, 44 | Colors= Green and Silver,Slytherin, 45 | Snakes,Slytherin, 46 | Power hungry,Slytherin, 47 | Ambitious and after power,Slytherin, 48 | Evil,Slytherin, 49 | Parseltongue,Slytherin, 50 | Talks to snakes,Slytherin, 51 | Nasty,Slytherin, 52 | Negative,Slytherin, 53 | Jerk,Slytherin, 54 | serpent,Slytherin, 55 | snake,Slytherin, 56 | slither,Slytherin, 57 | slippery,Slytherin, 58 | bravery,Gryffindor, 59 | courage,Gryffindor, 60 | dignity,Gryffindor,Hufflepuff 61 | patriot,Gryffindor, 62 | slimy,Slytherin, 63 | yucky,Slytherin, 64 | mean,Slytherin, 65 | bad,Slytherin, 66 | bright,Ravenclaw, 67 | IQ,Ravenclaw, 68 | intelligence,Ravenclaw, 69 | genius,Ravenclaw, 70 | bookworm,Ravenclaw, 71 | cerebral,Ravenclaw, 72 | meek,Hufflepuff, 73 | quiet,Hufflepuff, 74 | shy,Hufflepuff, 75 | brave,Gryffindor, 76 | bold,Gryffindor, 77 | steadfast,Gryffindor,Hufflepuff 78 | integrity,Gryffindor,Hufflepuff 79 | honorable,Gryffindor, 80 | good,Gryffindor, 81 | fire,Gryffindor, 82 | earth,Hufflepuff, 83 | water,Slytherin, 84 | air,Ravenclaw, 85 | Vodelmort,Slytherin, 86 | Gryffindor,Gryffindor, 87 | Hufflepuff,Hufflepuff, 88 | Slytherin,Slytherin, 89 | Ravenclaw,Ravenclaw, 90 | Griffindor,Gryffindor, 91 | Pomona Sprout,Hufflepuff, 92 | Severus Snape,Slytherin, 93 | Minerva McGonagall,Gryffindor, 94 | Euan Abercrombie,Gryffindor, 95 | Katie Bell,Gryffindor, 96 | Lavender Brown,Gryffindor, 97 | Ritchie Coote,Gryffindor, 98 | Colin Creevey,Gryffindor, 99 | Dennis Creevey,Gryffindor, 100 | Seamus Finnigan,Gryffindor, 101 | Hermione Granger,Gryffindor, 102 | Angelina Johnson,Gryffindor, 103 | Lee Jordan,Gryffindor, 104 | Andrew Kirke,Gryffindor, 105 | Neville Longbottom,Gryffindor, 106 | Natalie McDonald,Gryffindor, 107 | Mary Macdonald,Gryffindor, 108 | Cormac McLaggen,Gryffindor, 109 | Parvati Patil,Gryffindor, 110 | Jimmy Peakes,Gryffindor, 111 | Harry Potter,Gryffindor, 112 | Demelza Robins,Gryffindor, 113 | Jack Sloper,Gryffindor, 114 | Alicia Spinnet,Gryffindor, 115 | Dean Thomas,Gryffindor, 116 | Romilda Vane,Gryffindor, 117 | Fred Weasley,Gryffindor, 118 | George Weasley,Gryffindor, 119 | Ginny Weasley,Gryffindor, 120 | Percy Weasley,Gryffindor, 121 | Ron Weasley,Gryffindor, 122 | Oliver Wood,Gryffindor, 123 | Sirius Black,Gryffindor, 124 | Albus Dumbledore,Gryffindor, 125 | Rubeus Hagrid,Gryffindor, 126 | Remus Lupin,Gryffindor, 127 | Minerva McGonagall,Gryffindor, 128 | Peter Pettigrew,Gryffindor, 129 | James Potter,Gryffindor, 130 | Lily Potter (Evans),Gryffindor, 131 | Bill Weasley,Gryffindor, 132 | Charlie Weasley,Gryffindor, 133 | Arthur Weasley,Gryffindor, 134 | Molly Weasley (Prewett),Gryffindor, 135 | Hannah Abbott,Hufflepuff, 136 | Susan Bones,Hufflepuff, 137 | Eleanor Branstone,Hufflepuff, 138 | Cadwallader,Hufflepuff, 139 | Owen Cauldwell,Hufflepuff, 140 | Cedric Diggory,Hufflepuff, 141 | Justin Finch-Fletchley,Hufflepuff, 142 | Ernie Macmillan,Hufflepuff, 143 | Laura Madley,Hufflepuff, 144 | Eloise Midgeon,Hufflepuff, 145 | Zacharias Smith,Hufflepuff, 146 | Pomona Sprout,Hufflepuff, 147 | Stebbins,Hufflepuff, 148 | Summerby,Hufflepuff, 149 | Summers,Hufflepuff, 150 | Nymphadora Tonks,Hufflepuff, 151 | Kevin Whitby,Hufflepuff, 152 | Rose Zeller,Hufflepuff, 153 | Stewart Ackerley,Ravenclaw, 154 | Marcus Belby,Ravenclaw, 155 | Terry Boot,Ravenclaw, 156 | Mandy Brocklehurst,Ravenclaw, 157 | Cho Chang,Ravenclaw, 158 | Eddie Carmichael,Ravenclaw, 159 | Penelope Clearwater,Ravenclaw, 160 | Michael Corner,Ravenclaw, 161 | Roger Davies,Ravenclaw, 162 | Marietta Edgecombe,Ravenclaw, 163 | Fawcett,Ravenclaw, 164 | Filius Flitwick,Ravenclaw, 165 | Anthony Goldstein,Ravenclaw, 166 | Luna Lovegood,Ravenclaw, 167 | Padma Patil,Ravenclaw, 168 | Orla Quirke,Ravenclaw, 169 | Lisa Turpin,Ravenclaw, 170 | Avery,Slytherin, 171 | Malcolm Baddock,Slytherin, 172 | Regulus Black,Slytherin, 173 | Miles Bletchley,Slytherin, 174 | Bole,Slytherin, 175 | Millicent Bullstrode,Slytherin, 176 | Vincent Crabbe,Slytherin, 177 | Derrick,Slytherin, 178 | Marcus Flint,Slytherin, 179 | Gregory Goyle,Slytherin, 180 | Harper,Slytherin, 181 | Terence Higgs,Slytherin, 182 | Bellatrix Lestrange,Slytherin, 183 | Rabastan Lestrange,Slytherin, 184 | Rodolphus Lestrange,Slytherin, 185 | Abraxas Malfoy,Slytherin, 186 | Draco Malfoy,Slytherin, 187 | Lucius Malfoy,Slytherin, 188 | Narcissa Malfoy,Slytherin, 189 | Montague,Slytherin, 190 | Theodore Nott,Slytherin, 191 | Pansy Parkinson,Slytherin, 192 | Graham Pritchard,Slytherin, 193 | Adrian Pucey,Slytherin, 194 | Tom Marvolo Riddle,Slytherin, 195 | Horace Slughorn,Slytherin, 196 | Severus Snape,Slytherin, 197 | Vaisey,Slytherin, 198 | Urquhart,Slytherin, 199 | Warrington,Slytherin, 200 | Blaise Zabini,Slytherin, 201 | Bloody Baron,Slytherin, 202 | Fat Friar,Hufflepuff, 203 | Grey Lady,Ravenclaw, 204 | Nearly Headless Nick,Gryffindor, 205 | Godric Gryffindor,Gryffindor, 206 | Helga Hufflepuff,Hufflepuff, 207 | Rowena Ravenclaw,Ravenclaw, 208 | Salazar Slytherin,Slytherin, 209 | Gryffindor values bravery daring nerve and chivalry. Its emblematic animal is the lion and its colours are scarlet and gold.,Gryffindor, 210 | values hard work dedication patience loyalty and fair play,Hufflepuff, 211 | values intelligence knowledge and wit. Its emblematic animal is the eagle ,Ravenclaw, 212 | ambition cunning and resourcefulness,Slytherin, 213 | resourceful,Gryffindor,Slytherin 214 | smart,Gryffindor,Ravenclaw 215 | I am a good friend who has courage,Hufflepuff,Gryffindor 216 | I am ambitious and resourceful,Gryffindor,Slytherin 217 | I am a bookworm but also brave,Ravenclaw,Gryffindor 218 | I am smart and also courageous,Ravenclaw,Gryffindor 219 | I am clever and crafty,Ravenclaw,Slytherin 220 | I like to hang out with my pals,Hufflepuff,Gryffindor 221 | I fight dragons,Gryffindor, 222 | killer,Slytherin, 223 | murderer,Slytherin, 224 | easy going,Hufflepuff, 225 | Achievement striving,Gryffindor,Slytherin 226 | Activity level,Gryffindor,Slytherin 227 | Adventurousness,Gryffindor,Slytherin 228 | Agreeableness,Hufflepuff, 229 | Altruism,Hufflepuff,Gryffindor 230 | Anger,Slytherin, 231 | Anxiety,Hufflepuff, 232 | Artistic interests,Ravenclaw,Gryffindor 233 | Assertiveness,Gryffindor,Slytherin 234 | Cautiousness,Hufflepuff, 235 | Challenge,Gryffindor, 236 | Cheerfulness,Hufflepuff, 237 | Closeness,Ravenclaw, 238 | Conscientiousness,Hufflepuff, 239 | Conservation,Ravenclaw,Hufflepuff 240 | Cooperation,Hufflepuff, 241 | Curiosity,Ravenclaw, 242 | Depression,Slytherin, 243 | Dutifulness,Hufflepuff,Gryffindor 244 | Emotionality,Gryffindor, 245 | Excitement,Gryffindor,Slytherin 246 | Excitement-seeking,Gryffindor,Slytherin 247 | Extraversion,Gryffindor,Slytherin 248 | Friendliness,Hufflepuff,Gryffindor 249 | Gregariousness,Gryffindor, 250 | Harmony,Hufflepuff, 251 | Hedonism,Slytherin,Gryffindor 252 | Ideal,Gryffindor, 253 | Imagination,Ravenclaw,Gryffindor 254 | Immoderation,Slytherin, 255 | Intellect,Ravenclaw, 256 | Liberalism,Gryffindor, 257 | Liberty,Gryffindor, 258 | Love,Hufflepuff, 259 | Modesty,Hufflepuff, 260 | Morality,Gryffindor,Ravenclaw 261 | Neuroticism,Hufflepuff, 262 | Openness,Gryffindor, 263 | Openness to change,Gryffindor, 264 | Orderliness,Ravenclaw,Hufflepuff 265 | Practicality,Hufflepuff, 266 | Self-consciousness,Hufflepuff, 267 | Self-discipline,Slytherin,Gryffindor 268 | Self-efficacy,Gryffindor, 269 | Self-enhancement,Gryffindor,Slytherin 270 | Self-expression,Gryffindor, 271 | Self-transcendence,Gryffindor,Slytherin 272 | Stability,Hufflepuff, 273 | Structure,Ravenclaw, 274 | Sympathy,Hufflepuff, 275 | Trust,Gryffindor,Hufflepuff 276 | Vulnerability,Hufflepuff, 277 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WatsonR 2 | A package for R to engage Watson Developer Cloud Services 3 | Demo Video - https://www.youtube.com/watch?v=leKCMu9TrEI 4 | 5 | # Status - Feb 15, 2017 6 | added new credentials method for alchemy only. This new method is described under 'Secrets Management' below. Soon all the API will be calllable using this method. 7 | 8 | # Status - Feb 12, 2017 9 | Joe and Ryan had a short talk to synch up. (thanks Joe!) 10 | TO DO BEFORE GOOD ENOUGH FOR CRAN (Soft target March 2017) 11 | 1) Still working on better authentication 12 | 2) 4 Warnings and 3 notes when building - so need to get rid of those 13 | 14 | Some Tidy up Merged on Feb 12. 15 | 16 | 17 | 18 | # Status - Aug 23rd 19 | STATUS: STILL IN DEVELOPMENT - CAN PULL CODE - MUCH WILL WORK - BUT NOT INSTALLING CLEAN AS OF AUG 23 20 | DONE: Alchemy, Tone, Personality Insights, Speech to Text, and Text to Speech (basics); 21 | Natural Language Classifier (NLC); 22 | SOON: DEMO At Aggregate; and being less ham fisted with loading libraries & credentials; VIsion 23 | Q4: Once functionality is established across features, will code review with an R Guru and tighten up 24 | 25 | # Objective 26 | To create a WatsonR package that is available for the R Programming language that can be used by R programmers to access IBM Watson Developer Cloud (WDC) Services. 27 | https://www.ibm.com/watson/developercloud/services-catalog.html 28 | 29 | # Secret Management 30 | (JD Feb 15 2017) I am moving WatsonR away from using the watson.keys method described below. The prefered method will be to create a folder in your R project to hold files for your secrets. Each file should contain the json document from bluemix that contains your credentials for the service you want. 31 | 32 | For example, To use the alchemy API, you first need to create an alchemy instance on bluemix. Next go to the credentials tab and copy the full json document containing your credentials. 33 | 34 | Next, in RStudio or your favorite text editor, open a text file and paste the json into the file. save the file with a '.json' extension. 35 | 36 | When you call the api, one of the parameters of the call is the name of the credentials file to use to access the service. For example, to call the combined alchemy api, follow the steps above to create a credentials file and then call the method as follows: 37 | 38 | WatsonR::watson.alchemy.combined("Credentials/alchemy1.json", "I shot an elephant in my pajamas") 39 | 40 | watson.keys doesn't work correctly in the package setting so we will be deprecating that method. 41 | 42 | # watson.keys 43 | enter in keys / authenticate 44 | API keys are needed for EACH service - so building out a few ways to check and enter KEYS 45 | Free Trial here: https://console.ng.bluemix.net/ Register, Login and 46 | Step-By-Step instructions here https://dreamtolearn.com/ryan/r_journey_to_watson/43 47 | List of Services here: https://www.ibm.com/watson/developercloud/services-catalog.html 48 | (these are just the WDC services, there are heaps of other IBM Watson technologies around) 49 | 50 | > watson.keys.load() 51 | > [1] "This Function will Load your API keys from KEYS.R file if it is in working directory, then 52 | > [1] "This Function Displays your Existing API Keys for the IBM Watson Services" 53 | > watson.keys.enter() 54 | > [1] "This Funtcion Helps you enter API Keys Manually for the IBM Watson Services" 55 | > watson.keys.display() 56 | > [1] "This Function Displays your Existing API Keys for the IBM Watson Services" 57 | 58 | 59 | # watson.demo 60 | including NLC/Harry potter (needs keys, alerts if no keys in) 61 | MACRO Demo - There are a bunch of other little demos, so probably just calls them 62 | > watson.demo() 63 | > [1] "FULL Demo that will do all available services - and also train NLC with Ground truth " 64 | 65 | ________________________________________________________ 66 | 67 | # watson.alchemy 68 | https://www.ibm.com/watson/developercloud/alchemy-language.html 69 | AlchemyLanguage is a collection of APIs that offer text analysis through natural language processing. The AlchemyLanguage APIs can analyze text and help you to understand its sentiment, keywords, entities, high-level concepts and more. 70 | > watson.alchemy.test() 71 | > [1] "Short Test of Alchemy - Hitting Endpoint; 72 | > watson.alchemy.combined("I like beer in Calgary") 73 | > [1] "Alchemy combined call- running multiple Alchemy Language calls" 74 | > $docSentiment$type [1] "positive" 75 | > $entities[[1]]$text [1] "Calgary" 76 | > $taxonomy[[1]]$label [1] "/food and drink/beverages/alcoholic beverages/cocktails and beer" - etc... 77 | 78 | # watson.tone 79 | https://www.ibm.com/watson/developercloud/tone-analyzer.html 80 | Discover, understand, and revise the language tones in text. 81 | one Analyzer Service uses linguistic analysis to detect three types of tones from text: emotion, social tendencies, and language style. Emotions identified include things like anger, fear, joy, sadness, and disgust. Identified social tendencies include things from the Big Five personality traits used by some psychologists. These include openness, conscientiousness, extroversion, agreeableness, and emotional range. Identified language styles include confident, analytical, and tentative. 82 | > watson.tone.demo() 83 | > [1] "EXAMPLE: Angry and Confident person:" 84 | > [1] "I am so angry that I got a speeding ticket. I'm certain it's the last time!" 85 | > watson.tone.analyze("I hate parking tickets") 86 | > [1] "Tone Analyzer - Analyzing..." 87 | > trait signal 88 | > anger 0.88 89 | 90 | # watson.pi 91 | https://www.ibm.com/watson/developercloud/personality-insights.html 92 | Uncover a deeper understanding of people's personality characteristics, needs, and values to drive personalization. 93 | Personality Insights extracts and analyzes a spectrum of personality attributes to help discover actionable insights about people and entities, and in turn guides end users to highly personalized interactions. The service outputs personality characteristics that are divided into three dimensions: the Big 5, Values, and Needs 94 | 95 | > watson.pi.demo() 96 | > [1] "Loading Text for Ronald Reagan Speech 1986 - Space Shuttle Challenger" 97 | > [1] "Personality Insights" 98 | > trait category percentage error row 99 | > Openness personality 0.9900 0.0529 1 100 | > watson.pi.analyze("at least a hundred words here") 101 | 102 | # watson.nlc 103 | https://www.ibm.com/watson/developercloud/nl-classifier.html 104 | Interpret and classify natural language with confidence. 105 | The service enables developers without a background in machine learning or statistical algorithms to create natural language interfaces for their applications. The service interprets the intent behind text and returns a corresponding classification with associated confidence levels. The return value can then be used to trigger a corresponding action, such as redirecting the request or answering a question. 106 | THIS IS A REALLY POWERFUL SERVICE. (My fave) 107 | > watson.nlc.listallclassifiers() 108 | > classifier name date_created 109 | > 1: 340008x87-nlc-967 name sortinghat3 created 2016-08-17T080131.570Z 110 | > watson.nlc.checkclassifierstatus("7ace87x92-nlc-1514") 111 | > [1] "{\n \"classifier_id\" : \"7ace87x92-nlc-1514\",\n \"name\" : \"sorting_hat_834\",\n \"language\" 112 | > \"status_description\" : \"The classifier instance is in its training phase, not yet ready 113 | > watson.nlc.processtext("340008x87-nlc-967","bravery and zeal") 114 | > class confidence 115 | > 1: Gryffindor 0.9897621641325142 116 | > 2: Hufflepuff 0.0035370741165151928 117 | > 3: Slytherin 0.003411116817893181 118 | > 4: Ravenclaw 0.003289644933077479 119 | > watson.nlc.createnewclassifier(file,classifiername) 120 | > watson.nlc.deleteclassifier(kill_classifier_id) 121 | 122 | 123 | # watson.stt 124 | https://www.ibm.com/watson/developercloud/speech-to-text.html 125 | The Speech to Text service converts the human voice into the written word. 126 | The Speech to Text service can be used anywhere voice-interactivity is needed. The service is great for mobile experiences, transcribing media files, call center transcriptions, voice control of embedded systems, or converting sound to text to then make data searchable. Supported languages include US English, UK English, Japanese, Spanish, Brazilian Portuguese, Modern Standard Arabic, and Mandarin. The Speech to Text service now provides the ability to detect the presence of specific keywords or key phrases in the input stream. 127 | > watson.stt.test() 128 | > [1] "Speech to text Test using the speech_test.WAV Test file in the media dir" 129 | > [1] " the quick brown fox jumped over the lazy red dog " 130 | > watson.stt.process(filename) 131 | 132 | # watson.tts 133 | https://www.ibm.com/watson/developercloud/text-to-speech.html 134 | Designed for streaming low-latency synthesis of audio from written text. The service synthesizes natural-sounding speech from input text in a variety of languages and voices that speak with appropriate cadence and intonation. 135 | Brazilian Portuguese speech (1 female voice) 136 | US English speech (choose between 3 voices: 2 female, 1 male) 137 | UK English speech (1 female voice) 138 | French speech (1 female voice) 139 | German speech (choose between 2 voices: 1 female, 1 male) 140 | Japanese speech (1 female voice) 141 | Italian speech (1 female voice) 142 | Castilian Spanish speech (choose between 2 voices: 1 female, 1 male) 143 | North American Spanish speech (1 female voice) 144 | > watson.tts.demovoices() 145 | > [1] "en-GB_KateVoice - UK" 146 | > [1] "Text to Speech - Sending Transcript to TTS service...." 147 | > [1] "now playing the WAV file on your computer... open filename.WAV.... 148 | > watson.tts.listvoices() 149 | > data.V1_04 150 | > 1 en-GB_KateVoice 151 | > 2 ja-JP_EmiVoice . etc.. 152 | > watson.tts.process(transcript,voice_number) 153 | 154 | 155 | 156 | ![VIDEO DEMO](https://www.youtube.com/watch?v=hpcmyj5cT18) 157 | 158 | # R Consortium 159 | Early June 2016, IBM announced it joined the R Consortium – an open-source foundation launched by the Linux Foundation in 2015 to support the R programming language and its user community. 160 | IBM joined Microsoft and R-Studio as platinum members. 161 | R is a free programming language and software environment for statistical computing and graphics - widely used among statisticians and data miners for developing statistical software and data analysis. 162 | R provides an interactive environment for data analysis, modeling and visualization. 163 | 164 | 165 | # Other Notes 166 | 1) API KEYS ARE REQUIRED TO ACCESS EACH SERVICE- FREE 30 DAY TRIAL here: https://console.ng.bluemix.net/ 167 | 2) These are the services in this version 168 | AlchemyLanguage 169 | Natural Language Classifier 170 | Personality Insights 171 | Tone Analyzer 172 | Speech to Text 173 | Text to Speech 174 | 3) Code Was largely derived from 175 | https://github.com/rustyoldrake/R_Scripts_for_Watson and 176 | https://dreamtolearn.com/ryan/r_journey_to_watson/ projects 177 | 178 | --------------------------------------------------------------------------------