2017-01-16 13 views
0

텍스트 분석을 수행하는 간단한 코드가 있습니다. DTM을 만들기 전에 stemCompletion을 적용합니다. 그러나이 결과물은 내가 잘못하고 있든, 아니면 그것이 행동하는 유일한 길인지를 이해하지 못하는 것입니다. text-mining-with-the-tm-package-word-stemmingtm 패키지 : stemCompletion이 작동하지 않습니다.

여기를 참조 따른 후, 내 DTm을 수축 모든 (반환 '내용', '메타')에서 토큰을 반환하지 않는다는 것입니다 문제 :

나는 rmy 도움이 링크를 언급 한

내 코드와 출력 :

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 

예상 출력은 성공적으로 (stemdocument 및 stemcompletion 둘 다)에 따른 실행합니다. tm 0.6 패키지를 사용 중입니다.

+0

은 도움'stemCompletion' 읽기 : 여기 그것이 작동하는 방법입니다. 그래서 그것은 줄기가있는 단어 토큰에 사용하기위한 것입니다. – lukeA

+0

줄기 출력 만 제공합니다 –

+0

당신은 TextDocument를 제공합니다. – lukeA

답변

0

잘못된 기능을 사용하고 있습니다. "완료 될 줄기의 문자 벡터."그 첫 번째 인수로 _ _ 함수는 기대하고 형 TextDocument 아닌 객체 :

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") 
corp <- Corpus(VectorSource(texts)) 
tdm <- TermDocumentMatrix(corp, control = list(stemming = TRUE)) 
Terms(tdm) 
# [1] "appli"  "associ" "for"  "lectur" "member" "memori" "most"  "open"  
# [9] "our"  "place"  "popular" "posit"  "take"  "the"  "vote"  "wednesday" 
# [17] "xyz" 
stemCompletion(Terms(tdm), corp) 
# appli  associ   for  lectur  member  memori  most  open 
# "" "associate"  "for" "lecture" "member" "memorial"  "most"  "open" 
# our  place  popular  posit  take   the  vote wednesday 
# "our"  "place" "popular" "position"  "takes"  "the"  "vote" "wednesday" 
# xyz 
# "xyz" 
+0

stemCompletion 출력이 올바르지 않습니까? –

+0

또한 dtm이 tdm이 아니기를 바래요. 이건 바꿔 치기 할 수 있을까요? –

+0

아니요 "정확합니다"(올바른 것으로 가정 한 내용에 따라 사물과의 일치를 시도하는 것임), 예, 교환 할 수 있습니다. – lukeA

관련 문제