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 reason post is likely nonsense #4304

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Next Next commit
Add reason post is likely nonsense
user12986714 authored Aug 6, 2020
commit 40b64cb375a7ed3b5340500348a7b4f529fa1090
13 changes: 13 additions & 0 deletions findspam.py
Original file line number Diff line number Diff line change
@@ -617,6 +617,19 @@ def mostly_img(s, site):
return False, ""


@create_rule("post is likely nonsense", max_rep=10000, max_score=10000)
def nonsense(s, site):
probability = [float(s.count(x)) / len(s) for x in s]
entropy_per_char = -sum([x * math.log2(x) for x in probability]) / len(s)

if x < 1.5 or x > 3:
# Average English entropy per letter is 2.6
# Since space and punctuations are not excluded, the value will be lower
# Too high or too low entropy indicates gibberish
return True, "Entropy per char is {:.4f}".format(x)
return False, ""


# noinspection PyUnusedLocal,PyMissingTypeHints
@create_rule("repeating characters in {}", stripcodeblocks=True, max_rep=10000, max_score=10000)
def has_repeating_characters(s, site):