-
Notifications
You must be signed in to change notification settings - Fork 3
/
scratchpad_character_cartridges.r
179 lines (135 loc) · 5.01 KB
/
scratchpad_character_cartridges.r
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
######################################################
### Character Cartridges - Experimental Code and Scratch Pad
### Focus: PERSONALITY
### https://dreamtolearn.com/ryan/cognitivewingman/18/en
### https://github.com/rustyoldrake/Character-Cartridges-Embodied-Identity
######################################################
library(RCurl) # install.packages("RCurl"xx) # if the package is not already installed
library(httr)
library(data.table)
library(dplyr)
library(reshape2)
library(stringr)
library(splitstackshape)
library(tidyr)
library(XML)
library(ggplot2)
library(png)
library(jpeg)
library(grid)
######### Housekeeping And Authentication
setwd("/Users/ryan/Code/Character_Cartridges") # Set working Directory
getwd()
source("keys.r") ## KEYS has acutal username:password for each IBM service. Seperate R file looks sort of like below
# Load in the CSV of the nearly 200 traits and types
human_traits_types <- read.csv("anthropomorphic_model_v4.csv",header=TRUE)
head(human_traits_types)
######################################################
######################################################
## Base URLs for IBM Watson APIs
base_url_NLC = "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/"
getURL(base_url_NLC,userpwd = username_password_NLC ) # non essential , but checks if working /authenticated
##### NLC ##### NLC ##### NLC ##### NLC ##### NLC
source("nlc_functions.r")
watson.NLC.listallclassifiers() # TEST
### TONE
source("tone_functions.r")
process_data_to_tone("radness is greatness") # TEST
# LOAD UP THREE CHARACTER CARTRIDGES ### DATA SOURCE
characters <- read.csv2("characters_input_basic_traits.csv", header = TRUE, sep = ",")
characters
names <- characters[ (characters$trait == "name"), ]
names
characters <- characters[ (characters$value %in% c(1:100)), ] # kills rows with non numeric values
characters
characters$value <- as.numeric(paste(characters$value))
characters
# sum(characters$value)
# Improt 3 images
img1<-readPNG("image_muskstark.png")
img1 <- rasterGrob(img1, interpolate=TRUE)
img2<-readPNG("image_jkoprah.png")
img2 <- rasterGrob(img2, interpolate=TRUE)
img3<-readPNG("image_halkitt.png")
img3 <- rasterGrob(img3, interpolate=TRUE)
#plot(img3)
#rasterImage(img3,0,0,5,100)
## Set the Table
plot.new()
#layout(matrix(1:9,3,3))
layout(matrix(1:4,2,2))
layout.show(1) # one at a time
#plot(img3)
#layout.show(9)
#plot(0, xaxt = 'n', yaxt = 'n', bty = 'n', ylab = '', xlab = '')
#barplot(img3)
## Colors for our emotions
identity_colors <<- c("violet", "orange", "yellow", "white", "deepskyblue","lawngreen", "blue")
emotion_colors <<- c("red", "violet", "yellow", "green", "blue","orange", "orange", "yellow", "lawngreen", "deepskyblue","violet","forestgreen","deeppink1")
## Set the Table
plot.new()
layout(matrix(1:9,3,3))
layout.show(9) # one at a time
for (i in 1:max(characters$id))
{
print(i)
data <- characters[ which(characters$id == i), ]
#print(newdata)
## IDENTITY PLOT ##
#plot(i, type='n', main=paste("Agent ",i,"- State"), xlab="x", ylab="y")
barplot(data$value, col = identity_colors,
main=paste("ID ",i," ",names$value[i],"- State"),
ylim=c(0,100),
xlab="",
names.arg=data$trait,
border="black",
las=2, srt=45)
# generic for now - but tune for identity later (sensitivity)
response_tone <- response_raw[1:13,]
response_tone
response_tone$signal <- response_tone$signal*100
## OBSERVATION PLOT ##
barplot(response_tone$signal, col = emotion_colors,
main=paste("ID ",i," ",names$value[i],"- Observation"),
ylim=c(0,100),
xlab="",
names.arg=response_tone$trait,
border="black",
las=2, srt=45)
barplot(0)
#plot(i, type='n', main=paste("Agent ",i,"- Observations"), xlab="x", ylab="y")
}
# CHARACTER STATE - IDENTITY
personality_state <- response_raw[1:13,]
personality_state
response_tone$signal <- response_tone$signal*100
barplot(response_tone$signal, col = emotion_colors,
main=paste("Agent ",i,"- State"),
xlab="",
names.arg=response_tone$trait,
border="black",
las=2, srt=45)
## Change this from sample to sample to see the characters observing change
text <- "I'm so happy and totally confident it's gonna be rad"
response_raw <- process_data_to_tone(text)
response_raw
# CHARACTER STATE - IDENTITY
personality_state <- response_raw[1:13,]
personality_state
response_tone$signal <- response_tone$signal*100
barplot(response_tone$signal, col = emotion_colors,
main="1 - Current Emotional State",
xlab="",
names.arg=response_tone$trait,
border="black",
las=2, srt=45)
# SPOTLIGHT - Tone, Language and Social Big 5
response_tone <- response_raw[1:13,]
response_tone
response_tone$signal <- response_tone$signal*100
barplot(response_tone$signal, col = emotion_colors,
main="1 - Current Emotional State",
xlab="",
names.arg=response_tone$trait,
border="black",
las=2, srt=45)