feat: implement WithExactWord to allow stricter matches #107

Merged
ntietz merged 5 commits from master into master 2025-09-22 09:48:17 -04:00
ntietz commented 2024-12-19 12:43:37 -05:00 (Migrated from github.com)

Summary

This is a fix for #38 to filter only exact words.

I chose to implement it by having an alternate implementation only for the profanities list, where the rest is untouched so false positives and false negatives will remain working as expected; it seems right to me that a false negative should not change from exact word matches.

I have one test in here. I could see a use for more, but comments/feedback in that area would be appreciated so I can calibrate what sort of test coverage you're aiming for.

Checklist

  • Tested and/or added tests to validate that the changes work as intended, if applicable.
  • Updated documentation in README.md, if applicable.
## Summary This is a fix for #38 to filter only exact words. I chose to implement it by having an alternate implementation *only* for the profanities list, where the rest is untouched so false positives and false negatives will remain working as expected; it seems right to me that a false negative should not change from exact word matches. I have one test in here. I could see a use for more, but comments/feedback in that area would be appreciated so I can calibrate what sort of test coverage you're aiming for. ## Checklist <!-- Replace [ ] by [X] if you have completed the item --> - [x] Tested and/or added tests to validate that the changes work as intended, if applicable. - [x] Updated documentation in `README.md`, if applicable.
TwiN (Migrated from github.com) requested changes 2024-12-19 18:29:53 -05:00
@ -548,6 +548,36 @@ func TestFalsePositives(t *testing.T) {
}
TwiN (Migrated from github.com) commented 2024-12-19 18:29:49 -05:00
	accept_sentences := []string{
		"I'm an analyst",
	}
	reject_sentences := []string{"Go away, ass."}
	tests := []struct {

Go uses camelCase instead of snake_case - could you make the changes to the other parts of your code?

```suggestion accept_sentences := []string{ "I'm an analyst", } reject_sentences := []string{"Go away, ass."} tests := []struct { ``` Go uses camelCase instead of snake_case - could you make the changes to the other parts of your code?
@ -564,6 +594,10 @@ func TestFalseNegatives(t *testing.T) {
name: "With Custom Dictionary",
TwiN (Migrated from github.com) commented 2024-12-19 18:28:47 -05:00
		{
			name:              "With Custom Dictionary",
			profanityDetector: NewProfanityDetector().WithCustomDictionary(DefaultProfanities, DefaultFalsePositives, DefaultFalseNegatives),
		},

Was this a typo? It's a duplicate of the scenario above

```suggestion { name: "With Custom Dictionary", profanityDetector: NewProfanityDetector().WithCustomDictionary(DefaultProfanities, DefaultFalsePositives, DefaultFalseNegatives), }, ``` Was this a typo? It's a duplicate of the scenario above
ntietz (Migrated from github.com) reviewed 2025-01-07 14:33:56 -05:00
ntietz (Migrated from github.com) left a comment

thank you for the feedback @TwiN ! I've updated the PR with it. sorry it took a while—shortly after the feedback I went on holiday, but I should be able to have more timely iteration now if this needs any further work.

thank you for the feedback @TwiN ! I've updated the PR with it. sorry it took a while—shortly after the feedback I went on holiday, but I should be able to have more timely iteration now if this needs any further work.
@ -548,6 +548,36 @@ func TestFalsePositives(t *testing.T) {
}
ntietz (Migrated from github.com) commented 2025-01-07 14:33:22 -05:00

done in bf6efc8, thank you! the perils of switching between languages and getting my styles mixed up 😅

done in bf6efc8, thank you! the perils of switching between languages and getting my styles mixed up :sweat_smile:
@ -564,6 +594,10 @@ func TestFalseNegatives(t *testing.T) {
name: "With Custom Dictionary",
ntietz (Migrated from github.com) commented 2025-01-07 14:32:56 -05:00

yes, I meant to have it include coverage of the new code by setting it to use exact words for one of them. pushed that fix in bf6efc8

yes, I meant to have it include coverage of the new code by setting it to use exact words for one of them. pushed that fix in bf6efc8
TwiN (Migrated from github.com) requested changes 2025-03-05 21:13:41 -05:00
@ -129,15 +142,34 @@ func (g *ProfanityDetector) ExtractProfanity(s string) string {
for _, word := range g.falsePositives {
TwiN (Migrated from github.com) commented 2025-01-07 21:54:15 -05:00

This may sound odd, but could you swap the blocks and make this if g.exactWord instead of if !g.exactWord? I feel it makes more sense

This may sound odd, but could you swap the blocks and make this if g.exactWord instead of if !g.exactWord? I feel it makes more sense
ntietz (Migrated from github.com) reviewed 2025-07-22 10:42:19 -04:00
@ -129,15 +142,34 @@ func (g *ProfanityDetector) ExtractProfanity(s string) string {
for _, word := range g.falsePositives {
ntietz (Migrated from github.com) commented 2025-07-22 10:42:19 -04:00

Yeah, sure! Done in 1ebc004. I agree that that's better, easier to reason about without a negation in the first case.

Yeah, sure! Done in 1ebc004. I agree that that's better, easier to reason about without a negation in the first case.
ntietz commented 2025-07-22 10:43:35 -04:00 (Migrated from github.com)

@TwiN Sorry for the delays on this! Life has been... rough. I made the requested change, and also rebased onto TwiN:master.

@TwiN Sorry for the delays on this! Life has been... rough. I made the requested change, and also rebased onto `TwiN:master`.
th0th commented 2025-09-22 07:32:47 -04:00 (Migrated from github.com)

Hey folks, is there anything I can help with to get this merged? 💐

Hey folks, is there anything I can help with to get this merged? 💐
ntietz commented 2025-09-22 07:53:13 -04:00 (Migrated from github.com)

I think we’re just waiting for @TwiN to approve and merge (or request further changes)

I think we’re just waiting for @TwiN to approve and merge (or request further changes)
TwiN (Migrated from github.com) requested changes 2025-09-22 07:55:00 -04:00
TwiN (Migrated from github.com) left a comment

Can you update the README.md

Can you update the README.md
TwiN commented 2025-09-22 07:55:36 -04:00 (Migrated from github.com)

Once you've updated the README, I'll merge.

Once you've updated the README, I'll merge.
ntietz commented 2025-09-22 08:05:00 -04:00 (Migrated from github.com)

@TwiN done, thanks!

@TwiN done, thanks!
th0th commented 2025-09-22 09:38:11 -04:00 (Migrated from github.com)

Can you please merge this @TwiN? 💐

Can you please merge this @TwiN? 💐
TwiN (Migrated from github.com) approved these changes 2025-09-22 09:46:52 -04:00
TwiN commented 2025-09-22 09:49:16 -04:00 (Migrated from github.com)

I'll make a release in 30ish minutes, not home at the moment. Thank you for your patience folks :)

I'll make a release in 30ish minutes, not home at the moment. Thank you for your patience folks :)
ntietz commented 2025-09-23 11:32:20 -04:00 (Migrated from github.com)

thank you so much, @TwiN !

thank you so much, @TwiN !
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
TwiN/go-away!107
No description provided.