<commit_before>module SeoPages
  class SeoPage < ActiveRecord::Base
    validates :url_identifier, uniqueness: true

    scope :regex, -> { where(is_regex: true)}
    scope :non_regex, -> { where(is_regex: false)}

    @@regex = {}

    def self.find_by_url_identifier url
      seo = exact_match url
      unless seo
        seo = regex_match url
      end
    end

    def self.exact_match url
      non_regex.where(url_identifier: url).first
    end

    def self.regex_match url
      regex.to_a.find do |seo|
        not (get_regex(seo.url_identifier) =~ url).nil?
      end
    end

    def self.get_regex url
      @@regex[url].nil? ? @@regex[url] = Regexp.new(url) : @@regex[url]
    end
  end
end<commit_msg>regexp review<commit_after>module SeoPages
  class SeoPage < ActiveRecord::Base
    validates :url_identifier, uniqueness: true

    scope :regex, -> { where(is_regex: true)}
    scope :non_regex, -> { where(is_regex: false)}

    @@regex = {}

    def self.find_by_url_identifier(url)
      exact_match(url) || regex_match(url)
    end

    def self.exact_match(url)
      non_regex.where(url_identifier: url).first
    end

    def self.regex_match(url)
      regex.to_a.find do |seo|
        get_regex(seo.url_identifier) =~ url
      end
    end

    def self.get_regex(url)
      if @@regex[url].nil? 
        @@regex[url] = Regexp.new(url)
      else
        @@regex[url]
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.0, 'mean_word_length': 2.5753768844221105, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4310148', 'n_tokens_mistral': 511, 'n_tokens_neox': 485, 'n_words': 107}