obelics/utils/filtering_utils.py (427 lines of code) (raw):

import re import string import emoji NON_PRINTING_CHARACTERS_RE = re.compile(f"[{''.join(map(chr, list(range(0,32)) + list(range(127,160))))}]") DIGITS_RE = re.compile(r"\d") UNICODE_PUNCTUATION = { ",": ",", "。": ".", "、": ",", "„": '"', "”": '"', "“": '"', "«": '"', "»": '"', "1": '"', "」": '"', "「": '"', "《": '"', "》": '"', "´": "'", "∶": ":", ":": ":", "?": "?", "!": "!", "(": "(", ")": ")", ";": ";", "–": "-", "—": " - ", ".": ". ", "~": "~", "’": "'", "…": "...", "━": "-", "〈": "<", "〉": ">", "【": "[", "】": "]", "%": "%", "►": "-", } main_special_characters = string.punctuation + string.digits + string.whitespace other_special_characters = ( "’ “— ™ – •‘œ    ˜ ‚ƒ„’“”–ー一▬…✦�­£​•€«»°·═" "×士^˘⇓↓↑←→()§″′´¿−±∈¢ø‚„½¼¾¹²³―⁃,ˌ¸‹›ʺˈʻ¦‐⠀‰……‑≤≥‖" "◆●■►▼▲▴∆▻¡★☆✱ːº。¯˜¥ɪ≈†上ン:∼⁄・♡✓⊕․.⋅÷1‟;،、¨ाাी्े◦˚" "゜ʼ≖ʼ¤ッツシ℃√!【】‿∞➤~πه۩☛₨➩☻๑٪♥ıॽ《‘©﴿٬?▷Г♫∟™ª₪®「—❖" "」﴾》" ) emoji = list(emoji.UNICODE_EMOJI["en"].keys()) SPECIAL_CHARACTERS = set(main_special_characters + other_special_characters) SPECIAL_CHARACTERS.update(emoji) STOPWORDS = [ "a", "a.k.a", "aboard", "about", "above", "abt", "accord", "according", "across", "after", "against", "ago", "aground", "ahead", "aka", "ala", "albeit", "all", "along", "alongside", "although", "am", "amid", "amidst", "among", "amongst", "amoung", "an", "and", "and/or", "another", "any", "any1", "anybody", "anyone", "anything", "are", "around", "as", "aside", "astride", "at", "atop", "away", "b", "b/c", "b/t", "back", "base", "based", "bc", "be", "because", "been", "before", "behind", "being", "below", "beneath", "beside", "besides", "between", "beyond", "board", "both", "btwn", "but", "by", "can", "cause", "circa", "cos", "could", "coz", "cus", "depend", "depending", "despite", "did", "do", "does", "down", "due", "during", "each", "either", "else", "even", "ever", "every", "everybody", "everyone", "everything", "except", "for", "forth", "from", "get", "gets", "getting", "give", "given", "got", "had", "half", "has", "hav", "have", "having", "he", "her", "hers", "herself", "him", "himself", "his", "how", "however", "i", "i'd", "if", "in", "include", "including", "inside", "instead", "into", "is", "it", "it's", "its", "itself", "lest", "like", "made", "many", "may", "me", "might", "mine", "minus", "most", "much", "must", "my", "myself", "nary", "near", "nearby", "neither", "next", "nigh", "no", "nobody", "none", "noone", "nor", "not", "nothing", "notwithstanding", "of", "off", "on", "onboard", "once", "one", "ones", "oneself", "only", "onto", "opposite", "or", "other", "others", "ought", "our", "ours", "ourselves", "out", "outside", "over", "overt", "own", "past", "per", "plus", "prior", "quite", "rather", "re", "regard", "regarding", "regardless", "round", "s/he", "save", "self", "shall", "she", "should", "side", "since", "so", "some", "somebody", "someone", "something", "such", "sure", "teh", "than", "thanks", "that", "the", "their", "theirs", "them", "themselves", "then", "there", "these", "they", "they're", "thier", "this", "tho", "those", "thou", "though", "through", "throughout", "thru", "thy", "til", "till", "to", "together", "too", "toward", "towards", "u", "under", "underneath", "unless", "unlike", "until", "unto", "up", "upon", "ur", "us", "use", "versus", "via", "vs", "vs.", "w/", "w/o", "w/out", "was", "we", "were", "what", "whatever", "whatnot", "when", "whenever", "where", "whereas", "wherever", "whether", "which", "while", "whilst", "whither", "who", "who's", "whoever", "whom", "whomever", "whose", "why", "will", "with", "within", "without", "wo", "worth", "would", "wud", "y'all", "ya", "yet", "yo", "you", "you're", "your", "youre", "yours", "yourself", "yourselves", ] STOPWORDS = set(STOPWORDS) FLAGGED_WORDS = [ "anal", "bareback", "bbw", "bdsm", "blowjob", "blowjobs", "brazzers", "bukkake", "camgirl", "camwhore", "cocksucking", "creampie", "cuckold", "cum", "cumming", "cums", "cumshot", "cumshots", "cumslut", "cunnilingus", "deepthroat", "deepthroating", "dildo", "dildos", "dogging", "doggystyle", "dominatrix", "erotic", "fellatio", "femdom", "fingering", "fisting", "footjob", "gangbang", "handjob", "hentai", "horney", "horniest", "horny", "jism", "jizz", "masterbating", "masturbate", "masturbating", "masturbation", "milf", "orgies", "orgy", "pegging", "porn", "pornhub", "porno", "pornos", "pornstar", "pornstars", "redtube", "rimming", "slutty", "squirting", "strapon", "threesome", "vibrator", "xhamster", "xnxx", "xvideos", "xxx", "youporn", ] FLAGGED_WORDS = set(FLAGGED_WORDS) PUNCTUATION = set([",", ";", ":", "?", "!", "."])