-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalyse des sentiments.R
67 lines (54 loc) · 1.76 KB
/
Analyse des sentiments.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
# Load the package
library(sentiment.ai)
library(SentimentAnalysis)
library(sentimentr)
### Espace de travail
setwd('/Users/maddi/Documents/Pubpeer project/Pubpeer explo')
library(alluvial)
library(DBI)
library(ggplot2)
library(sentimentr)
library(tidyverse)
### CONNEXION
con<-dbConnect(RPostgres::Postgres())
db <- 'SKEPTISCIENCE' #provide the name of your db
host_db <- 'localhost' # server
db_port <- '5433' # port DBA
db_user <- 'postgres' # nom utilisateur
db_password <- 'Maroua1912'
con <- dbConnect(RPostgres::Postgres(), dbname = db, host=host_db, port=db_port, user=db_user, password=db_password)
# Test connexion
dbListTables(con)
### RECUPERATION DES DONNEES
reqsql= paste('select * from commentaires_par_discipline')
text = dbGetQuery(con,reqsql)
debates <- data.frame(subset((str_replace_all((str_split(text$markdown, "'," , simplify = TRUE)), "[[:punct:]]", " ")), text != ""))
names(debates)=c("commentaires")
###
debates_with_pol <- debates %>%
get_sentences() %>%
sentiment() %>%
mutate(polarity_level = ifelse(sentiment < 0.15, "Negative",
ifelse(sentiment > 0.15, "Positive","Neutral")))
###
debates_with_pol %>% filter(polarity_level == "Negative") %>% View()
debates_with_pol %>% filter(polarity_level == "Positive") %>% View()
###
debates_with_senti %>%
ggplot() + geom_boxplot(aes(y = person, x = sentiment))
###
debates$dialogue %>%
get_sentences() %>%
sentiment_by() %>% #View()
highlight()
###
debates %>%
get_sentences() %>%
sentiment_by(by = NULL) %>% #View()
ggplot() + geom_density(aes(ave_sentiment))
###
library(sentimentr)
text = c("this video is awesom. the author is boring","I am very sad","very intersting!")
sentiment(text)
sentiment_by(text)
view(emotion(text))