如何建立一个标签语料库(文本挖掘)

问题描述 投票:0回答:1

我试图通过挖掘所有主题标签来分析Twitter数据。我想将所有主题标签放在语料库中,并将此语料库映射到单词列表。你知道如何管理这个问题吗?这是我的数据的一个快照

这是我使用的代码,但我的DTM有100%的稀疏性问题

step1 <- strsplit(newFile$Hashtag, "#")
step2 <- lapply(step1, tail, -1)
result <- lapply(step2, function(x){
sapply(strsplit(x, " "), head, 1)
})
result2<-do.call(c, unlist(result, recursive=FALSE))
myCorpus <- tm::Corpus(VectorSource(result2)) # create a corpus

这是关于我的语料库的信息

myCorpus
  <<SimpleCorpus>>
 Metadata:  corpus specific: 1, document level (indexed): 0
 Content:  documents: 12635

还有我的DTM

<<DocumentTermMatrix (documents: 12635, terms: 6280)>>
Non-/sparse entries: 12285/79335515
Sparsity           : 100%
Maximal term length: 36
Weighting          : term frequency (tf)
r text-mining corpus topic-modeling
1个回答
0
投票

你的问题是你正在使用str_split。你应该试试:

str_extract_all("This all are hashtag #hello #I #am #a #buch #of #hashtags", "#\\S+")

As results this list:
[[1]]
[1] "#hello"    "#I"        "#am"       "#a"        "#buch"     "#of"      
[7] "#hashtags"

如果您想要的结果是数据框,请使用simplify = T

str_extract_all("This all are hashtag #hello #I #am #a #buch #of #hashtags", "#\\S+", simplify = T)

结果:

     [,1]     [,2] [,3]  [,4] [,5]    [,6]  [,7]       
[1,] "#hello" "#I" "#am" "#a" "#buch" "#of" "#hashtags"
© www.soinside.com 2019 - 2024. All rights reserved.