R tm和wordcloud与西里尔文本

时间:2016-03-17 12:45:35

标签: r text-mining cyrillic word-cloud

我尝试按照一些例子在R中创建一个wordcloud。像往常一样,我遇到了一些编码问题,试图修复它们但没有成功。

这是我的代码:

library(tm)
library(wordcloud)
library(SnowballC)

articles <- Corpus (DirSource('tmp/'), readerControl = list(reader = readPlain,
                                                        language = "ru",
                                                        load = T))

articles <- tm_map(articles, iconv, 'cp1251', 'UTF-8')
articles <- tm_map(articles, stripWhitespace)
articles <- tm_map(articles, tolower)
articles <- tm_map(articles, removeNumbers)
articles <- tm_map(articles, removeWords, stopwords("russian"))
articles <- tm_map(articles, removePunctuation)
articles <- tm_map(articles, PlainTextDocument)


wordcloud(articles, random.order=F, max.words=80, 
          colors=brewer.pal(6,"Oranges"))

我没有得到任何错误,但云似乎是其他类型的编码 - 虽然有西里尔字符,但也有一些其他。 Here is the resulting wordcloud

我该如何解决这个问题?

提前谢谢!

UPD。我的输入文件是UTF-8。我想出第一个tm_map将Windows-1251转换为UTF-8,所以我将输入文件更改为1251. But nothing changed much...

0 个答案:

没有答案