Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

false positives #6

Merged
merged 21 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,3 @@ Instead, the following steps are taken before checking for profanities in a stri
The upside of this method is that we only need to add base bad words, and not all tenses of said bad word.

e.g. the `fuck` entry would support `fucker`, `fucking`, etc)

The downside is that words like `assassin`, which contain `ass`, would also be filtered as profane.
So in the future, a list of false positives would have to be added.
35 changes: 35 additions & 0 deletions falsePositives.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package goaway

var falsePositives = []string{
"Scuntthorpe",
"scuntthorpe",
"associate",
"assassin",
"bass",
"class",
"compass",
"surpass",
"canvass",
"glass",
"lass",
"grass",
"mass",
"pass",
"Penistone",
"clitheroe",
"horniman",
"shitake",
"sussex",
"cockburn",
"libshitz",
"magna cum laude",
"Super Bowl XXX",
"evaluate",
"mocha",
"expression",
"Arsenal",
"classic",
"Tyson Gay",
"Dick Van Dyke",
"basement",
}
3 changes: 3 additions & 0 deletions goaway.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const Space = " "
// Returns a boolean
func IsProfane(s string) bool {
s = strings.Replace(sanitize(s), Space, "", -1) // Sanitize leetspeak AND remove all spaces
for _, falsePositive := range falsePositives {
s = strings.Replace(s, falsePositive, "", -1)
}
for _, word := range profanities {
if match := strings.Contains(s, word); match {
return true
Expand Down
18 changes: 18 additions & 0 deletions goaway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,21 @@ func TestSentencesWithNoProfanities(t *testing.T) {
}
}
}

func TestSentencesWithFalsePositives(t *testing.T) {
sentences := []string{"I am from Scuntthorpe, north Lincolnshire", "He is an associate of mine"}
for _, s := range sentences {
if goaway.IsProfane(s) {
t.Error("Expected false, got true from sentence", s)
}
}
}

func TestSentencesWithFalsePositivesAndProfanities(t *testing.T) {
sentences := []string{"You are a shitty associate", "Go back to Scuntthorpe, Asshole!"}
for _, s := range sentences {
if !goaway.IsProfane(s) {
t.Error("Expected true, got false from sentence", s)
}
}
}