0

在 Personality Insight 分析期间,最后一个代码不起作用并出现错误消息“未提供编码:默认为 UTF-8”。显示。我不明白我应该解决哪一点...非常感谢您的帮助。

#### FUNCTION TO TIDY UP THE PI RESPONSE TO TABLE FORMAT - some rough 
methods that can be improved below
tidyResponse <- function(data) 
{
  data <- as.data.frame(strsplit(as.character(data),"\"id\":\""))
  data <- data[-c(1:5), ] # remove dud first row
  data <- data.frame(matrix(data)) 
  data[,1]  <- gsub("\"","",data[,1] ) 
  data <- data.frame(do.call('rbind', 
  strsplit(as.character(data$matrix.data),',',fixed=TRUE)))
  data <- data[!grepl('name:',data$X5),]
  data <- data[!grepl('children:',data$X5),]
  data <- data[,-c(2,6), ] # remove columns we dont need - duplicates or 
  dont care for SAMPLING ERROR (now) but mght later
  rownames(data) <- NULL # resets row names to remove 'gaps'
  data$row <- as.numeric(rownames(data))
  return(data)
}

########## FUNCTION - ScreenScrape support Clean up Response from HTML to 
DOC.TXT (import speeches)
cleanDoc <- function(doc) 
{
  doc <- gsub("<.*?>", "", doc)
  doc <- gsub("\\t","",doc)
  doc <- gsub("\\n","",doc)
  doc <- gsub("\\r","",doc)
  doc <- gsub("\\t","",doc)
  doc <- gsub("\\n","",doc)
  doc <- gsub("\\r","",doc)
  doc <- gsub("&nbsp;","",doc)
  doc <- gsub("&quot;","",doc)
  return(doc)
}

getwd()
speeches <- read.csv("watson_data.csv",header=TRUE)
speeches <- data.frame(watson_data)
speeches
length <- dim(watson_data)[1]+0  # how long is our list?
for (i in 1:length) 



{
  doc <- watson_data
  doc <- cleanDoc(doc)
  response <- watson.personality_insights.analyze(doc)
  data <- content(response,style= "text") # here are the personality 
  insights!
  data <- tidyResponse(data)
  alldata <- rbind(alldata,data)
} # this part does not work, and shows the error message "No encoding 
supplied: defaulting to UTF-8."
4

0 回答 0