Skip to content

Commit

Permalink
Merge pull request #6 from mattwhite180/master
Browse files Browse the repository at this point in the history
false positives
  • Loading branch information
TwiN authored Aug 10, 2020
2 parents 0c0799f + 46b8be5 commit 7272efb
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
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)
}
}
}

0 comments on commit 7272efb

Please sign in to comment.