convert from plural to singular using R

╄→尐↘猪︶ㄣ 提交于 2020-01-02 09:19:39

问题


How to convert plural text into singular from corpus using R i am tring with "tm" package but i am not able to find any function. i have try with this function but this i can not apply to the corpus.

aggregate.plurals <- function (v) {
  aggro_fen <- function(v, singular, plural) {

    if (! is.na(v[plural])) {
      v[singular] <- v[singular] + v[plural]
      v <- v[-which(names(v) == plural)]
    }
    return(v)
  }
  for (n in names(v)) {
    n_pl <- paste(n, 's', Sep='')
    v <- aggro_fen(v, n, n_pl)
    n_pl <- paste(n, 'es', Sep='')
    v <- aggro_fen(v, n, n_pl)
  }
  return(v)
}

回答1:


If you are doing text analysis you might be looking for word conversion in a broader context than only singular - plural. That would be stemming and you can use the 'stemDocument' function from 'SnowballC' directly on tm corpus with 'tm_map' function

reut21578 <- system.file("texts", "crude", package = "tm")
reuters <- VCorpus(DirSource(reut21578, mode = "binary"), readerControl = list(reader = readReut21578XMLasPlain))
tm_map(reuters, stemDocument)

source: tm introduction paper https://cran.r-project.org/web/packages/tm/vignettes/tm.pdf



来源:https://stackoverflow.com/questions/50171715/convert-from-plural-to-singular-using-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!