Corpus
オブジェクトを R から静的ファイルにエクスポートしようとしています。コーパスには、ファイル システム内の既存の前処理済みファイルを解析することによって作成された、語幹を付けられたドキュメントが含まれています。著者は、「R でのテキスト マイニングの概要」(pp. 2) でこれを行う方法について説明し、次のように提案しています。
> writeCorpus(file)
しかし、これまでの私の試みは次のものしか得られません:
Error in UseMethod("as.PlainTextDocument", x):
no applicable method for 'as.PlainTextDocument' applied to an object of class "character"
これまでのところ、私のスクリプトは非常に単純ですが、単純な見落としである可能性が高いと思います。どんなアドバイスでも大歓迎です。それはフリンジの問題のようです。
# Turn off Java so it doesn't interfere with Weka interface
Sys.setenv(NOAWT=1)
# Load required text mining packages
require(tm)
require(rJava)
require(RWeka)
require(Snowball)
# Populate a vector with the number of subdirectories in preprocessed dir
preprocessed <- list.files(path="preprocessed_dir", include.dirs=TRUE, full.names=TRUE)
# For each element in the vector
for(i in 1:length(preprocessed)) {
# Get the files in each subdirectory by appending a number to the absolute path
files <- list.files(sprintf("preprocessed_dir/%.0f", i))
# Create a Corpus object of all the files in the subdirectory
corpora <- Corpus(VectorSource(files))
# Stem the words in the Corpus object
corpora <- tm_map(corpora, SnowballStemmer)
# (Try to) write the object to the file system
writeCorpus(corpora)
}
FWIW:呼び出しclass(corpora)
が返さ
[1] "VCorpus" "Corpus" "list"
れるため、オブジェクトは明らかにタイプではありませんcharacter