【发布时间】:2014-11-09 21:00:41
【问题描述】:
我在 CSV 文件中有 10 行文本数据。我想纠正各种拼写错误。例如单词“battery”(拼写错误为“battere”或“batt”等)。我考虑使用 StemDocument 后跟 stemCompletion,因此使用了以下代码:
library(tm)
library(SnowballC)
text.var<-read.csv("C:\\Users\\Sambit\\Desktop\\Sample Data.csv",header=FALSE)
data_corp<-Corpus(VectorSource(text.var))
data_corp.copy<-data_corp
data_corp<-tm_map(data_corp, stemDocument)
data_corp<-tm_map(data_corp, stemCompletion, dictionary=data_corp.copy)
但是,最后一步,即 Stem Completion 步骤显示以下错误:
Error in setNames(if (length(n)) n else rep(NA, length(x)), x) :
'names' attribute [10] must be the same length as the vector [2]
In addition: Warning messages:
1: In grep(sprintf("^%s", w), dictionary, value = TRUE) :
argument 'pattern' has length > 1 and only the first element will be used
2: In grep(sprintf("^%s", w), dictionary, value = TRUE) :
argument 'pattern' has length > 1 and only the first element will be used
我哪里可能出错了?
【问题讨论】:
-
试试这个解决方法:stackoverflow.com/a/26696490/1036500
-
它最有效。感谢那。但在一种情况下,“battery”被拼写为“batteri”;并且它的 StemCompletion 给出 NA;而“batter”被正确识别为“bettery”。有什么建议吗?
-
不太确定,似乎拼写错误与原始单词差异太大,以至于词干没有用处。如果您知道所有拼写错误的单词以及它们应该是什么,您可以尝试使用字典方法
-
其实“batteri”这个词在词干后没有变化;这就是它不受 StemCompletion 影响的原因。我想知道为什么:/
标签: r text-mining