首页 > 解决方案 > “是否有用于标记单词主题的 R 函数(文本分析)(例如:名词、形容词)?”

问题描述

我正在对情感分析进行文本挖掘。但是,当我对英文文章使用文本挖掘时,我遇到了一个问题。请问有没有类似jieba包的worker(type='tag')函数,但是在英文文本挖掘包中使用的函数(例如:tidytext)?

在下文中,它是我的代码的一部分。此代码用于中文文本挖掘。但是,我想以类似的方式进行英文文本挖掘。可以用什么函数代替worker(type="tag")的函数

library(jiebaRD)
library(jiebaR)
library(dplyr)
jieba <- worker(type="tag",user="C:/Users/User/Desktop/dict/bbb.txt",symbol = TRUE)

ecal<-function(str){
  result <- jieba <= str    
  winfront <- 1L 
  count <- 1  
  winvalue <- c()  
  posvalue <- c()  
  negvalue <-c ()  
  pvalue <- 0L     
  nvalue <- 0L    
  ppcount <- 1
  nncount <- 1
  rheflag <- FALSE
  for (i in 1:length(result)){
    if(names(result[i])=="positive"){      
      #cat("find positive word:",result[i],"\n")      
      if(i==1)
        winvalue[count] <- 1
      else{
        winvalue[count] <- 1
        for (j in (i-1):winfront) {
          if(!is.na((as.numeric(names(result[j])))))
            winvalue[count] = winvalue[count]*as.numeric(names(result[j]))
          else if(names(result[j])=="deny")
            winvalue[count] = winvalue[count]*(-1)
          else if(names(result[j])=="rhe")
            rheflag <- TRUE
        }
      }
      #cat("the value of window is:",winvalue[count],"\n")      
      count = count+1
      winfront <- i+1
    }

标签: rnlp

解决方案


您可以执行以下操作:

library(udpipe)
x <- udpipe("我拜訪了我在香港的朋友", "chinese")

请注意,如果您已经有中文分词器(例如 Jieba),您还可以使用 udpipe 使用 pos 标签丰富您的分词数据 - 请参阅https://cran.r-project 中的“我的文本数据已经分词”部分。 org/web/packages/udpipe/vignettes/udpipe-annotation.html#annotate_your_text

此处报告了基于通用依赖项的基于 Chinese-GSD 的模型的准确度统计信息:https ://github.com/jwijffels/udpipe.models.ud.2.3/blob/master/inst/udpipe-ud-2.3-181115/README 标记化不是最理想的,但是考虑到黄金标记化的 pos 标记在准确性方面非常好。


推荐阅读