<commit_before># @abstract
class Classification < ActiveRecord::Base
  include Searchable
  include SimpleWorkflow

  searchable title: :name,
             link: :search_link,
             content: :description,
             description: :description_without_markup,
             format: 'topic',
             slug: :slug

  has_many :classification_memberships, inverse_of: :classification
  has_many :editions, through: :classification_memberships

  has_many :organisation_classifications
  has_many :organisations, through: :organisation_classifications
  has_many :classification_relations, inverse_of: :classification
  has_many :related_classifications,
            through: :classification_relations,
            before_remove: -> pa, rpa {
              ClassificationRelation.relation_for(pa.id, rpa.id).destroy_inverse_relation
            }

  has_many :classification_featurings,
            -> { where("editions.state = 'published' or classification_featurings.edition_id is null").
                 references(:edition).
                 includes(edition: :translations).
                 order("classification_featurings.ordering asc") },
            foreign_key: :classification_id,
            inverse_of: :classification

  has_many :featured_editions,
            -> { order("classification_featurings.ordering ASC") },
            through: :classification_featurings,
            source: :edition

  has_many :classification_policies

  validates_with SafeHtmlValidator
  validates_with NoFootnotesInGovspeakValidator, attribute: :description

  validates :name, presence: true, uniqueness: true
  validates :description, presence: true

  accepts_nested_attributes_for :classification_memberships
  accepts_nested_attributes_for :organisation_classifications
  accepts_nested_attributes_for :classification_featurings

  has_many :offsite_links, as: :parent

  scope :alphabetical, -> { order("name ASC") }

  mount_uploader :logo, ImageUploader, mount_on: :carrierwave_image

  extend FriendlyId
  friendly_id

  def self.grouped_by_type
    Rails.cache.fetch("filter_options/topics", expires_in: 30.minutes) do
      {
        'Topics' => Topic.alphabetical.map { |o| [o.name, o.slug] },
        'Topical events' => TopicalEvent.active.order_by_start_date.map { |o| [o.name, o.slug] }
      }
    end
  end

  def published_editions
    editions.published
  end

  def scheduled_editions
    editions.scheduled.order('scheduled_publication ASC')
  end

  def published_announcements
    published_editions.announcements
  end
<commit_msg>Rename Topic to PolicyArea in models<commit_after># @abstract
class Classification < ActiveRecord::Base
  include Searchable
  include SimpleWorkflow

  searchable title: :name,
             link: :search_link,
             content: :description,
             description: :description_without_markup,
             format: 'topic',
             slug: :slug

  has_many :classification_memberships, inverse_of: :classification
  has_many :editions, through: :classification_memberships

  has_many :organisation_classifications
  has_many :organisations, through: :organisation_classifications
  has_many :classification_relations, inverse_of: :classification
  has_many :related_classifications,
            through: :classification_relations,
            before_remove: -> pa, rpa {
              ClassificationRelation.relation_for(pa.id, rpa.id).destroy_inverse_relation
            }

  has_many :classification_featurings,
            -> { where("editions.state = 'published' or classification_featurings.edition_id is null").
                 references(:edition).
                 includes(edition: :translations).
                 order("classification_featurings.ordering asc") },
            foreign_key: :classification_id,
            inverse_of: :classification

  has_many :featured_editions,
            -> { order("classification_featurings.ordering ASC") },
            through: :classification_featurings,
            source: :edition

  has_many :classification_policies

  validates_with SafeHtmlValidator
  validates_with NoFootnotesInGovspeakValidator, attribute: :description

  validates :name, presence: true, uniqueness: true
  validates :description, presence: true

  accepts_nested_attributes_for :classification_memberships
  accepts_nested_attributes_for :organisation_classifications
  accepts_nested_attributes_for :classification_featurings

  has_many :offsite_links, as: :parent

  scope :alphabetical, -> { order("name ASC") }

  mount_uploader :logo, ImageUploader, mount_on: :carrierwave_image

  extend FriendlyId
  friendly_id

  def self.grouped_by_type
    Rails.cache.fetch("filter_options/topics", expires_in: 30.minutes) do
      {
        'Policy areas' => Topic.alphabetical.map { |o| [o.name, o.slug] },
        'Topical events' => TopicalEvent.active.order_by_start_date.map { |o| [o.name, o.slug] }
      }
    end
  end

  def published_editions
    editions.published
  end

  def scheduled_editions
    editions.scheduled.order('scheduled_publication ASC')
  end

  def published_announcements
    published_editions.announcements
  end

{'fraction_non_alphanumeric': 0.0780128080729672, 'fraction_numerical': 0.0007762468464971861, 'mean_word_length': 3.509186351706037, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3192966', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1434, 'n_words': 298}