Quiero detener los documentos en un Corpus de documentos de texto sin formato con el paquete tm en R. Cuando aplico la función SnowballStemmer a todos los documentos del corpus, solo la última palabra de cada documento es derivadoSnowball Stemmer solo se deriva de la última palabra
library(tm)
library(Snowball)
library(RWeka)
library(rJava)
path <- c("C:/path/to/diretory")
corp <- Corpus(DirSource(path),
readerControl = list(reader = readPlain, language = "en_US",
load = TRUE))
tm_map(corp,SnowballStemmer) #stemDocument has the same problem
Creo que está relacionado con la forma en que se leen los documentos en el corpus. Para ilustrar esto con algunos ejemplos sencillos:
> vec<-c("running runner runs","happyness happies")
> stemDocument(vec)
[1] "running runner run" "happyness happi"
> vec2<-c("running","runner","runs","happyness","happies")
> stemDocument(vec2)
[1] "run" "runner" "run" "happy" "happi" <-
> corp<-Corpus(VectorSource(vec))
> corp<-tm_map(corp, stemDocument)
> inspect(corp)
A corpus with 2 text documents
The metadata consists of 2 tag-value pairs and a data frame
Available tags are:
create_date creator
Available variables in the data frame are:
MetaID
[[1]]
run runner run
[[2]]
happy happi
> corp2<-Corpus(DirSource(path),readerControl=list(reader=readPlain,language="en_US" , load=T))
> corp2<-tm_map(corp2, stemDocument)
> inspect(corp2)
A corpus with 2 text documents
The metadata consists of 2 tag-value pairs and a data frame
Available tags are:
create_date creator
Available variables in the data frame are:
MetaID
$`1.txt`
running runner runs
$`2.txt`
happyness happies
¿No es Rstem la interfaz R de Snowball? Por lo tanto, debe library (Rstem) y probar tm_map (corp, wordStem). –
Gracias por el comentario. Lo intenté y los resultados fueron los mismos. Incluiré un mejor ejemplo anterior para ilustrar el problema un poco más. – Christian