Last active
April 21, 2017 17:05
-
-
Save viveknarang/a9758f8254f7806f24c53e710d12012b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################### | |
####################### DA: Assignment A7 ######################### | |
########################################### Vivek Narang ########## | |
# Start # | |
# Importing required libraries # | |
library(readr) | |
library(stringr) | |
library(sentimentr) | |
# Reading the text file containing text from the Universal Declaration of Human Rights # | |
mystring <- read_file("C:\\A7.txt") | |
# Removing \r from string # | |
mystring2 <- str_replace_all(mystring, "\r", " ") | |
# Removing \n from string # | |
mystring3 <- str_replace_all(mystring2, "\n", " ") | |
# Removing 'Article' from string # | |
mystring4 <- str_replace_all(mystring3, "Article", "") | |
for(i in seq(0, 6, by = 2)) { | |
for(j in seq(0, 4, by = 2)) { | |
y <- sentiment(mystring4, n.before=i, n.after=j, amplifier.weight=1) | |
write(paste("(n.before=", i, ", n.after=",j,"): ",mean(y$sentiment), sep="") , stdout()) | |
} | |
} | |
##################################################################### | |
# Inference: | |
# The mean of the sentiment value is positive across all combinations | |
# Increasing n.before is increasing means while increasing n.after | |
# is decreasing the mean values. The overall positive number from | |
# sentiment analysis tells us that there is an overall positive tone | |
# in the text. The n.before is a parameter which configures how many | |
# words to look for before the polarized word during the analysis. | |
# The n.after parameter configures the number of words to use after | |
# the polarized word. With n.before increasing there is a general | |
# increase in the mean sentiment values, however with the increase in | |
# n.after values the mean is decreasing for each n.before value. | |
##################################################################### | |
# End # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment