對豆瓣某電影進行情感分析,在計算完情感得分后所有得分均為零有沒有大神幫忙求解

情況說明:1)資料源應該不會有問題,發給別人對方可以得出結果;2)代碼問題應該也不大...因為用別人的資料可以出結果...;3)軟體:R3.6 64位
我的結果:回傳EmotionRank中的值全為0,但用別人的資料就是正常的1、2、3、4、0、-1、2······
最大的問題:就是我不知道到底哪里有問題
求大神幫助以下是代碼:
library(rJava)
library(Rwordseg)
Evaluation<-read.csv(file = file.choose(), encoding = 'UFT-8',stringsAsFactors = FALSE,quote = "")
text <- gsub('[a-zA-Z0-9]','',Evaluation$Evaluation)
#讀入肯定評價詞和否定評價詞詞庫
nwords<-readLines("D:\\檔案\\課件+報告\\專業課\\web挖掘\\正面評價詞.txt")
pwords<-readLines("D:\\檔案\\課件+報告\\專業課\\web挖掘\\負面評價詞.txt")
#資料清洗并使用串列函式將每條評論以向量的形式展示出來
x<-gsub(pattern="http:[a-zA-Z\\/\\.0-9]+","",text)
x<-gsub("\n","",text)
x<-gsub(" ","",text)
word=lapply(x=text,FUN=strsplit,"")
word
x<-segmentCN(x)
#計算情感得分
#定義getEmotionalType函式,進行情感得分計算
getEmotionalType <- function(x,pwords,nwords){
emotionType <-numeric(0)
xLen <-length(x)
emotionType[1:xLen]<- 0
index <- 1
while(index <=xLen){
yLen <-length(x[[index]])
index2 <- 1
while(index2<= yLen){
if(length(pwords[pwords==x[[index]][index2]]) >= 1){
emotionType[index] <- emotionType[index] + 1
}else if(length(nwords[nwords==x[[index]][index2]]) >= 1){
emotionType[index] <- emotionType[index] - 1
}
index2<- index2 + 1
}
#獲取進度
if(index%%100==0){
print(round(index/xLen,3))
}
index <-index +1
}
emotionType
}
#使用EmotionRank用表格的形式展示出來
EmotionRank <-getEmotionalType(x,pwords,nwords)
commentEmotionalRank <-list(rank=EmotionRank,comment=text)
commentEmotionalRank <-as.data.frame(commentEmotionalRank)
fix(commentEmotionalRank)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/51218.html
標籤:人工智能技術
