问题
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