I saw very nice R script for sentiment score of each sentences, available at: sentiment.R and I was wondering, how could I replace this part
# split into words. str_split is in the stringr package
word.list = str_split(sentence, '\\s+')
# sometimes a list() is one level of hierarchy too much
words = unlist(word.list)
for matching multiple terms with pos and neg dictionaries with multiple terms. I have an example below.
I have following data.frame:
sent <- data.frame(words = c("just right size", "love this quality",
"good quality", "very good quality", "i hate this notebook",
"great improvement", "notebook is not good","notebook was"), user = c(1,2,3,4,5,6,7,8))
words user
1 just right size 1
2 love this quality 2
3 good quality 3
4 very good quality 4
5 i hate this notebook 5
6 great improvement 6
7 notebook is not good 7
8 notebook was 8
Then I have dictionaties with pos and neg words:
posWord <- c("great","improvement","love","great improvement","very good","good","right","very")
negWords <- c("hate","bad","not good","horrible")
Desired output is below:
words user SentimentScore
1 just right size 1 1
2 love this quality 2 1
3 good quality 3 1
4 very good quality 4 1
5 i hate this notebook 5 -1
6 great improvement 6 1
7 notebook is not good 7 -1
8 notebook was 8 0
How should I rewrite that code at github to have a desired output. I mean, if I use source code at github as it is, so e.g. in 4th row there'll be 2 instead of 1 in SentimentScore column.
Do anyone have any advice or similar solution for that, please. I'll appreciate any of your help. Thank you very much in advance.