This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2013.09.30 MBTI Classifier.r
104 lines (90 loc) · 2.77 KB
/
2013.09.30 MBTI Classifier.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
library(RCurl)
library(RJSONIO)
library(utils)
library(XML)
library(plyr)
library(scrapeR)
library(stringr)
#clear existing objects
rm(list=ls(all=TRUE))
#declare variables
data = data.frame()
apikey = list()
apikey$Read = "8Hqho0jaYAKORqd92TCh8vVNUI"
apikey$Write = "1xTSoZUnSiFwlEtdwI4tRiZIuww"
apicall = paste0(URLencode("http://uclassify.com/browse/prfekt/Myers Briggs Judging Function/ClassifyText"),"?")
#webpage = getURL("http://www.deltaattack.com/author/ikecube/"))
# Parse HTML and extract speech text
webpage = getURL("http://www.gamefaqs.com/gba/930370-final-fantasy-vi-advance/faqs/47016",follow=TRUE)
doc = htmlParse(webpage, asText=TRUE)
plain.text <- xpathSApply(doc, "//pre", xmlValue)
txt = paste(plain.text, collapse = "\r")
#build data frame for parsing
data = data.frame(str_locate_all(txt, "\r\n[A-Za-z]*:(\t| )?"))
#split into columns
d = data.frame(name,line)
for(i in 1:nrow(data))
{
linefeed = str_trim(str_replace_all(substr(txt,data[i,1],data[i+1,1]), "\r|\n|\t",""))
name = str_trim(substr(linefeed, 0, str_locate(linefeed,":")-1))
line = str_trim(substr(linefeed, str_locate(linefeed,":")+1,str_length(linefeed)))
newline = data.frame(name, line)
if(exists("d"))
{
d = rbind.fill(d, newline)
}
else
{
d = newline
}
}
#clear unused variables
rm(data)
rm(newline)
rm(apicall)
rm(apikey)
rm(doc)
rm(i)
rm(line)
rm(linefeed)
rm(name)
rm(namelist)
rm(plain.text)
rm(txt)
rm(webpage)
rm(charcorpus)
#get full script of a character
namelist = as.list(unique(d[1]$name))
lines = ""
for(i in 1:length(namelist))
{
namelist[7]
lines = d[d$name=="Wedge",2]
}
lines = ""
lines = d[d$name=="Kefka",2]
# build a row for each name
row = c(Name = "ike")
#Judging Function
apicall = paste0(apicall,"readkey=",apikey$Read,"&text=",URLencode(marker),"&output=json")
result = getURL(apicall)
result = fromJSON(result)
row = as.list(c(row,result$cls1))
#Attitude Function
apicall = paste0(URLencode("http://uclassify.com/browse/prfekt/Myers Briggs Attitude/ClassifyText"),"?")
apicall = paste0(apicall,"readkey=",apikey$Read,"&text=",URLencode(marker),"&output=json")
result = getURL(apicall)
result = fromJSON(result)
row = as.list(c(row,result$cls1))
#Perceiving Function
apicall = paste0(URLencode("http://uclassify.com/browse/prfekt/Myers Briggs Perceiving Function/ClassifyText"),"?")
apicall = paste0(apicall,"readkey=",apikey$Read,"&text=",URLencode(marker),"&output=json")
result = getURL(apicall)
result = fromJSON(result)
row = as.list(c(row,result$cls1))
#Lifestyle Function
apicall = paste0(URLencode("http://uclassify.com/browse/prfekt/Myers Briggs Lifestyle/ClassifyText"),"?")
apicall = paste0(apicall,"readkey=",apikey$Read,"&text=",URLencode(marker),"&output=json")
result = getURL(apicall)
result = fromJSON(result)
row = as.list(c(row,result$cls1))