如何在 R tm 包中显示语料库文本? [英] How to show corpus text in R tm package?

查看:31
本文介绍了如何在 R tm 包中显示语料库文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 R 和 tm 包的新手,所以请原谅我的愚蠢问题;-)如何在 R tm 包中显示纯文本语料库的文本?

I'm completely new in R and tm package, so please excuse my stupid question ;-) How can I show the text of a plain text corpus in R tm package?

我在一个语料库中加载了一个包含 323 个纯文本文件的语料库:

I've loaded a corpus with 323 plain text files in a corpus:

 src <- DirSource("Korpora/technologie")
corpus <- Corpus(src)

但是当我调用语料库时:

But when I call the corpus with:

corpus[[1]]

我总是得到一些这样的输出而不是语料库文本本身:

I always get some output like this instead of the corpus text itself:

<<PlainTextDocument>>
Metadata:  7
Content:  chars: 144
Content:  chars: 141
Content:  chars: 224
Content:  chars: 75
Content:  chars: 105

如何显示语料库的文本?

How can I show the text of the corpus?

谢谢!

更新可重现的示例:我已经使用内置示例文本进行了尝试:

UPDATE Reproducible sample: I've tried it with the built-in sample text:

> data("crude")
> crude
<<VCorpus>>
Metadata:  corpus specific: 0, document level (indexed): 0
Content:  documents: 20
> crude[1]
<<VCorpus>>
Metadata:  corpus specific: 0, document level (indexed): 0
Content:  documents: 1
> crude[[1]]
<<PlainTextDocument>>
Metadata:  15
Content:  chars: 527

如何打印文档的文本?

更新 2:会话信息:

> sessionInfo()
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252   
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tm_0.6-1  NLP_0.1-7

loaded via a namespace (and not attached):
[1] parallel_3.1.3 slam_0.1-32    tools_3.1.3   

推荐答案

您可以尝试将语料库文本转换为数据框,并从数据框本身访问所需的文本.我使用内置的示例数据粗略"(来自 tm 包)作为示例.

You can try converting your corpus text into a dataframe, and accessing the required text from the dataframe itself. I have used the built-in sample data "crude" (from the tm package) as an example.

data("crude")
dataframe<-data.frame(text=unlist(sapply(crude, `[`, "content")), stringsAsFactors=F)

dataframe[1,]
[1] "Diamond Shamrock Corp said that\neffective today it had cut its contract prices for crude oil by\n1.50 dlrs a barrel.\n    The reduction brings its posted price for West Texas\nIntermediate to 16.00 dlrs a barrel, the copany said.\n    \"The price reduction today was made in the light of falling\noil product prices and a weak crude oil market,\" a company\nspokeswoman said.\n    Diamond is the latest in a line of U.S. oil companies that\nhave cut its contract, or posted, prices over the last two days\nciting weak oil markets.\n Reuter"

这篇关于如何在 R tm 包中显示语料库文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆