2013-02-27 6 views
4

Corpus 개체를 R에서 정적 파일로 내보내려고합니다. 이 코퍼스에는 파일 시스템에서 기존의 사전 처리 된 파일을 구문 분석하여 생성 된 형태소 분석 문서가 들어 있습니다. (. 2 쪽)를 저자는R에서 TM에서 코퍼스 내보내기

> writeCorpus(file) 

을 제안, 'R에서 광업을 텍스트로 소개'자신이 할 수있는 방법을 설명하지만 내 시도는 지금까지 단 다음 얻을 :

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

+1

실제 형태소 분석은 형태소 분석을하기 전에 'Corpus' 클래스 객체 인 것처럼 보입니다. 그런 다음 형태가있는 ('writeCorpus'로 쓸 수없는) 문자 형 객체가됩니다. 강제 변환 방법 조사 그것은 다시 코퍼스 객체로 돌아갑니다! –

+2

괜찮 았어, 나는 n00b 그래서 내 자신의 질문에 대답 할 수 없지만, 여기있다 : 'tm'는'tm_map'에 의해'문자'객체'로 불린'코퍼스'객체를 던집니다. '> corpora <- Corpus (VectorSource (corpora))를 호출하여 파일 시스템에 파일을 쓸 수있게하려면 먼저 'Corpus' 객체로 강제 변환해야합니다. –

+0

해당 디렉토리는 어떤 디렉토리에 기록됩니까? –

답변

0

당신이 코퍼스를 내보낼 왜 wordering 오전 분명히 아니다. 다른 사람들에게 텍스트를 보여주고 싶다면, 단순히 텍스트를 사용할 수 있습니다.

R로 다시 내보내고 싶다면, save() 함수를 사용하여 자료를 .RData로 저장하는 것이 좋습니다.

로드하려면로드() 함수 만 사용하면됩니다.

관련 문제