简体   繁体   English

R中的tm_map错误消息

[英]tm_map error message in R

I can create a corpus in R but when I try to apply tm_map functions to it I get the following error message: 我可以在R中创建一个语料库,但是当我尝试对其应用tm_map函数时,出现以下错误消息:

Error in UseMethod("as.PlainTextDocument", x) : no applicable method for 'as.PlainTextDocument' applied to an object of class "c('PlainTextDocument', 'TextDocument', 'character')" UseMethod(“ as.PlainTextDocument”,x)中的错误:没有适用于'as.PlainTextDocument'的适用方法应用于类“ c('PlainTextDocument','TextDocument','character')”的对象

The code up to that point is: 到目前为止的代码是:

setwd("C:/…/Documents/TextMining")
webtextGoogle <- GoogleNewsSource("Greek shipping")
GreekShippingContent <- WebCorpus(GoogleNewsSource("Greek shipping"))
writeCorpus(GreekShippingContent, "C:/…/Documents/TextMining", filenames = paste(seq_along(GreekShippingContent), ".txt", sep=""))
GreekShippingContent0 <- Corpus(DirSource("C:/…/Documents/TextMining"), list(reader = readPlain))
GreekShippingContent2 <- tm_map(GreekShippingContent0, as.PlainTextDocument)

I have looked in the documentation and explanations of what this means in related contexts but I cannot understand what to do (not a developer). 我已经查看了文档和相关上下文中的含义的解释,但是我不知道该怎么做(不是开发人员)。 Can anyone correct the code? 任何人都可以更正代码吗? I have learned a lot by example. 我从榜样中学到了很多。 Thanks. 谢谢。

This is a shot in the dark because you haven't conveyed the problem in a minimal way. 这是一个黑暗的镜头,因为您没有以最小的方式传达问题。 I'd suggest to make changes in your question with code tags rather than as comments. 我建议使用代码标签而不是注释来更改您的问题。 This works: 这有效:

library(tm)

GreekShippingContent <- "The Greek administration is coming under increasing pressure over it foot-dragging regarding its meeting international convention deadlines, especially when it relies on classification societies as an Recognised Organisation (RO) on its behalf. " 
GreekShippingContent0 <-  Corpus(VectorSource(GreekShippingContent))
tm_map(GreekShippingContent0, PlainTextDocument)

You'll have to do some leg work and apply to your situation. 您将不得不做一些腿部工作,并适应您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM