2016-04-06 9 views
1

Ich möchte ein TDM aus einem Text mit bestimmten Sätzen (zwei oder mehr Wörter kombiniert) anstelle von einzelnen Wörtern erstellen. Die Sätze könnten zum Beispiel "climate change", "global worming", "lad use" usw. sein. Die Beispiele, die ich gesehen habe, sind alle mit einzelnen Wörtern.Text Mining in R

tabela = DocumentTermMatrix(textolimpo, 
     list(dictionary = c("climate change","global worming","land use"))) 

Ich schätze, wenn mir jemand helfen könnte.

Prost.

Rafael

Antwort

2

Ich empfehle quanteda:

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 
+3

globale Entwurmung ist das, was in Tremors passiert? – rawr