Это предупреждение появляется только тогда, когда вы используете content_transformer
для создания собственной определенной функции. И это появляется только тогда, когда у вас есть корпус на основе VectorSource
.
Причина в том, что в базовом коде есть проверка, чтобы увидеть, соответствует ли количество имен содержимого корпуса длине содержимого корпуса. При чтении текста в виде вектора имена документов отсутствуют, и появляется это предупреждение. И это только предупреждение, никаких документов не было сброшено.
См. Следующие примеры:
text <- c("this is my text with a forward slash / and some other text")
library(tm)
toSpace <- content_transformer(function (x , pattern ) gsub(pattern, " ", x))
text <- c("this is my text with a forward slash / and some other text")
text_corpus <- Corpus(VectorSource(text))
inspect(text_corpus)
<<SimpleCorpus>>
Metadata: corpus specific: 1, document level (indexed): 0
Content: documents: 1
[1] this is my text with a forward slash / and some other text
# warning appears here
text_corpus <- tm_map(text_corpus, toSpace, "/")
inspect(text_corpus)
<<SimpleCorpus>>
Metadata: corpus specific: 1, document level (indexed): 0
Content: documents: 1
[1] this is my text with a forward slash and some other text
Вы можете видеть, что в text_corpus нет имен с помощью следующей команды:
names(content(text_corpus))
NULL
Если вы не хотите, чтобы это предупреждение появлялось, вам нужно создать data.frame и использовать его в качестве источника с DataframeSource
.
text <- c("this is my text with a forward slash / and some other text")
doc_ids <- c(1)
df <- data.frame(doc_id = doc_ids, text = text, stringsAsFactors = FALSE)
df_corpus <- Corpus(DataframeSource(df))
inspect(df_corpus)
# no warning appears
df_corpus <- tm_map(df_corpus, toSpace, "/")
inspect(df_corpus)
names(content(df_corpus))
"1"