私はテキスト解析を実行するための簡単なコードを持っています。 DTMを作成する前に、私はstemCompletionを適用しています。しかし、これの出力は、私が間違っているかどうか、あるいはそれが動作する唯一の方法であるかどうか、私が理解していないものです。tm package:stemCompletion not working
私はRMY助けのこのリンクを参照している:私はここを参照してくださいtext-mining-with-the-tm-package-word-stemming
問題が生じるの後、私のDTMが収縮し、すべての(リターンのコンテンツ '「メタ」)でトークンを返さないということです
私のコードおよび出力:成功した(stemdocumentとstemcompletionの両方を)語幹を実行するには、次の出力を期待
texts <- c("i am member of the XYZ association",
"apply for our open associate position",
"xyz memorial lecture takes place on wednesday",
"vote for the most popular lecturer")
myCorpus <- Corpus(VectorSource(texts))
myCorpus <- tm_map(myCorpus, content_transformer(tolower))
myCorpus <- tm_map(myCorpus, removePunctuation)
myCorpus <- tm_map(myCorpus, removeNumbers)
removeURL <- function(x) gsub("http[[:alnum:]]*", "", x)
myCorpus <- tm_map(myCorpus, content_transformer(removeURL)) #??
myCorpusCopy <- myCorpus
myCorpus <- tm_map(myCorpus, stemDocument)
for (i in 1:4) {
cat(paste("[[", i, "]] ", sep = ""))
writeLines(as.character(myCorpus[[i]]))
}
Output:
[[1]] i am member of the xyz associ
[[2]] appli for our open associ posit
[[3]] xyz memori lectur take place on wednesday
[[4]] vote for the most popular lectur
myCorpus <- tm_map(myCorpus, stemCompletion, dictionary = myCorpusCopy)
for (i in 1:4) {
cat(paste("[[", i, "]] ", sep = ""))
writeLines(as.character(myCorpus[[i]]))
}
Output:
[[1]] content
meta
[[2]] content
meta
[[3]] content
meta
[[4]] content
meta
myCorpus <- tm_map(myCorpus, PlainTextDocument)
dtm <- DocumentTermMatrix(myCorpus, control = list(weighting = weightTf))
dtm
inspect(dtm)
Output:
> inspect(dtm)
<<DocumentTermMatrix (documents: 4, terms: 2)>>
Non-/sparse entries: 8/0
Sparsity : 0%
Maximal term length: 7
Weighting : term frequency (tf)
Terms
Docs content meta
character(0) 1 1
character(0) 1 1
character(0) 1 1
character(0) 1 1
。私は0.6のパッケージを使用しています
は助け 'stemCompletion'を読む:ここではそれがどのように動作するかです。したがって、それは、語幹の単語トークンで使用されることを意味します。 – lukeA
私はstemmed出力のみを提供しています –
あなたはそれにTextDocumentを与えます。 – lukeA