<commit_before>class Character < ActiveRecord::Base
  belongs_to :user
  belongs_to :template
  belongs_to :default_icon, class_name: Icon
  belongs_to :character_group
  has_many :replies
  has_many :posts
  has_and_belongs_to_many :galleries
  has_many :character_tags, inverse_of: :character, dependent: :destroy
  has_many :tags, through: :character_tags

  validates_presence_of :name, :user
  validate :valid_template, :valid_group

  after_save :update_galleries

  attr_accessor :new_template_name, :group_name, :gallery_ids

  nilify_blanks

  def icon
    @icon ||= default_icon || galleries.detect(&:default_icon).try(:default_icon)
  end

  def icons
    @icons ||= galleries.map(&:icons).flatten.uniq_by(&:id)
  end

  def recent_posts(limit=25, page=1)
    return @recent unless @recent.nil?
    reply_ids =  replies.group(:post_id).select(:post_id).map(&:post_id)
    post_ids = posts.select(:id).map(&:id)
    @recent ||= Post.where(id: (post_ids + reply_ids).uniq).order('tagged_at desc').paginate(per_page: limit, page: page)
  end

  def selector_name
    [name, template_name, screenname].compact.join(' | ')
  end

  private

  def valid_template
    return unless template_id == 0
    @template = Template.new(user: user, name: new_template_name)
    return if @template.valid?
    @template.errors.messages.each do |k, v|
      v.each { |val| errors.add('template '+k.to_s, val) }
    end
  end<commit_msg>Remove a weird space<commit_after>class Character < ActiveRecord::Base
  belongs_to :user
  belongs_to :template
  belongs_to :default_icon, class_name: Icon
  belongs_to :character_group
  has_many :replies
  has_many :posts
  has_and_belongs_to_many :galleries
  has_many :character_tags, inverse_of: :character, dependent: :destroy
  has_many :tags, through: :character_tags

  validates_presence_of :name, :user
  validate :valid_template, :valid_group

  after_save :update_galleries

  attr_accessor :new_template_name, :group_name, :gallery_ids

  nilify_blanks

  def icon
    @icon ||= default_icon || galleries.detect(&:default_icon).try(:default_icon)
  end

  def icons
    @icons ||= galleries.map(&:icons).flatten.uniq_by(&:id)
  end

  def recent_posts(limit=25, page=1)
    return @recent unless @recent.nil?
    reply_ids = replies.group(:post_id).select(:post_id).map(&:post_id)
    post_ids = posts.select(:id).map(&:id)
    @recent ||= Post.where(id: (post_ids + reply_ids).uniq).order('tagged_at desc').paginate(per_page: limit, page: page)
  end

  def selector_name
    [name, template_name, screenname].compact.join(' | ')
  end

  private

  def valid_template
    return unless template_id == 0
    @template = Template.new(user: user, name: new_template_name)
    return if @template.valid?
    @template.errors.messages.each do |k, v|
      v.each { |val| errors.add('template '+k.to_s, val) }
    end
  end
{'fraction_non_alphanumeric': 0.11731843575418995, 'fraction_numerical': 0.002793296089385475, 'mean_word_length': 4.520231213872832, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2190244', 'n_tokens_mistral': 1027, 'n_tokens_neox': 984, 'n_words': 212}