TermDocumentMatrix的'dictionary'参数在R

时间:2019-09-11 07:39:49

标签: r text-mining term-document-matrix

即使我按照下面的代码在“字典”中添加了关键字,它也不会从句子中提取出来。

示例代码

library(tm)

data = c('a', 'a b', 'c')
keyword = c('a', 'b')

data = VectorSource(data)
corpus = VCorpus(data)
tdm = TermDocumentMatrix(corpus, control = list(dictionary = keyword))

我上面的代码的结果

inspect(tdm)

<<TermDocumentMatrix (terms: 2, documents: 3)>>
Non-/sparse entries: 0/6
Sparsity           : 100%
Maximal term length: 1
Weighting          : term frequency (tf)
Sample             :
Docs
Terms 1 2 3
    a 0 0 0
    b 0 0 0

正常结果如下:

Terms 1 2 3
    a 1 1 0
    b 0 1 0

1 个答案:

答案 0 :(得分:0)

您必须将最小字长传递给npm run build serve -s build termFreq

control