Skip to content

Commit 16b57c6

Browse files
authored
Added no_Profanity.R
An algorithm for blocking out profanities in text data such as social media posts. The profanities used in this program is by no means exhaustive. Users can add more to list as they see fit.
1 parent b46d3ac commit 16b57c6

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

string_manipulation/no_Profanity.R

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
no_Profanity <- function(text, block) {
2+
text_split <- c(unlist(strsplit(text, split = " ")))
3+
4+
post_n <- c()
5+
for (i in text_split) {
6+
post_n <- c(
7+
post_n,
8+
if (i %in% c(
9+
"Damn",
10+
"damn",
11+
"DAMN",
12+
"SHIT",
13+
"Shit",
14+
"shit",
15+
"fuck",
16+
"Fuck",
17+
"FUCK",
18+
"crap",
19+
"CRAP",
20+
"Crap",
21+
"bullshit",
22+
"Bullshit",
23+
"BULLSHIT",
24+
"BullShit",
25+
"Fucking",
26+
"fucking",
27+
"FUCKING"
28+
)) {
29+
tolower(i)
30+
} else {
31+
i
32+
}
33+
)
34+
}
35+
36+
clean_text <- gsub("\\b(fuck|shit|bullshit|damn|crap|fucking)\\b", block, post_n)
37+
38+
clean_text <- gsub("\n", "", clean_text)
39+
40+
return(paste(clean_text, collapse = " "))
41+
}
42+
43+
post <- "The damn business does not give a crap about it."
44+
45+
no_Profanity(text = post,block = "$$$")

0 commit comments

Comments
 (0)