Case description: 1) should be no problem, the data source, to each other can the results of others; 2) code problem should also not... Because in someone else's data can be the result... ; 3) software: R3.6 64
My results: returns the value of the EmotionRank is 0, but with someone else's data is normal,2,3,4,0 1, 1, 2,...,
Is the biggest problem: I don't know exactly where there are problems help great god
The following is the code:
The library (rJava)
The library (Rwordseg)
Evaluation<- read. CSV (file=file. Choose (), encoding='UFT - 8, stringsAsFactors=FALSE, quote="")
The text & lt; - gsub (' [a zA - Z0-9] ', ' ', Evaluation $Evaluation)
# should be able to read the words and negative evaluation thesaurus
Nwords<- readLines (" D: \ \ documents \ \ specialized courses in courseware + report \ \ \ \ \ \ positive word web mining. TXT ")
Pwords<- readLines (" D: \ \ documents \ \ specialized courses in courseware + report \ \ \ \ \ \ negative word web mining. TXT ")
# data cleaning and use function will list each comments displayed in the form of a vector
X<- gsub (pattern="HTTP: [a zA - Z \ \/\ \. 0-9] +", "", the text)
X<- gsub (" \ n ", "", the text)
X<- gsub (" ", "", the text)
The word=lapply (x=text, FUN=strsplit, "")
Word
X<- segmentCN (x)
# calculation emotional score
# define getEmotionalType function, emotional score calculated
GetEmotionalType & lt; - the function (x, pwords, nwords) {
EmotionType & lt; - numeric (0)
XLen & lt; - length (x)
EmotionType [1: xLen] <0
The index & lt; 1
While (index & lt;={xLen)
YLen & lt; [[index]] - length (x)
Index2 & lt; 1
While (index2 & lt;={yLen)
If (length (pwords [[[index]] pwords==x [index2]]) & gt;=1) {
EmotionType [index] <- emotionType [index] + 1
} else if (length (nwords [[[index]] nwords==x [index2]]) & gt;=1) {
EmotionType [index] <- emotionType [index] - 1
}
Index2 & lt; - index2 + 1
}
# get progress
If (index % %==0 100) {
Print (round (index/xLen, 3))
}
The index & lt; - index + 1
}
EmotionType
}
# use EmotionRank shown in the form of table
EmotionRank & lt; - getEmotionalType (x, pwords, nwords)
CommentEmotionalRank & lt; - the list (rank=EmotionRank, comment=text)
CommentEmotionalRank & lt; - the as. The data frame (commentEmotionalRank)
Fix (commentEmotionalRank)