gpt4 book ai didi

tm - R : find most frequent group of words in corpus

转载 作者:行者123 更新时间:2023-12-01 01:00:46 25 4
gpt4 key购买 nike

有没有一种简单的方法如何不仅可以找到最常用的术语,还可以在 R 的文本语料库中找到表达式(所以不止一个单词,单词组)?

使用 tm 包,我可以找到最常见的术语,如下所示:

tdm <- TermDocumentMatrix(corpus)
findFreqTerms(tdm, lowfreq=3, highfreq=Inf)

我可以使用 findAssocs() 找到与最常用词相关的词函数,所以我可以手动对这些词进行分组。但是我怎样才能找到这些词组在语料库中出现的次数呢?

谢谢

最佳答案

如果我没记错的话,您可以使用weka构建一个Bigrams的TermDocumentMatrix(2个总是一起出现的词),然后根据需要处理它们

library("tm") #text mining
library("RWeka") # for tokenization algorithms more complicated than single-word


BigramTokenizer <- function(x) NGramTokenizer(x, Weka_control(min = 2, max = 2))

tdm <- TermDocumentMatrix(corpus, control = list(tokenize = BigramTokenizer))

# process tdm
# findFreqTerms(tdm, lowfreq=3, highfreq=Inf)
# ...

tdm <- removeSparseTerms(tdm, 0.99)
print("----")
print("tdm properties")
str(tdm)
tdm_top_N_percent = tdm$nrow / 100 * topN_percentage_wanted

或者,
#words combinations that occur at least once together an at most 5 times
wmin=1
wmax = 5

BigramTokenizer <- function(x) NGramTokenizer(x, Weka_control(min = wmin, max = wmax))

有时,为了获得“更好”的词组,先进行词干提取会有所帮助。

关于tm - R : find most frequent group of words in corpus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23655694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com