<commit_before>class Category < ActiveRecord::Base
  require "lib/utils.rb"
  acts_as_tree :order => "name"
  has_many :metapackages
  belongs_to :category, :foreign_key => 'parent_id'

  def name
    translation(self.name_tid)
  end

  def description
    translation(self.description_tid)
  end

  def link
    trans = translation(self.link_tid)
    if trans == "unknown"
      trans = ""
    end
    return trans
  end

  def parent_name
    if category.nil? then "" else category.name end
  end
  
  def self.draw_tree
    f=File.open("categories.dot","w")
    f.puts "digraph G {"
    Category.find(1).draw_tree_aux(f)
    f.puts "}"
    f.close
  end
  
  def draw_tree_aux(f)
    f.puts '"'+self.name+'";'
    self.children.each do |child|
      f.puts '"'+self.name+'" -> "'+child.name+'";'
      child.draw_tree_aux(f)
    end
  end

  def default_bundles
    BasePackage.find_all_by_default_install_and_category_id(true,self.id)
  end
end<commit_msg>also use subcategories for selection of default bundles<commit_after>class Category < ActiveRecord::Base
  require "lib/utils.rb"
  acts_as_tree :order => "name"
  has_many :metapackages
  belongs_to :category, :foreign_key => 'parent_id'
  has_many :categories, :foreign_key => 'parent_id'

  def name
    translation(self.name_tid)
  end

  def description
    translation(self.description_tid)
  end

  def link
    trans = translation(self.link_tid)
    if trans == "unknown"
      trans = ""
    end
    return trans
  end

  def parent_name
    if category.nil? then "" else category.name end
  end

  def children
    categories
  end

  def recursive_children
    ch = children
    ([self] + ch + ch.map{|c| c.recursive_children}.flatten).uniq
  end

  def self.draw_tree
    f=File.open("categories.dot","w")
    f.puts "digraph G {"
    Category.find(1).draw_tree_aux(f)
    f.puts "}"
    f.close
  end
  
  def draw_tree_aux(f)
    f.puts '"'+self.name+'";'
    self.children.each do |child|
      f.puts '"'+self.name+'" -> "'+child.name+'";'
      child.draw_tree_aux(f)
    end
  end

  def default_bundles
    (recursive_children.map do |c|
      BasePackage.find_all_by_default_install_and_category_id(true,c.id)
    end).flatten
  end
end
{'fraction_non_alphanumeric': 0.11732851985559567, 'fraction_numerical': 0.0009025270758122744, 'mean_word_length': 3.0828729281767955, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '475499', 'n_tokens_mistral': 808, 'n_tokens_neox': 795, 'n_words': 169}