-
Notifications
You must be signed in to change notification settings - Fork 0
/
pas pbl.R
75 lines (44 loc) · 1.36 KB
/
pas pbl.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
library(tm)
library(wordcloud)
library(syuzhet)
reviews <- read.csv(file.choose(),header = T)
str(reviews)
corpus <- iconv(reviews$text)
corpus <- Corpus(VectorSource(corpus))
inspect(corpus[1:5])
corpus <- tm_map(corpus, tolower)
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, removeNumbers)
corpus <- tm_map(corpus, removeWords, stopwords("english"))
corpus <- tm_map(corpus, removeWords, c("book","read","life"))
corpus <- tm_map(corpus, stripWhitespace)
inspect(corpus[1:5])
reviews_final <- corpus
tdm <- TermDocumentMatrix(reviews_final)
tdm <- as.matrix(tdm)
tdm[1:10, 1:5]
w <- rowSums(tdm)
w <- subset(w, w>=300)
barplot(w, las = 2,col = "blue")
w <- sort(rowSums(tdm),decreasing = T)
set.seed(8000)
wordcloud(words = names(w),
freq = w,
max.words = 50,
random.order = T,
min.freq = 5,
colors = brewer.pal(25,"Dark2"),
scale = c(3,0.3))
sentiment_data <- iconv(reviews$text)
s <- get_nrc_sentiment(sentiment_data)
s[1:10,]
s$score <- s$positve - s$negative
s[1:10,]
write.csv(x = s,file ="C:/Users/admin/Desktop/Final_score2.csv")
review_score <- colSums(s[,])
print(review_score)
barplot(colSums(s),
las = 2,
col = rainbow(10),
ylab = 'Count',
main = 'Sentiment')