-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_Rhistory
127 lines (127 loc) · 6.46 KB
/
_Rhistory
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
install.packages("syuzhet")
library(twitteR)
library(ROAuth)
library(plyr)
library(dplyr)
library(stringr)
library(ggplot2)
library(httr)
library(wordcloud)
library(RCurl)
library(syuzhet)
oauth_endpoint(authorize = "https://api.twitter.com/oauth" , access = "https://api.twitter.com/oauth/access_token")
download.file(url = "http://curl.haxx.se/ca/cacert.pem" , destfile = "cacert.pem")
reqURL <- 'https://api.twitter.com/oauth/request_token'
accessURL <- 'https://api.twitter.com/oauth/access_token'
authURL <- 'https://api.twitter.com/oauth/authorize'
consumerKey = "D57e41bCCKX8AwILpQbj5GTmk"
consumerSecret = "RQ0ws6puGWKq7OQMJ8gqucKyl1FXYez7xhpC5Uj1WLoaEIwRJn"
accesstoken = "962001620727771136-482ck4DcQ44eYulYCGtnuhqUrdzjDvk"
accesssecret = "CpAtdB8Fryot85hp1rsXJVvt7ZLctnEupDDuTEsiPnCtx"
Cred <- OAuthFactory$new(consumerKey=consumerKey , consumerSecret = consumerSecret , requestURL=reqURL , accessURL=accessURL, authURL=authURL)
Cred$handshake(cainfo = system.file('CurlSSL' , 'cacert.pem' , package = 'RCurl'))
6486828
Cred$handshake(cainfo = system.file('CurlSSL' , 'cacert.pem' , package = 'RCurl'))
save(Cred, file = 'twitter authentication.Rdata')
load('twitter authentication.Rdata')
setup_twitter_oauth(consumer_key = consumerKey , consumer_secret = consumerSecret , access_token = accesstoken , access_secret = access_secret)
setup_twitter_oauth(consumer_key = consumerKey , consumer_secret = consumerSecret , access_token = accesstoken , access_secret = accesssecret)
some_tweets = searchTwitter("trump" , n=20, since = 2017-12-01 , lang = "en")
some_tweets = searchTwitter("trump" , n=20, since = "2017-12-01" , lang = "en")
install.packages("sentimentr")
Cred <- OAuthFactory$new(consumerKey = consumerKey ,
consumerSecret = consumerSecret ,
requestURL = reqURL ,
accessURL = accessURL ,
authURL = authURL)
Cred <- OAuthFactory$new(consumerKey = consumerKey ,
consumerSecret = consumerSecret ,
requestURL = reqURL ,
accessURL = accessURL,
authURL = authURL)
Cred$handshake(cainfo = system.file('CurlSSL' , 'cacert.pem' , package = 'RCurl'))
save(Cred, file = 'twitter authentication.Rdata')
load('twitter authentication.Rdata')
setup_twitter_oauth(consumer_key = consumerKey , consumer_secret = consumerSecret , access_token = accesstoken , access_secret = accesssecret)
consumerKey = "D57e41bCCKX8AwILpQbj5GTmk"
consumerSecret = "RQ0ws6puGWKq7OQMJ8gqucKyl1FXYez7xhpC5Uj1WLoaEIwRJn"
accesstoken = "962001620727771136-1HaBpIqN6R4i9th7iXa30iZO3SfVACC"
accesssecret = "zZ6MkCGraJueoeuMeE9Yj7MxIbD6KREt3FRCvGVijXOLi"
setup_twitter_oauth(consumer_key = consumerKey , consumer_secret = consumerSecret , access_token = accesstoken , access_secret = accesssecret)
Cred <- OAuthFactory$new(consumerKey = consumerKey ,
consumerSecret = consumerSecret ,
requestURL = reqURL ,
accessURL = accessURL,
authURL = authURL)
Cred$handshake(cainfo = system.file('CurlSSL' , 'cacert.pem' , package = 'RCurl'))
load('twitter authentication.Rdata')
setup_twitter_oauth(consumer_key = consumerKey , consumer_secret = consumerSecret , access_token = accesstoken , access_secret = accesssecret)
some_tweets = searchTwitter("trump" , n=20, since = "2017-12-01" , lang = "en")
some_tweets
some_tweets = searchTwitter("trump" , n=2000, since = "2017-12-01" , lang = "en")
setwd("C:/Users/HP/Desktop/thss")
library(twitteR)
library(ROAuth)
library(plyr)
library(dplyr)
library(stringr)
library(ggplot2)
library(httr)
library(wordcloud)
library(RCurl)
library(syuzhet)
library(tm)
library(sentimentr)
library(SentimentAnalysis)
oauth_endpoint(authorize = "https://api.twitter.com/oauth" , access = "https://api.twitter.com/oauth/access_token")
download.file(url = "http://curl.haxx.se/ca/cacert.pem" , destfile = "cacert.pem")
reqURL <- 'https://api.twitter.com/oauth/request_token'
accessURL <- 'https://api.twitter.com/oauth/access_token'
authURL <- 'https://api.twitter.com/oauth/authorize'
consumerKey = "D57e41bCCKX8AwILpQbj5GTmk"
consumerSecret = "RQ0ws6puGWKq7OQMJ8gqucKyl1FXYez7xhpC5Uj1WLoaEIwRJn"
accesstoken = "962001620727771136-1HaBpIqN6R4i9th7iXa30iZO3SfVACC"
accesssecret = "zZ6MkCGraJueoeuMeE9Yj7MxIbD6KREt3FRCvGVijXOLi"
Cred <- OAuthFactory$new(consumerKey = consumerKey ,
consumerSecret = consumerSecret ,
requestURL = reqURL ,
accessURL = accessURL,
authURL = authURL)
Cred$handshake(cainfo = system.file('CurlSSL' , 'cacert.pem' , package = 'RCurl'))
save(Cred, file = 'twitter authentication.Rdata')
load('twitter authentication.Rdata')
setup_twitter_oauth(consumer_key = consumerKey , consumer_secret = consumerSecret , access_token = accesstoken , access_secret = accesssecret)
some_tweets = searchTwitter("cryptocurrency" ,n = 500 , since = "2018-03-17" , until="2018-03-18" , lang = "en" )
some_tweets
length.some_tweets <- length(some_tweets)
length.some_tweets
some_tweets.df <- ldply(some_tweets , function(t) t$toDataFrame())
write.csv(some_tweets.df , "rawtweetsmar17-18.csv")
some_txt = sapply(some_tweets, function(x) x$getText())
some_txt1 = gsub("(RT|via)((?:\\b\\W*@\\w+)+)", "",some_txt)
some_txt2 = gsub("http[^[:blank:]]+", "",some_txt1)
some_txt3 = gsub("@\\w+","",some_txt2)
some_txt4 = gsub("[[:punct:]]", " ",some_txt3)
some_txt5 = gsub("[^[:alnum:]]"," ",some_txt4)
write.csv(some_txt5, "tweetsmar17-18.csv")
some_txt6 <- Corpus(VectorSource(some_txt5))
some_txt6 <- tm_map(some_txt6, removePunctuation)
some_txt6 <- tm_map(some_txt6, content_transformer(tolower))
some_txt6 <- tm_map(some_txt6, removeWords, stopwords("english"))
some_txt6 <- tm_map(some_txt6, stripWhitespace)
pal <- brewer.pal(8, "Dark2")
wordcloud(some_txt6, min.freq = 5, max.words = Inf ,width=1000, height=1000, random.order = FALSE , color=pal)
get_nrc_sentiment("I bought an iPhone a few days ag0. It is such a nice phone, although a little large. The touch screen is cool. The voice quality is clear too. I simply love it!")
mysentiment <- get_nrc_sentiment(some_txt5)
SentimentScores <- data.frame(colSums(mysentiment[,]))
names(SentimentScores) <- "Score"
SentimentScores <- cbind("sentiment" = rownames(SentimentScores), SentimentScores)
rownames(SentimentScores) <- NULL
ggplot(data = SentimentScores, aes(x = sentiment, y= Score)) + geom_bar(aes(fill = sentiment),stat = "identity")+ theme(legend.position = "none")+ xlab("Sentiment")+ylab("Score")+ggtitle("Total Sentiment Score Based On Tweets")
write.csv(SentimentScores,"sentimar17-18.csv")
sentiment <-analyzeSentiment(some_txt5)
write.csv(convertToBinaryResponse(sentiment)$SentimentQDAP , "binarylabel.csv")
documents <- c(some_txt5)
sentimentnum <- analyzeSentiment(documents)
sentimentnum$SentimentQDAP
source('C:/Users/HP/Desktop/thesis.R')