2017-11-20 1 views
4

R Studio를 사용하여 일부 의견을 분석하는 중입니다. 지금 tidytext 패키지의 Bing Sentiment 어휘를 사용하고 있습니다.Bing 정서 사전에 새 단어 추가 R

Bing (런타임 또는 오프라인)에 추가하려는 몇 가지 추가 단어가 있습니다. 예를 들어 나는 양성 또는 부정적 또는 다른 정서의 수준으로 그들을 추가 할 수 있습니다. 어떻게해야합니까?

답변

2

sentiment 그래서 새로운 단어를 추가하는 것은 단순히 rbind이다하는 tibble입니다 :

additional_sentiment <- tibble(word=c("verygood","verybad"), 
           sentiment=c("positive","negative")) 

new_sentiment <- get_sentiments("bing")%>% 
        rbind(additional_sentiment) 

tail(new_sentiment) 
# A tibble: 6 x 2 
     word sentiment 
    <chr>  <chr> 
1 zenith positive 
2  zest positive 
3 zippy positive 
4 zombie negative 
5 verygood positive 
6 verybad negative 

joined <- austen_books() %>% 
    unnest_tokens(word, text) %>% 
    left_join(new_sentiment) 

head(joined[!is.na(joined$sentiment),]) 
# A tibble: 6 x 3 
       book  word sentiment 
       <fctr>  <chr>  <chr> 
1 Sense & Sensibility respectable positive 
2 Sense & Sensibility  good positive 
3 Sense & Sensibility advanced positive 
4 Sense & Sensibility  death negative 
5 Sense & Sensibility  great positive 
6 Sense & Sensibility  loss negative