Filter only the exact words #38

Open
opened 2022-08-24 02:15:12 -04:00 by karthikrajanuber · 4 comments
karthikrajanuber commented 2022-08-24 02:15:12 -04:00 (Migrated from github.com)

Describe the bug

We need to filter out only the exact words provided in the profanities list.
Eg: fr -> con is a profane word. It should be filter if it is an exact word. 'contactes' should not be filtered.

Is there a way can do this? I don't want to use falsepositvies because we are maintaining multiple languages.

Please suggest

What do you see?

No response

What do you expect to see?

No response

List the steps that must be taken to reproduce this issue

We need to filter out only the exact words provided in the profanities list.
Eg: fr -> con is a profane word. It should be filter if it is an exact word. 'contactes' should not be filtered.

Is there a way can do this? I don't want to use falsepositvies because we are maintaining multiple languages.

Please suggest

Version

No response

Additional information

No response

### Describe the bug We need to filter out only the exact words provided in the profanities list. Eg: fr -> con is a profane word. It should be filter if it is an exact word. 'contactes' should not be filtered. Is there a way can do this? I don't want to use falsepositvies because we are maintaining multiple languages. Please suggest ### What do you see? _No response_ ### What do you expect to see? _No response_ ### List the steps that must be taken to reproduce this issue We need to filter out only the exact words provided in the profanities list. Eg: fr -> con is a profane word. It should be filter if it is an exact word. 'contactes' should not be filtered. Is there a way can do this? I don't want to use falsepositvies because we are maintaining multiple languages. Please suggest ### Version _No response_ ### Additional information _No response_
TwiN commented 2022-08-24 03:03:54 -04:00 (Migrated from github.com)

Have you tried using WithSanitizeSpaces(false)?

Have you tried using `WithSanitizeSpaces(false)`?
karthikrajanuber commented 2022-08-24 03:25:29 -04:00 (Migrated from github.com)

Hi @TwiN
Yes I tried using WithSanitizeSapces(false) -> it removes the spaces in the the string. But still it is not working.

Screenshot 2022-08-24 at 12 55 17 PM

Screenshot 2022-08-24 at 12 54 13 PM

I tried modifying the code but not able. The thing is instead of doing substring search, I need to search for exact word.

Hi @TwiN Yes I tried using WithSanitizeSapces(false) -> it removes the spaces in the the string. But still it is not working. ![Screenshot 2022-08-24 at 12 55 17 PM](https://user-images.githubusercontent.com/82805406/186357116-f96b9549-14d4-48e7-9275-35892befc047.png) <img width="1301" alt="Screenshot 2022-08-24 at 12 54 13 PM" src="https://user-images.githubusercontent.com/82805406/186356865-4935055c-1757-49f6-970a-d1bfabb82573.png"> I tried modifying the code but not able. The thing is instead of doing substring search, I need to search for exact word.
TwiN commented 2022-08-24 20:23:59 -04:00 (Migrated from github.com)

Ah you're right, yeah. We'd need to add a new WithExactWord(bool) feature

Ah you're right, yeah. We'd need to add a new `WithExactWord(bool)` feature
karthikrajanuber commented 2022-09-08 03:15:51 -04:00 (Migrated from github.com)

I got this with the below code

	for currentIndex != -1 {
		if currentIndex == 0 {
			searchWord = word + " "
			wordPlacement = 1
		}
		if len([]rune(" "+word))+strings.LastIndex(s, " "+word) == len([]rune(s)) {
			searchWord = " " + word
			wordPlacement = 2
		}
		str := strings.Split(s, " ")
		if len(str) == 1 {
			if foundIndex := strings.Index(s[currentIndex:], strings.TrimSpace(searchWord)); foundIndex != -1 {
				for i := 0; i < len([]rune(strings.TrimSpace(searchWord))); i++ {
					runeIndex := g.indexToRune(string(censored), currentIndex+foundIndex+i)
					censored[originalIndexes[runeIndex]] = '*'
				}
				currentIndex += foundIndex + len([]rune(strings.TrimSpace(searchWord)))
			} else {
				break
			}
		}

		if foundIndex := strings.Index(s[currentIndex:], searchWord); foundIndex != -1 {
			if wordPlacement == 0 {
				for i := 0; i < len([]rune(searchWord))-1; i++ {
					runeIndex := g.indexToRune(string(censored), currentIndex+foundIndex+i)
					censored[originalIndexes[runeIndex]] = '*'
				}
				currentIndex += foundIndex + len([]rune(searchWord))
			}
			if wordPlacement == 1 {
				for i := 0; i < len([]rune(strings.TrimSpace(searchWord))); i++ {
					runeIndex := g.indexToRune(string(censored), currentIndex+foundIndex+i)
					censored[originalIndexes[runeIndex]] = '*'
				}
				currentIndex += foundIndex + len([]rune(strings.TrimSpace(searchWord)))
			}
			if wordPlacement == 2 {
				for i := 1; i < len([]rune(strings.TrimSpace(searchWord)))+1; i++ {
					runeIndex := g.indexToRune(string(censored), currentIndex+foundIndex+i)
					censored[originalIndexes[runeIndex]] = '*'
				}
				currentIndex += foundIndex + len([]rune(strings.TrimSpace(searchWord)))
			}
			wordPlacement = 0
		} else {
			break
		}
	}
I got this with the below code for currentIndex != -1 { if currentIndex == 0 { searchWord = word + " " wordPlacement = 1 } if len([]rune(" "+word))+strings.LastIndex(s, " "+word) == len([]rune(s)) { searchWord = " " + word wordPlacement = 2 } str := strings.Split(s, " ") if len(str) == 1 { if foundIndex := strings.Index(s[currentIndex:], strings.TrimSpace(searchWord)); foundIndex != -1 { for i := 0; i < len([]rune(strings.TrimSpace(searchWord))); i++ { runeIndex := g.indexToRune(string(censored), currentIndex+foundIndex+i) censored[originalIndexes[runeIndex]] = '*' } currentIndex += foundIndex + len([]rune(strings.TrimSpace(searchWord))) } else { break } } if foundIndex := strings.Index(s[currentIndex:], searchWord); foundIndex != -1 { if wordPlacement == 0 { for i := 0; i < len([]rune(searchWord))-1; i++ { runeIndex := g.indexToRune(string(censored), currentIndex+foundIndex+i) censored[originalIndexes[runeIndex]] = '*' } currentIndex += foundIndex + len([]rune(searchWord)) } if wordPlacement == 1 { for i := 0; i < len([]rune(strings.TrimSpace(searchWord))); i++ { runeIndex := g.indexToRune(string(censored), currentIndex+foundIndex+i) censored[originalIndexes[runeIndex]] = '*' } currentIndex += foundIndex + len([]rune(strings.TrimSpace(searchWord))) } if wordPlacement == 2 { for i := 1; i < len([]rune(strings.TrimSpace(searchWord)))+1; i++ { runeIndex := g.indexToRune(string(censored), currentIndex+foundIndex+i) censored[originalIndexes[runeIndex]] = '*' } currentIndex += foundIndex + len([]rune(strings.TrimSpace(searchWord))) } wordPlacement = 0 } else { break } }
Sign in to join this conversation.
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#38
No description provided.