我使用twitteR软件包从Twitter中提取了推文,并将它们保存到文本文件中。
我对语料库进行了以下处理
xx<-tm_map(xx,removeNumbers, lazy=TRUE, 'mc.cores=1')
xx<-tm_map(xx,stripWhitespace, lazy=TRUE, 'mc.cores=1')
xx<-tm_map(xx,removePunctuation, lazy=TRUE, 'mc.cores=1')
xx<-tm_map(xx,strip_retweets, lazy=TRUE, 'mc.cores=1')
xx<-tm_map(xx,removeWords,stopwords(english), lazy=TRUE, 'mc.cores=1')
(使用mc.cores = 1和lazy = True,否则在Mac上使用R时会遇到错误)
tdm<-TermDocumentMatrix(xx)
但是这个术语文档矩阵中有很多奇怪的符号、无意义的词语等等。 如果一个推文是
RT @Foxtel: One man stands between us and annihilation: @IanZiering.
Sharknado‚Äã 3: OH HELL NO! - July 23 on Foxtel @SyfyAU
在清理推文后,我希望只保留适当完整的英文单词,即句子/短语中不包含其他任何内容(用户名,缩写词,URL)。例如:
One man stands between us and annihilation oh hell no on
(注意:tm包中的转换命令仅能删除停用词、标点符号、空格并转换为小写)
sharknado
和foxtel
就完成了,因为它们不是“正确”的英语单词... - Marc Bxx <- tm_map(xx, content_transformer(removePunctuation)
或者xx <- tm_map(xx, content_transformer(tolower))
,您是否看到了任何改进? - RHerteltm
包的版本号。 - RHertel