コーパスを指定すると、単語のステミングとステム補完のためにRにtm (Text Mining) packageを使用して、正規化する必要がありますが、stemCompletionステップには0.6.xバージョンのパッケージに問題があります。 tm 0.6-2でR 3.3.1を使用する。StemCompletionとPlainTextDocumentを呼び出すR
この質問は以前に尋ねられましたが、実際に動作する完全な回答は見られませんでした。問題を適切に示すための完全なコードは次のとおりです。ここで
require(tm)
txt <- c("Once we have a corpus we typically want to modify the documents in it",
"e.g., stemming, stopword removal, et cetera.",
"In tm, all this functionality is subsumed into the concept of a transformation.")
myCorpus <- Corpus(VectorSource(txt))
myCorpus <- tm_map(myCorpus, content_transformer(tolower))
myCorpus <- tm_map(myCorpus, removePunctuation)
myCorpusCopy <- myCorpus
# *Removing common word endings* (e.g., "ing", "es")
myCorpus <- tm_map(myCorpus, stemDocument, language = "english")
# Next, we remove all the empty spaces generated by isolating the
# word stems in the previous step.
myCorpus <- tm_map(myCorpus, content_transformer(stripWhitespace))
tdm <- TermDocumentMatrix(myCorpus, control = list(wordLengths = c(3, Inf)))
print(tdm)
print(dimnames(tdm)$Terms)
が出力されます。
<<TermDocumentMatrix (terms: 19, documents: 2)>>
Non-/sparse entries: 20/18
Sparsity : 47%
Maximal term length: 9
Weighting : term frequency (tf)
[1] "all" "cetera" "concept" "corpus" "document"
[6] "function" "have" "into" "modifi" "onc"
[11] "remov" "stem" "stopword" "subsum" "the"
[16] "this" "transform" "typic" "want"
用語のいくつかは食い止められている: "MODIFI"、 "remov"、 "subsum"、 "typic"、および "ONC"。
次に、ステミングを完了します。この段階で
myCorpus = tm_map(myCorpus, stemCompletion, dictionary=myCorpusCopy)
、コーパスは、もはやTextDocumentではないとTermDocumentMatrixを作成すると、エラーで失敗します(DOC、「TextDocument」)を継承TRUEではありません。次に関数PlainTextDocument()
を適用することが文書化されています。ここで
myCorpus <- tm_map(myCorpus, PlainTextDocument)
tdm <- TermDocumentMatrix(myCorpus, control = list(wordLengths = c(3, Inf)))
print(tdm)
print(dimnames(tdm)$Terms)
が出力されます。
<TermDocumentMatrix (terms: 2, documents: 2)>>
Non-/sparse entries: 4/0
Sparsity : 0%
Maximal term length: 7
Weighting : term frequency (tf)
[1] "content" "meta"
コーパスを破損したPlainTextDocument
を呼び出します。
ステム付きの単語が完成することを期待してください。 "modifi" => "修飾子"、 "onc" => "once"など
[Rの警告は、stemCompletionとTermDocumentMatrixのエラーで警告されます](http://stackoverflow.com/questions/30321770/r-warning-in-stemcompletion-and-error-in-termdocumentmatrix) –
前述のように質問では、この質問は繰り返されましたが、完全な回答は見られず、より多くの場合、質問は完全に自己完結型ではありませんでした(例:テキストファイルを読み込みました)。 – JasonM1
http://stackoverflow.com/questions/25206049/stemcompletion-is-not-working –