-
Notifications
You must be signed in to change notification settings - Fork 190
Add reason post is likely nonsense #4304
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
Open
user12986714
wants to merge
13
commits into
Charcoal-SE:master
Choose a base branch
from
user12986714:patch-50
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
40b64cb
Add reason post is likely nonsense
user12986714 4e23c81
Fix typo
user12986714 1196fa3
Fix division by zero + use constants
user12986714 5b43377
Syntax fix
user12986714 38b143f
Make CI happy
user12986714 dc3ba10
Fix constants
user12986714 eddf95e
Exclude codegolf.SE
user12986714 a274d2c
2stddev
user12986714 7592eb0
Exclude non-English sites
user12986714 d271d65
Add italian.SE to exclusion list + fix CI
user12986714 83b6000
Fix flake8 attempt 1
user12986714 ae2bdf4
Correct math
user12986714 5eec477
Collapse whitespaces
user12986714 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -39,6 +39,16 @@ | |
| PUNCTUATION_RATIO = 0.42 | ||
| REPEATED_CHARACTER_RATIO = 0.20 | ||
| IMG_TXT_R_THRES = 0.7 | ||
|
|
||
| # >>> statistics.mean(result) | ||
| # 0.20483261275004847 | ||
| # >>> statistics.median(result) | ||
| # 0.20223865427238322 | ||
| # >>> statistics.stdev(result) | ||
| # 0.031230117152319384 | ||
| ENTROPY_TOO_LOW = 0.14 | ||
| ENTROPY_TOO_HIGH = 0.26 | ||
|
|
||
| EXCEPTION_RE = r"^Domain (.*) didn't .*!$" | ||
| RE_COMPILE = regex.compile(EXCEPTION_RE) | ||
| COMMON_MALFORMED_PROTOCOLS = [ | ||
|
|
@@ -617,6 +627,30 @@ def mostly_img(s, site): | |
| return False, "" | ||
|
|
||
|
|
||
| @create_rule("post is likely nonsense", title=False, | ||
| sites=["codegolf.stackexchange.com", | ||
| "stackoverflow.com", "ja.stackoverflow.com", "pt.stackoverflow.com", | ||
| "es.stackoverflow.com", "islam.stackexchange.com", | ||
| "japanese.stackexchange.com", "anime.stackexchange.com", | ||
| "hinduism.stackexchange.com", "judaism.stackexchange.com", | ||
| "buddhism.stackexchange.com", "chinese.stackexchange.com", | ||
| "french.stackexchange.com", "spanish.stackexchange.com", | ||
| "portuguese.stackexchange.com", "korean.stackexchange.com", | ||
| "ukrainian.stackexchange.com", "italian.stackexchange.com"], | ||
| max_rep=10000, max_score=10000) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to strip code blocks, for instance https://askubuntu.com/a/623972. Or at least collapse repeated whitespace characters. |
||
| def nonsense(s, site): | ||
| if len(s) == 0: | ||
| return False, "" | ||
| if "pytest" in sys.modules: | ||
| return False, "" | ||
| 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) | ||
user12986714 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if entropy_per_char < ENTROPY_TOO_LOW or entropy_per_char > ENTROPY_TOO_HIGH: | ||
| return True, "Entropy per char is {:.4f}".format(entropy_per_char) | ||
| return False, "" | ||
|
|
||
|
|
||
| # noinspection PyUnusedLocal,PyMissingTypeHints | ||
| @create_rule("repeating characters in {}", stripcodeblocks=True, max_rep=10000, max_score=10000) | ||
| def has_repeating_characters(s, site): | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.