首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >俄语/西里尔语情感分析文本分析

俄语/西里尔语情感分析文本分析
EN

Stack Overflow用户
提问于 2017-11-17 05:35:19
回答 1查看 964关注 0票数 0

这是一个令人难以置信的资源。我不敢相信这个平台的贡献者是如此的慷慨。我将非常感谢任何关于使用俄语/西里尔语言处理文本分析/情感分析的建议。

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

还有别的选择吗?

EN

回答 1

Stack Overflow用户

发布于 2018-02-06 20:01:05

我只是想弄清楚同样的事情:如何在西里尔语料库上运行一些情感分析。虽然你是对的,优秀的syuzhet包仍然不支持西里尔文,但我能够偷工减料地修改syuzhet的版本,它支持西里尔文!这是我使用的代码。您可以指定nrc方法和俄语语言,也可以使用自定义方法并提供您自己的俄语词典。

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

代码语言:javascript
复制
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)
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47339479

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档