在 R 中从语料库中搜索已删除的文档

searching for deleted documents from corpus in R

我想在分析之前预处理我的文本

我的数据

   Production of banners 1,2x2, Cutting
Production of a plate with the size 2330 * 600mm
Delivery
















Placement of advertising information on posters 0.85 * 0.65 at Ordzhonikidze Street (TSUM) -Gerzen, side A2 April 2014
Manufacturing of a banner 3,7х2,7
Placement of advertising information on the prismatron 3 * 4 at 60, Ordzhonikidze, Aldjonikidze Street, A (01.12.2011-14.12.2011)
Placement of advertising information on the multipanel 3 * 12 at Malygina-M.Torez street, side A, (01.12.2011-14.12.2011)
Designer services
41526326

12
Mounting and rolling of the RIM on the prismatron 3 * 6

代码

 mydat=read.csv("C:/kr_csv.csv", sep=";",dec=",")

  tw.corpus <- Corpus(VectorSource(mydat$descr))
  tw.corpus <- tm_map(tw.corpus, removePunctuation)
  tw.corpus <- tm_map(tw.corpus, removeNumbers)
  tw.corpus = tm_map(tw.corpus, content_transformer(tolower))
  tw.corpus = tm_map(tw.corpus, stemDocument)


#deleting emptu documents 

doc.m <- DocumentTermMatrix(tw.corpus)


rowTotals <- apply(doc.m , 1, sum) #Find the sum of words in each Document
doc.m.new   <- doc.m[rowTotals> 0, ]  

1. 我如何知道在预处理过程中被删除的观察数量(例如第一、第二文本被删除)? 2.如何从原始数据集 (mydat) 中删除这些观测值?

在 pre-processing 和词干化语料库之后,您正在计算每个文档中剩余的单词数。当然,其中没有单词的 "documents" 的计数为零。另外,只有字母和标点符号的文件也是空的,因为你删除了那些字符串。

在您的数据中,有许多 "documents" 行是空行。总共,你的语料库中有 28 "documents",但其中超过一半是空行(即它们包含零个单词)。

您为 rowTotals 中的每个文档计算 word-count。如果您检查 rowTotals 中的哪些条目等于零,您将获得随后从 doc.m:

中删除的文档编号
rowTotals
# 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 
# 3  5  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 10  2  8  8  2  0  0  0  7 

您可以看到文档 4、5、6、7、8、9、10、11、12、13 等都包含零个单词,因此不存在于 doc.m 中。您可以使用 which():

自动获取这些数字
which( rowTotals == 0)
# [1] 4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 25 26 27