用俄语/西里尔语写的情感分析文本分析

时间:2017-11-16 21:35:19

标签: r text-mining sentiment-analysis cyrillic

这是一个令人难以置信的资源。我无法相信平台的贡献者是多么慷慨。 对于使用俄语/西里尔语进行文本分析/情感分析的任何建议,我将不胜感激。

Syuzhet是我的首选工具 - 获得8种情绪以及消极和正极性情绪的机会非常突出。但是,我不认为它支持西里尔语。

还有其他选择吗?

1 个答案:

答案 0 :(得分:0)

我只想弄清楚同样的事情:如何对西里尔语语料库进行一些情绪分析。虽然你是对的,优秀的syuzhet包仍然不支持西里尔语,但我能够巧妙地修改syuzhet的修改版本!这是我使用的代码。您可以指定nrc方法和俄语语言,或者您可以使用自定义方法并提供您自己的俄语词典(如果有的话)。

希望这会有所帮助;你的里程可能会有所不同!

get_sentiment_rus <- function(char_v, method="custom", lexicon=NULL, path_to_tagger = NULL, cl = NULL, language = "english") {
  language <- tolower(language)
  russ.char.yes <- "[\u0401\u0410-\u044F\u0451]"
  russ.char.no <- "[^\u0401\u0410-\u044F\u0451]"

    if (is.na(pmatch(method, c("syuzhet", "afinn", "bing", "nrc", 
                             "stanford", "custom")))) 
    stop("Invalid Method")
  if (!is.character(char_v)) 
    stop("Data must be a character vector.")
  if (!is.null(cl) && !inherits(cl, "cluster")) 
    stop("Invalid Cluster")
  if (method == "syuzhet") {
    char_v <- gsub("-", "", char_v)
  }
  if (method == "afinn" || method == "bing" || method == "syuzhet") {
    word_l <- strsplit(tolower(char_v), "[^A-Za-z']+")
    if (is.null(cl)) {
      result <- unlist(lapply(word_l, get_sent_values, 
                              method))
    }
    else {
      result <- unlist(parallel::parLapply(cl = cl, word_l, 
                                           get_sent_values, method))
    }
  }
  else if (method == "nrc") {
#    word_l <- strsplit(tolower(char_v), "[^A-Za-z']+")
    word_l <- strsplit(tolower(char_v), paste0(russ.char.no, "+"), perl=T)
    lexicon <- dplyr::filter_(syuzhet:::nrc, ~lang == tolower(language), 
                              ~sentiment %in% c("positive", "negative"))
    lexicon[which(lexicon$sentiment == "negative"), "value"] <- -1
    result <- unlist(lapply(word_l, get_sent_values, method, 
                            lexicon))
  }
  else if (method == "custom") {
#    word_l <- strsplit(tolower(char_v), "[^A-Za-z']+")
    word_l <- strsplit(tolower(char_v), paste0(russ.char.no, "+"), perl=T)
    result <- unlist(lapply(word_l, get_sent_values, method, 
                            lexicon))
  }
  else if (method == "stanford") {
    if (is.null(path_to_tagger)) 
      stop("You must include a path to your installation of the coreNLP package.  See http://nlp.stanford.edu/software/corenlp.shtml")
    result <- get_stanford_sentiment(char_v, path_to_tagger)
  }
  return(result)
}