首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用tm分析tripadvisor的内容

用tm分析tripadvisor的内容
EN

Stack Overflow用户
提问于 2016-04-14 14:43:26
回答 1查看 149关注 0票数 0

我在csv文件中抓取了tripadvisor的一些内容(id、报价、评级、完整的评审),并试图过滤出只有5*评级的文档,但它似乎不起作用。

代码语言:javascript
复制
> x <- read.csv ("test.csv", header = TRUE, stringsAsFactors = FALSE)   
> (corp <- VCorpus(DataframeSource (x),  
+  readerControl = list(language = "eng")))

我得到以下信息:

代码语言:javascript
复制
<<VCorpus>>
Metadata:  corpus specific: 0, document level (indexed): 0
Content:  documents: 50

现在,在过滤,它显示,有0,评级为5*,这是不对的。

代码语言:javascript
复制
> idx <- meta(corp, "rating") == '5'

> corp [idx]

<<VCorpus>>
Metadata:  corpus specific: 0, document level (indexed): 0
Content:  documents: 0

我在创建语料库时有没有忽略任何东西?

请求的文本输出

代码语言:javascript
复制
'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...
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-15 20:21:35

您的数据导入方法根本不传递元数据。DataFrameSource(x)x的所有变量作为文档文本传递。

此外,无论采用何种方法,在tm中添加一组元数据并不是一种简单、自动的方法。相反,我们可以使用VectorSource(x$reviewnospace) (假设这是保存文本的列),在第二步中为它分配元数据。然后,您的索引就会像预期的那样工作。

代码语言:javascript
复制
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]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36626540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档