我一直在使用 R 的文本挖掘包,它确实是一个很棒的工具。我没有找到检索支持,或者我缺少某些功能。如何使用 R 的文本挖掘包实现一个简单的 VSM 模型?
问问题
3758 次
2 回答
1
# Sample R commands in support of my previous answer
require(fortunes)
require(tm)
sentences <- NULL
for (i in 1:10) sentences <- c(sentences,fortune(i)$quote)
d <- data.frame(textCol =sentences )
ds <- DataframeSource(d)
dsc<-Corpus(ds)
dtm<- DocumentTermMatrix(dsc, control = list(weighting = weightTf, stopwords = TRUE))
dictC <- Dictionary(dtm)
# The query below is created from words in fortune(1) and fortune(2)
newQry <- data.frame(textCol = "lets stand up and be counted seems to work undocumented")
newQryC <- Corpus(DataframeSource(newQry))
dtmNewQry <- DocumentTermMatrix(newQryC, control = list(weighting=weightTf,stopwords=TRUE,dictionary=dict1))
dictQry <- Dictionary(dtmNewQry)
# Below does a naive similarity (number of features in common)
apply(dtm,1,function(x,y=dictQry){length(intersect(names(x)[x!= 0],y))})
于 2010-11-02T16:15:17.177 回答
0
假设 VSM = 向量空间模型,您可以通过以下方式构建一个简单的检索系统:
- 创建您的收藏/语料库的文档术语矩阵
- 为您的相似性度量创建一个函数(Jaccard、Euclidean 等)。有这些功能可用的软件包。RSiteSearch 应该有助于找到它们。
- 将您的查询转换为文档术语矩阵(它将有 1 行并使用与第一步相同的字典进行映射)
- 计算与第一步的查询和矩阵的相似度。
- 对结果进行排序并选择前 n 个。
一种非 R 方法是在 PostgreSQL 中表的文本列(行是文档)上使用 GINI 索引。使用 ts_vector 查询方法,您可以拥有一个非常快速的检索系统。
于 2010-11-01T17:11:16.183 回答