This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package moderation | ||
|
||
import ( | ||
"encoding/csv" | ||
"io" | ||
"os" | ||
"testing" | ||
|
||
"github.com/finnbear/moderation" | ||
"github.com/TwinProduction/go-away" | ||
) | ||
|
||
func moderationIsInappropriate(phrase string) bool { | ||
return moderation.Analyze(phrase).IsInappropriate() | ||
} | ||
|
||
func TestModerationWikipedia(t *testing.T) { | ||
testWikipedia(t, moderationIsInappropriate) | ||
} | ||
|
||
func TestGoAwayWikipedia(t *testing.T) { | ||
testWikipedia(t, goaway.IsProfane) | ||
} | ||
|
||
func testWikipedia(t *testing.T, isInappropriate func(string) bool) { | ||
wikiModerationData, err := os.Open("../wikipedia-test.csv") | ||
if err != nil { | ||
t.Skip() | ||
} | ||
reader := csv.NewReader(wikiModerationData) | ||
|
||
correct := 0 | ||
total := 0 | ||
|
||
for total < 50000 { | ||
fields, err := reader.Read() | ||
if err != nil { | ||
if err == io.EOF { | ||
break | ||
} | ||
t.Error(err) | ||
} | ||
phrase := fields[1] | ||
offensive := fields[0] == "1" | ||
inappropriate := isInappropriate(phrase) | ||
if inappropriate == offensive { | ||
correct++ | ||
} else { | ||
//fmt.Printf("phrase=\"%s\" analysis offensive=%v actual offensive=%v", phrase, inappropriate, offensive) | ||
} | ||
|
||
total++ | ||
} | ||
|
||
accuracy := 100 * float64(correct) / float64(total) | ||
|
||
// Wikipedia takes into account more than whether the text contains | ||
// bad words | ||
const requiredAccuracy = 90 | ||
|
||
if accuracy >= requiredAccuracy { | ||
t.Logf("accuracy was %f%% (%d%% required)\n", accuracy, requiredAccuracy) | ||
} else { | ||
t.Errorf("accuracy was %f%% (%d%% required)\n", accuracy, requiredAccuracy) | ||
} | ||
|
||
err = wikiModerationData.Close() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module comparison | ||
|
||
go 1.15 | ||
|
||
require ( | ||
github.com/TwinProduction/go-away v1.0.1 | ||
github.com/finnbear/moderation v0.5.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
github.com/TwinProduction/go-away v1.0.1 h1:LDe6jPktucIz/dftNGL5x2LYRB6VXjVUtRsrlVHo+Ag= | ||
github.com/TwinProduction/go-away v1.0.1/go.mod h1:VB/lNzhkzh7Xw2QgU+tYBjMheldukJaIJzVaIx2rh30= | ||
github.com/finnbear/moderation v0.5.0 h1:k00252U3XaworO6EN/VRf1hasn0pcANWe7tNjEoyzsc= | ||
github.com/finnbear/moderation v0.5.0/go.mod h1:zoexQHUm4TZCb9x/Re0TqV8SgvnDPZjMRdSMAjEqmgE= | ||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc= | ||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters