forked from Hendrik147/HR_Analytics_in_R_book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
15-personality.Rmd
69 lines (53 loc) · 2.49 KB
/
15-personality.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Personality insights {#personality}
```{r personality, include=FALSE}
chap <- 16
lc <- 0
rq <- 0
# **`r paste0("(LC", chap, ".", (lc <- lc + 1), ")")`**
# **`r paste0("(RQ", chap, ".", (rq <- rq + 1), ")")`**
knitr::opts_chunk$set(
tidy = FALSE,
out.width = '\\textwidth',
fig.height = 4,
warning = FALSE
)
options(scipen = 99, digits = 3)
# Set random number generator see value for replicable pseudorandomness. Why 76?
# https://www.youtube.com/watch?v=xjJ7FheCkCU
set.seed(76)
```
The IBM Watson Personality Insights service uses linguistic analysis to extract cognitive and social characteristics from input text such as email, text messages, tweets, forum posts, and more. By deriving cognitive and social preferences, the service helps users to understand, connect to, and communicate with other people on a more personalized level.
- [Getting started guide](https://console.bluemix.net/docs/services/personality-insights/getting-started.html#getting-started-tutorial)
- [IBM's open source plotting library](https://github.com/personality-insights/sunburst-chart)
- [The ibmsunburst R documentation](https://itsalocke.com/ibmsunburst/)
- [Working with curl and personality insights](https://www.ibm.com/watson/developercloud/personality-insights/api/v3/curl.html?curl#introduction)
We can use communications from a person to analyse their personality.
```{r include=FALSE, warning=FALSE, message=FALSE}
if(!require(httr)) install.packages("httr")
if(!require(janeaustenr)) install.packages("janeaustenr")
if (!require(ibmsunburst)) install.packages("ibmsunburst")
```
We first need to be able to talk to Personality Insights. We get most of this information off the IBM site once we've made an account.
```{r eval=FALSE}
key = "aOWMNztQ_VVlz9fINhc3v67rtnJqcN6JuubQorAvhq"
url = "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13"
uname="a4a4ea65-e8e7-492c-a95e-128f10fc5f"
pword="LuFm4BELs"
```
We can then talk to the API using the `httr` package. We can send a body of text to be analysed. The guidance for the API says you should send it more than 600 words to get a robust results.
```{r eval=FALSE}
library(httr)
library(janeaustenr)
cr=POST(url,
authenticate(uname, pword),
content_type("text/plain;charset=utf-8"),
accept_json(),
body=paste(janeaustenr::emma, collapse = " ")
)
status_code(cr)
```
We can then visualise the results using the `ibmsunburst` package.
```{r eval=FALSE}
library(ibmsunburst)
ibmsunburst(content(cr), version = "v3")
```