首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R中的文本挖掘

R中的文本挖掘
EN

Stack Overflow用户
提问于 2016-04-07 04:38:11
回答 1查看 81关注 0票数 1

我想创建一个TDM文本与特定的句子(两个或更多的单词组合),而不是单个单词。例如,句子可以是"climate change""global worming""lad use"等。我看到的例子都是单个单词。

代码语言:javascript
复制
tabela = DocumentTermMatrix(textolimpo,
         list(dictionary = c("climate change","global worming","land use")))

如果有人能帮我,我将不胜感激。

干杯。

拉斐尔

EN

回答 1

Stack Overflow用户

发布于 2016-04-07 04:50:45

我推荐quanteda

代码语言:javascript
复制
library(quanteda)
textolimpo <- c("This climate change concerns me. This climate changes", "Wormed: global worming increased")
(dfm <- dfm(textolimpo, 
           ngrams=2L,
           dictionary = list(climate="climate_change",
                             warm="global_worming"), 
           valuetype = "regex"))
# 2 x 2 sparse Matrix of class "dfmSparse"
#        features
# docs    climate warm
#   text1       2    0
#   text2       0    1
(dfm <- dfm(textolimpo, 
            ngrams=2L, 
            thesaurus = list(climate="climate_change",
                             warm="global_worming"), 
            valuetype = "regex"))
# 2 x 8 sparse Matrix of class "dfmSparse"
#       this_climate change_concerns concerns_me me_this wormed_global worming_increased CLIMATE WARM
# text1            2               1           1       1             0                 0       2    0
# text2            0               0           0       0             1                 1       0    1
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36461869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档