<commit_before>module Category::Addon
  module Setting
    extend SS::Addon
    extend ActiveSupport::Concern

    included do
      embeds_ids :st_categories, class_name: "Category::Node::Base"
      permit_params st_category_ids: []
      define_method(:st_categories) do
        if st_categories_sortable?
          items = ::Category::Node::Base.in(id: st_category_ids).to_a
          return st_category_ids.map { |id| items.find { |item| item.id == id } }
        end

        ::Category::Node::Base.in(id: st_category_ids)
      end
    end

    def st_categories_sortable?
      false
    end

    def st_parent_categories
      categories = []
      parents = st_categories.sort_by { |cate| cate.filename.count("/") }
      while parents.present?
        parent = parents.shift
        parents = parents.map { |c| /^#{::Regexp.escape(parent.filename)}\//.match?(c.filename) ? nil : c }.compact
        categories << parent
      end
      categories
    end
  end
end<commit_msg>[fix] category addon setting st_categories (#4452)<commit_after>module Category::Addon
  module Setting
    extend SS::Addon
    extend ActiveSupport::Concern

    included do
      embeds_ids :st_categories, class_name: "Category::Node::Base"
      permit_params st_category_ids: []
      define_method(:st_categories) do
        if st_categories_sortable?
          items = ::Category::Node::Base.in(id: st_category_ids).to_a
          return items.sort_by { |item| st_category_ids.index(item.id) }
        end

        ::Category::Node::Base.in(id: st_category_ids)
      end
    end

    def st_categories_sortable?
      false
    end

    def st_parent_categories
      categories = []
      parents = st_categories.sort_by { |cate| cate.filename.count("/") }
      while parents.present?
        parent = parents.shift
        parents = parents.map { |c| /^#{::Regexp.escape(parent.filename)}\//.match?(c.filename) ? nil : c }.compact
        categories << parent
      end
      categories
    end
  end
end
{'fraction_non_alphanumeric': 0.11138861138861139, 'fraction_numerical': 0.001998001998001998, 'mean_word_length': 2.695571955719557, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4143602', 'n_tokens_mistral': 620, 'n_tokens_neox': 606, 'n_words': 129}