我在csv文件中抓取了tripadvisor的一些内容(id、报价、评级、完整的评审),并试图过滤出只有5*评级的文档,但它似乎不起作用。
> x <- read.csv ("test.csv", header = TRUE, stringsAsFactors = FALSE)
> (corp <- VCorpus(DataframeSource (x),
+ readerControl = list(language = "eng")))我得到以下信息:
<<VCorpus>>
Metadata: corpus specific: 0, document level (indexed): 0
Content: documents: 50现在,在过滤,它显示,有0,评级为5*,这是不对的。
> idx <- meta(corp, "rating") == '5'
> corp [idx]
<<VCorpus>>
Metadata: corpus specific: 0, document level (indexed): 0
Content: documents: 0我在创建语料库时有没有忽略任何东西?
请求的文本输出
'data.frame': 682 obs. of 6 variables:
$ X : int 1 2 3 4 5 6 7 8 9 10 ...
$ id : chr "rn360260358" "rn359340351" "rn356397660" "rn355961772" ...
$ quote : chr "Nice but not unique " "Beautiful scenery of German forest with a lake" "Beautiful Lake and Amazing Mountain Views" "Beautiful!" ...
$ rating : chr "3" "5" "5" "5" ...
$ date : chr "Reviewed 5 March 2016" "Reviewed 29 February 2016" "Reviewed 27 February 2016" ...
$ reviewnospace: chr "We visited the lake with our daughters in March. All s...发布于 2016-04-15 20:21:35
您的数据导入方法根本不传递元数据。DataFrameSource(x)将x的所有变量作为文档文本传递。
此外,无论采用何种方法,在tm中添加一组元数据并不是一种简单、自动的方法。相反,我们可以使用VectorSource(x$reviewnospace) (假设这是保存文本的列),在第二步中为它分配元数据。然后,您的索引就会像预期的那样工作。
library(tm)
# use VectorSource to import data
corp <- VCorpus(VectorSource(x$reviewnospace), readerControl = list(language = "eng"))
# assign metadata
meta(corp,tag = "rating") <- x$rating
idx <- meta(corp, "rating") == '5'
corp [idx]https://stackoverflow.com/questions/36626540
复制相似问题