我正在对德国客户评论进行情绪分析,并希望实施否定处理。我决定在“not”之后的单词和“not”之前的单词中都添加前缀“neg_”(这对英语可能没有意义,但对德语来说却有意义)。
我已经找到了如何使用此函数将前缀“_neg”添加到“not”之后的单词中:
addprefix <-function(text){
words<-unlist(strsplit(text, " "))
negative <- grepl("\\<not\\>",words,ignore.case=T)
negate <- append(FALSE,negative)[1:length(words)]
words[negate==T]<- paste0("neg_",words[negate==T])
words<-paste(words,collapse=" ")
}
是否有可能在“not”之前的单词中也添加前缀“_neg”?所以评论最初是这样的:
> str_negate("I did not like the product")
[1] "I did not like the product"
目前这个:
> str_negate("I did not like the product")
[1] "I did not neg_like the product"
到最后:
> str_negate("I did not like the product")
[1] "I neg_did not neg_like the product"
任何帮助,将不胜感激。谢谢!