Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.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 消除句子中的胡言乱语_R_Text Mining - Fatal编程技术网

R 消除句子中的胡言乱语

R 消除句子中的胡言乱语,r,text-mining,R,Text Mining,在文本清理过程中,是否可以检测并删除句子中的此类垃圾: x <- c("Thisisaverylongexample and I was to removeitnow", "thisisjustjunk but I do I remove it") 但是,我越是回顾我的数据框架,我发现更多的句子与这种类型的垃圾。如何使用诸如regex之类的工具来检测和删除包含此类垃圾内容的行 如果“垃圾”可以通过其不寻常的长度检测到,您可以相应地定义规则。例如,如果要删除10个或更多字符的单词,这将提取

在文本清理过程中,是否可以检测并删除句子中的此类垃圾:

x <- c("Thisisaverylongexample and I was to removeitnow", "thisisjustjunk but I do I remove it")

但是,我越是回顾我的数据框架,我发现更多的句子与这种类型的垃圾。如何使用诸如regex之类的工具来检测和删除包含此类垃圾内容的行

如果“垃圾”可以通过其不寻常的长度检测到,您可以相应地定义规则。例如,如果要删除10个或更多字符的单词,这将提取它们:

library(stringr)
str_extract_all(x, "\\b\\w{10,}\\b")
[[1]]
[1] "Thisisaverylongexample" "removeitnow"           

[[2]]
[1] "thisisjustjunk"
这将消除它们:

trimws(gsub("\\b\\w{10,}\\b", "", x))
[1] "and I was to"         "but I do I remove it"
数据:


x如果“垃圾”可以通过其不寻常的长度检测到,则可以相应地定义规则。例如,如果要删除10个或更多字符的单词,这将提取它们:

library(stringr)
str_extract_all(x, "\\b\\w{10,}\\b")
[[1]]
[1] "Thisisaverylongexample" "removeitnow"           

[[2]]
[1] "thisisjustjunk"
这将消除它们:

trimws(gsub("\\b\\w{10,}\\b", "", x))
[1] "and I was to"         "but I do I remove it"
数据:


x你想要
str_remove(x,'thisaverylongexample')
还是
gsub('thisaverylongexample','',x)
?我想要一个类似这样的东西:gsub('thisaverylongexample','',x)。基本上,如何在一个句子中检测出这样的垃圾。为此,你需要先定义“垃圾”。即使使用regex,您也需要定义一些规则来检测此类垃圾。它在肉眼看来是垃圾,但你如何告诉计算机这一点?这是你所谓的“垃圾”的一个定义特征,即它是一个异常长的字符串?如果是这样,您可以相应地定义一个规则。您想要
str_remove(x,'thisaverylongexample')
还是
gsub('thisaverylongexample','',x)
?我想要一个类似这样的东西:gsub('thisaverylongexample','',x)。基本上,如何在一个句子中检测出这样的垃圾。为此,你需要先定义“垃圾”。即使使用regex,您也需要定义一些规则来检测此类垃圾。它在肉眼看来是垃圾,但你如何告诉计算机这一点?这是你所谓的“垃圾”的一个定义特征,即它是一个异常长的字符串?如果是这样,您可以相应地定义规则。