<commit_before>class Filter
  @by_type: (type, target, text) ->
    switch type
      when "string"
        switch target
          when "name"    then new NameFilter(text)
          when "url"     then new URLFilter(text)
          when "comment" then new CommentFilter(text)
      when "regex"
        switch target
          when "name"    then new NameRegexFilter(text)
          when "url"     then new URLRegexFilter(text)
          when "comment" then new CommentRegexFilter(text)

# String filters
class StringFilter
  constructor: (@text) ->

class NameFilter extends StringFilter
  is_troll: (comment) ->
    comment.name is @text

class URLFilter extends StringFilter
  is_troll: (comment) ->
    comment.email is @text

class ContentFilter extends StringFilter
  is_troll: (comment) ->
    comment.content.indexOf(@text) isnt -1

# Regular expression filters
class RegexFilter extends Filter
  constructor: (text) ->
    split_text = text.split("/")
    @regex = new RegExp(split_text[1], split_text[2])

class NameRegexFilter extends RegexFilter<commit_msg>Regex auto-detects case-sensitivity<commit_after>class Filter
  @by_type: (type, target, text) ->
    switch type
      when "string"
        switch target
          when "name"    then new NameFilter(text)
          when "url"     then new URLFilter(text)
          when "comment" then new CommentFilter(text)
      when "regex"
        switch target
          when "name"    then new NameRegexFilter(text)
          when "url"     then new URLRegexFilter(text)
          when "comment" then new CommentRegexFilter(text)

# String filters
class StringFilter
  constructor: (@text) ->

class NameFilter extends StringFilter
  is_troll: (comment) ->
    comment.name is @text

class URLFilter extends StringFilter
  is_troll: (comment) ->
    comment.email is @text

class ContentFilter extends StringFilter
  is_troll: (comment) ->
    comment.content.indexOf(@text) isnt -1

# Regular expression filters
class RegexFilter extends Filter
  constructor: (text) ->
    @regex = new RegExp(text, if text is text.toLowerCase() then "i" else "")

class NameRegexFilter extends RegexFilter
{'fraction_non_alphanumeric': 0.08546214584300975, 'fraction_numerical': 0.0018578727357176034, 'mean_word_length': 3.0488721804511276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '886807', 'n_tokens_mistral': 604, 'n_tokens_neox': 604, 'n_words': 201}