I want to do an analysis of the moods of German tweets. The code I use works fine with English, but when I load the German word list, all scores just vanish. As far as I can guess, this should be relevant to the various structures of word lists. Therefore, I need to know how to adapt my code to the structure of the German vocabulary list. Can someone take a look at both lists?
English word
list German word list
pos.words = scan("~/positive-words.txt",what='character', comment.char=';')
neg.words = scan("~/negative-words.txt",what='character', comment.char=';')
score.sentiment = function(sentences, pos.words, neg.words, .progress='none')
{
require(plyr)
require(stringr)
scores = laply(sentences, function(sentence, pos.words, neg.words)
{
sentence = gsub('[[:punct:]]', '', sentence)
sentence = gsub('[[:cntrl:]]', '', sentence)
sentence = gsub('\\d+', '', sentence)
sentence = tolower(sentence)
word.list = str_split(sentence, '\\s+')
words = unlist(word.list)
pos.matches = match(words, pos.words)
neg.matches = match(words, neg.words)
pos.matches = !is.na(pos.matches)
neg.matches = !is.na(neg.matches)
score = sum(pos.matches) - sum(neg.matches)
return(score)
},
pos.words, neg.words, .progress=.progress )
scores.df = data.frame(score=scores, text=sentences)
return(scores.df)
}
sample = c("ich liebe dich. du bist wunderbar","I hate you. Die!");sample
test.sample = score.sentiment(sample, pos.words, neg.words);test.sample
source
share