<commit_before>#This file loads simileys
module SmileyHelpers
  def self.regex
    return @regex if defined?(@regex)

    before_and_after = "[.,;:!\\?\\(\\[\\{\\)\\]\\}\\-]|\\s"
    @regex = Regexp.compile("(^|#{before_and_after})(" +
            smilies.keys.map { |token| Regexp.escape(token) }.join("|") +
            ")($|#{before_and_after})", Regexp::MULTILINE)
  end

  def self.smilies
    return @smilies unless @smilies.nil?

    @smilies = {}
    
    YAML.load_file("#{Rails.root}/config/smilies.yml").each do |smiley_name, symbols|
      symbols.each{|s| @smilies[s] = smiley_name }
    end

    @smilies
  end

  def self.replace_smilies(str, animate=false)
    str = str.to_str
    str = str.gsub(self.regex) do
      if animate
        %(#{$1}<span class="smilies animate#{self.smilies[$2]}" title="#{$2}">&nbsp;</span>#{$3})
      else
        %(#{$1}<span class="smilies #{self.smilies[$2]}" title="#{$2}">&nbsp;</span>#{$3})
      end
    end

    str.respond_to?(:html_safe) ? str.html_safe : str
  end

  def replace_smilies(str, animate=false)
    # Just call class method.<commit_msg>regex to match multiple occurance of same smileys<commit_after>#This file loads simileys
module SmileyHelpers
  def self.regex
    return @regex if defined?(@regex)

    before_and_after_with_space = "[.,;:!\\?\\(\\[\\{\\)\\]\\}\\-]|\\s"
    before_and_after_without_space = "[.,;:!\\?\\(\\[\\{\\)\\]\\}\\-]|"
    @regex = Regexp.compile("(^|#{before_and_after_with_space})(" +
            smilies.keys.map { |token| Regexp.union(token) }.join("|") +
            ")($|#{before_and_after_without_space})", Regexp::MULTILINE|Regexp::IGNORECASE|Regexp::EXTENDED)
  end

  def self.smilies
    return @smilies unless @smilies.nil?

    @smilies = {}
    
    YAML.load_file("#{Rails.root}/config/smilies.yml").each do |smiley_name, symbols|
      symbols.each{|s| @smilies[s] = smiley_name }
    end

    @smilies
  end

  def self.replace_smilies(str, animate=false)
    str = str.to_str
    str = str.gsub(self.regex) do
      if animate
        %(#{$1}<span class="smilies animate#{self.smilies[$2]}" title="#{$2}">&nbsp;</span>#{$3})
      else
        %(#{$1}<span class="smilies #{self.smilies[$2]}" title="#{$2}">&nbsp;</span>#{$3})
      end
    end

    str.respond_to?(:html_safe) ? str.html_safe : str
  end

  def replace_smilies(str, animate=false)
    # Just call class method.
{'fraction_non_alphanumeric': 0.20334029227557412, 'fraction_numerical': 0.006680584551148226, 'mean_word_length': 3.138169257340242, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5507436', 'n_tokens_mistral': 941, 'n_tokens_neox': 878, 'n_words': 151}