2017-01-16 23 views
0

私はテキスト解析を実行するための簡単なコードを持っています。 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のパッケージを使用しています

+0

は助け 'stemCompletion'を読む:ここではそれがどのように動作するかです。したがって、それは、語幹の単語トークンで使用されることを意味します。 – lukeA

+0

私はstemmed出力のみを提供しています –

+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