我有错误编码的转录,也就是说,出现的字符
不应该
发生
在这个玩具数据中
允许
字符是此类:
"[)(/][A-Za-z0-9â⣥°!.,:¿?~<>â=_-]"
df <- data.frame(
Utterance = c("~°maybe you (.) >should ¥just¥<",
"SOME text |<-- pipe¿ andâ¬", # <--: | and â¬
"blah%", # <--: %
"text ^more text", # <--: ^
"£norm(hh)a::l£mal, (1.22)"))
我需要做的是:
-
发现
Utterance
包含任何错误编码的
-
提取错误的字符
就检测而言,我做得还可以,但提取失败得很惨:
library(stringr)
library(dplyr)
df %>%
filter(!str_detect(Utterance, "[)(/][A-Za-z0-9â⣥°!.,:¿?~<>â=_-]")) %>%
mutate(WrongChar = str_extract_all(Utterance, "[^)(/][A-Za-z0-9â⣥°!.,:¿?~<>â=_-]"))
Utterance WrongChar
1 SOME text |<-- pipe¿ and⬠SO, ME, t, ex, |<, --, p, ip, e¿, a, nd
2 blah% bl, ah
3 text ^more text te, xt, ^m, or, t, ex
如何改进提取以获得此
预期结果
:
Utterance WrongChar
1 SOME text |<-- pipe¿ and⬠|, â¬
2 blah% %
3 text ^more text ^