how can I get the str_replace_all when I make the first substitution (match) and stop looking for more matches in the dictionary
code that I have.
library(stringr)
x <- c("VALLE PINO CORSO","LA PAZ","PAZ")
dictionary bad words (malpal) and good words (buenapal) I can not make changes in the order of these.
malpal.corpus <- c("PINO CORSO","PAZ","PINO CORZO") # patron
buenapal.corpus <- c("VALLE PINO CORZO","LA PAZ","VALLE PINO CORZO") # reemplazo
malpal.corpus <- str_c("\b",malpal.corpus,"\b")
vect.corpus <- buenapal.corpus
names(vect.corpus) <- malpal.corpus
str_replace_all(x, vect.corpus)
[1] "VALLE VALLE VALLE PINO CORZO" "LA LA PAZ" "LA PAZ"
What I'm looking for is that only the "str_replace_all" function leaves the first match
[1] "VALLE PINO CORZO" "LA PAZ" "LA PAZ"
At least I would like to reduce a VALLE similarity:
[1] "VALLE VALLE PINO CORZO" "LA LA PAZ" "LA PAZ"