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

Add 'censor middle only' feature #35

Closed
wants to merge 1 commit into from
Closed

Conversation

emso-c
Copy link

@emso-c emso-c commented Jul 15, 2021

Firstly, thanks for the amazing module!

I've added a censor middle only feature which censors only the middle of the texts.

Can only be used if middle_only argument is set to True and it's set to False by default, so it doesn't break anything or alter the way the module works.

I didn't really test edge cases that much but it passes all 30 unit tests.

Without middle_only parameter (same result with middle_only=False):

from better_profanity import profanity

if __name__ == "__main__":
    profanity.load_censor_words()

    text = "fucking shit"
    print(profanity.censor(text))
    # "**** ****"

With middle_only parameter:

from better_profanity import profanity

if __name__ == "__main__":
    profanity.load_censor_words()

    text = "fucking shit"
    print(profanity.censor(text, middle_only=True))
    # "f*****g s**t"
Also added env/ to gitignore since I was using a virtual environment, discard it if you want.

@snguyenthanh
Copy link
Owner

May I ask what the use case for "middle only" censoring is ? Or is it just a personal preference ?

@emso-c
Copy link
Author

emso-c commented Jul 20, 2021

Actually we just needed a way to determine the true length of the censored text. With the current method it returns 4 regardless of the words length. Not censoring the initial and the last letter was a personal preference in order to make the word more "guessable".

@snguyenthanh
Copy link
Owner

Hmm I see. I think that would be fine, to give the users more options.

By the way, as #36 already includes the feature in the PR, I think we could close this one ?

@emso-c
Copy link
Author

emso-c commented Jul 20, 2021

Oh sure, sorry about that.

Closing rn.

@emso-c emso-c closed this Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants