Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R、 转换文件的tm错误_R_Extract_Keyword_Tm_Extraction - Fatal编程技术网

R、 转换文件的tm错误

R、 转换文件的tm错误,r,extract,keyword,tm,extraction,R,Extract,Keyword,Tm,Extraction,我想根据文本中关键字的权重创建一个网络。然后我在运行与tm_地图相关的代码时出错: library (tm) library(NLP) lirary (openNLP) text = c('.......') corp <- Corpus(VectorSource(text)) corp <- tm_map(corp, stripWhitespace) Warning message: In tm_map.SimpleCorpus(corp, stripWhitespace) :

我想根据文本中关键字的权重创建一个网络。然后我在运行与tm_地图相关的代码时出错:

library (tm)
library(NLP)
lirary (openNLP)

text = c('.......')
corp <- Corpus(VectorSource(text))
corp <- tm_map(corp, stripWhitespace)

Warning message:
In tm_map.SimpleCorpus(corp, stripWhitespace) :
transformation drops documents

corp <- tm_map(corp, tolower)

Warning message:
In tm_map.SimpleCorpus(corp, tolower) : transformation drops documents
library(tm)
图书馆(NLP)
lirary(openNLP)
text=c(“….”)

corp代码应该仍然有效。你得到的是警告,不是错误。当您使用语料库而不是VCorpus时,仅当您拥有基于矢量源的组合语料库时,此警告才会出现

原因是在底层代码中有一个检查,以查看语料库内容的名称数量是否与语料库内容的长度匹配。以矢量形式读取文本时,没有文档名称,会弹出此警告。这只是一个警告,没有文件被丢弃

请参见这两个示例之间的差异

library(tm)

text <- c("this is my text with some other text and some more")

# warning based on Corpus and Vectorsource
text_corpus <- Corpus(VectorSource(text))

# warning appears running following line
tm_map(text_corpus, content_transformer(tolower))
<<SimpleCorpus>>
Metadata:  corpus specific: 1, document level (indexed): 0
Content:  documents: 1
Warning message:
In tm_map.SimpleCorpus(text_corpus, content_transformer(tolower)) :
  transformation drops documents

# Using VCorpus
text_corpus <- VCorpus(VectorSource(text))

# warning doesn't appear
tm_map(text_corpus, content_transformer(tolower))
<<VCorpus>>
Metadata:  corpus specific: 0, document level (indexed): 0
Content:  documents: 1
tm_map(text_corpus, content_transformer(tolower))
library(tm)

text HI@phiver:非常感谢,您的回答确实回答了我的问题。请注意:a
VCorpus
是一个
易失性语料库,并且“易失性语料库完全保存在内存中,因此所有更改只影响相应的R对象”(cf.)。
library(tm)

text <- c("this is my text with some other text and some more")

# warning based on Corpus and Vectorsource
text_corpus <- Corpus(VectorSource(text))

# warning appears running following line
tm_map(text_corpus, content_transformer(tolower))
<<SimpleCorpus>>
Metadata:  corpus specific: 1, document level (indexed): 0
Content:  documents: 1
Warning message:
In tm_map.SimpleCorpus(text_corpus, content_transformer(tolower)) :
  transformation drops documents

# Using VCorpus
text_corpus <- VCorpus(VectorSource(text))

# warning doesn't appear
tm_map(text_corpus, content_transformer(tolower))
<<VCorpus>>
Metadata:  corpus specific: 0, document level (indexed): 0
Content:  documents: 1
tm_map(text_corpus, content_transformer(tolower))