西里尔语R中的情感分析

西里尔语R中的情感分析,r,nlp,R,Nlp,我无法在我找到函数的页面上发表评论 在我看来,你的函数并没有在你的文本中找到任何情感词。这可能与您正在使用的情感词典有关。而不是试图修复这个函数,你可能想考虑一个整洁的方法代替,这是在书中概述。优点是它不介意西里尔字母,而且它很容易理解和调整 首先,我们需要一本具有情感价值的词典。我在上面找到了一个,我们可以直接读入R: library(rvest) library(stringr) library(tidytext) library(dplyr) dict <- readr::read

我无法在我找到函数的页面上发表评论


在我看来,你的函数并没有在你的文本中找到任何情感词。这可能与您正在使用的情感词典有关。而不是试图修复这个函数,你可能想考虑一个整洁的方法代替,这是在书中概述。优点是它不介意西里尔字母,而且它很容易理解和调整

首先,我们需要一本具有情感价值的词典。我在上面找到了一个,我们可以直接读入R:

library(rvest)
library(stringr)
library(tidytext)
library(dplyr)

dict <- readr::read_csv("https://raw.githubusercontent.com/text-machine-lab/sentimental/master/sentimental/word_list/russian.csv")
库(rvest)
图书馆(stringr)
图书馆(tidytext)
图书馆(dplyr)

dict@MauritsEvers,安装了dplyr,udpipe和tidystopwords可以处理俄语。但要获得nrc/afinn这样的情绪分数,你必须发现自己是俄罗斯人。
> mysentiment <- get_sentiment_rus(as.character(corpus))
 Show Traceback

 Rerun with Debug
 Error in UseMethod("filter_") : 
  no applicable method for 'filter_' applied to an object of class "NULL" 
> SentimentScores <- data.frame(colSums(mysentiment[,]))
> SentimentScores
             colSums.mysentiment.....
anger                               0
anticipation                        0
disgust                             0
fear                                0
joy                                 0
sadness                             0
surprise                            0
trust                               0
negative                            0
positive                            0
library(rvest)
library(stringr)
library(tidytext)
library(dplyr)

dict <- readr::read_csv("https://raw.githubusercontent.com/text-machine-lab/sentimental/master/sentimental/word_list/russian.csv")
brexit <- "https://ru.wikipedia.org/wiki/%D0%92%D1%8B%D1%85%D0%BE%D0%B4_%D0%92%D0%B5%D0%BB%D0%B8%D0%BA%D0%BE%D0%B1%D1%80%D0%B8%D1%82%D0%B0%D0%BD%D0%B8%D0%B8_%D0%B8%D0%B7_%D0%95%D0%B2%D1%80%D0%BE%D0%BF%D0%B5%D0%B9%D1%81%D0%BA%D0%BE%D0%B3%D0%BE_%D1%81%D0%BE%D1%8E%D0%B7%D0%B0" %>% 
  read_html() %>% 
  html_nodes("body") %>% 
  html_text() %>%
  tibble(text = .)
brexit_tidy <- brexit %>%
  unnest_tokens(output = "paragraph", input = "text", token = "paragraphs") %>% 
  mutate(id = seq_along(paragraph)) %>% 
  unnest_tokens(output = "word", input = "paragraph", token = "words")
# apply dictionary
brexit_sentiment <- brexit_tidy %>% 
  inner_join(dict, by = "word")

head(brexit_sentiment)
#> # A tibble: 6 x 3
#>      id word         score
#>   <int> <chr>        <dbl>
#> 1     7 затяжной      -1.7
#> 2    13 против        -5  
#> 3    22 популярность   5  
#> 4    22 против        -5  
#> 5    23 нужно          1.7
#> 6    39 против        -5
# group sentiment by paragraph
brexit_sentiment %>% 
  group_by(id) %>% 
  summarise(sentiment = mean(score))
#> # A tibble: 25 x 2
#>       id sentiment
#>    <int>     <dbl>
#>  1     7     -1.7 
#>  2    13     -5   
#>  3    22      0   
#>  4    23      1.7 
#>  5    39     -5   
#>  6    42      5   
#>  7    43     -1.88
#>  8    44     -3.32
#>  9    45     -3.35
#> 10    47      1.7 
#> # … with 15 more rows