3

我已经使用 R 来挖掘推文,并且得到了推文中使用频率最高的词。然而,最常见的词是这样的:

 [1] "cant"     "dont"     "girl"     "gonna"    "lol"      "love"    
 [7] "que"      "thats"    "watching" "wish"     "youre"  

我正在寻找文本中的趋势、名称和事件。我想知道是否有办法从语料库中删除这种短信风格的词(例如,想要,想要,...)?他们有停用词吗?任何帮助,将不胜感激。

4

1 回答 1

4

文本挖掘包维护它自己的停用词列表,并提供有用的工具来管理和总结这种类型的文本。

假设您的推文存储在向量中。

library(tm)
words <- vector_of_strings
corpus <- Corpus(VectorSource(words))
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, function(x) tolower(x))
corpus <- tm_map(corpus, function(x) removeWords(x, 
                stopwords()))

您可以将最后一行与您自己的停用词列表一起使用():

stoppers <- c(stopwords(), "gonna", "wanna", "lol", ... ) 

不幸的是,您必须生成自己的“文本消息”或“互联网消息”停用词列表。

但是,您可以通过向 NetLingo ( http://vps.netlingo.com/acronyms.php )借用一点作弊

library(XML)
theurl <- "http://vps.netlingo.com/acronyms.php"
h <- htmlParse(theurl)
h <- getNodeSet(h,"//ul/li/span//a")
stoppers <- sapply(h,xmlValue)
于 2012-11-26T08:05:54.390 回答