<commit_before>import re
import phonenumbers


class FindSpam:
  rules = [
   {'regex': "(?i)\\b(baba(ji)?|nike|vashikaran|here is|porn)\\b", 'all': True,
    'sites': [], 'reason': "Bad keyword detected"},
   {'regex': "\\+\\d{10}|\\+?\\d{2}[\\s\\-]?\\d{8,11}", 'all': True, 
    'sites': ["patents.stackexchange.com"], 'reason': "Phone number detected", 'validation_method': 'phonenumbers'},
   {'regex': "(?i)\\b([Nn]igga|[Nn]igger|niga|[Aa]sshole|crap|fag|[Ff]uck|idiot|[Ss]hit|[Ww]hore)s?\\b", 'all': True,
    'sites': [], 'reason': "Offensive title detected",'insensitive':True},
   {'regex': "^[A-Z0-9\\(\\)\\.\\-\\?\\s'\"]*$", 'all': True, 'sites': [], 'reason': "All-caps title"}
  ]

  @staticmethod
  def testpost(title, site):
    result = [];
    for rule in FindSpam.rules:
      if rule['all'] != (site in rule['sites']):
        if re.compile(rule['regex']).search(title):
          try:
            if getattr(FindSpam, "%s" % rule['validation_method'])(title):
              result.append(rule['reason'])
          except KeyError:        # There is no special logic for this rule
            result.append(rule['reason'])
    return result

  @staticmethod
  def testtitle(title):
    regexes=["\\b(baba(ji)?|vashikaran|fashion|here is|porn)\\b","\\+\\d{10}","\\+?\\d{2}\\s?\\d{8}","\\b(asshole|crap|fag|fuck|idiot|shit|whore)s?\\b"]
    result = []
    p = [not not re.compile(s).search(title) for s in regexes]
    if 'vashikaran' in title or 'baba' in title or True in p:
      result.append('Possible spam')
      # magic if matches word
    return result

  @staticmethod
  def phonenumbers(msg):
    try:
      z = phonenumbers.parse(msg, "IN")
      if phonenumbers.is_possible_number(z) and phonenumbers.is_valid_number(z):
        print "Possible %s, Valid %s, Expain: %s" % (phonenumbers.is_possible_number(z), phonenumbers.is_valid_number(z), z)
        return True
    except phonenumbers.phonenumberutil.NumberParseException:
      return False<commit_msg>Updates to mesh current regex's with new phonenumbers logic<commit_after>import re
import phonenumbers

class FindSpam:
  rules = [
   {'regex': "(?i)\\b(baba(ji)?|nike|vashikaran|sumer|kolcak|porn|molvi|judi bola|ituBola.com|lost lover|11s|acai|skin care)\\b", 'all': True,
    'sites': [], 'reason': "Bad keyword detected"},
   {'regex': "(?i)\\b(weight loss)\\b", 'all': True,
    'sites': ["fitness.stackexchange.com"], 'reason': "Bad keyword detected"},
   {'regex': "\\d(?:_*\\d){9}|\\+?\\d_*\\d[\\s\\-]?(_*\\d){8,10}", 'all': True,
    'sites': ["patents.stackexchange.com"], 'reason': "Phone number detected", 'validation_method': 'phonenumbers'},
   {'regex': "(?i)\\b(nigg?(a|er)|asshole|crap|fag|fuck(ing?)?|idiot|shit|whore)s?\\b", 'all': True,
    'sites': [], 'reason': "Offensive title detected",'insensitive':True},
   {'regex': "^(?=.*[A-Z])[^a-z]*$", 'all': True, 'sites': [], 'reason': "All-caps title"}
  ]

  @staticmethod
  def testpost(title, site):
    result = [];
    for rule in FindSpam.rules:
      if rule['all'] != (site in rule['sites']):
        if re.compile(rule['regex']).search(title):
          try:
            if getattr(TestClass, "%s" % rule['validation_method'])(title):
              result.append(rule['reason'])
          except KeyError:        # There is no special logic for this rule
            result.append(rule['reason'])
    return result

  @staticmethod
  def phonenumbers(msg):
    try:
      z = phonenumbers.parse(msg, "IN")
      if phonenumbers.is_possible_number(z) and phonenumbers.is_valid_number(z):
        print "Possible %s, Valid %s, Explain: %s" % (phonenumbers.is_possible_number(z), phonenumbers.is_valid_number(z), z)
        return True
    except phonenumbers.phonenumberutil.NumberParseException:
      return False
{'fraction_non_alphanumeric': 0.20655911134620472, 'fraction_numerical': 0.004760645331922771, 'mean_word_length': 3.6234718826405867, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1485630', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1348, 'n_words': 270}