<commit_before>module Codily
  class Dumper
    def initialize(root)
      @root = root
    end

    attr_reader :root

    def tree
      # :children:
      #   service: (element_tree)
      #     KEY:
      #       :self: Elements::Base
      #       :children:
      #         healthcheck:
      #           KEY:
      #             :self: Elements::Base
      @tree ||= {self: root, children: {}}.tap do |tree|
        root.elements.each_key.sort_by { |klass| klass.path.size }.each do |klass|
          elements = root.list_element(klass)
          elements.each do |key, element|
            parents = element.parents
            subtree = parents.inject(tree) { |r,i| r[:children][i.class.name_for_attr][i.key] }
            (subtree[:children][element.class.name_for_attr] ||= {})[element.key] = {self: element, children: {}}
          end
        end
      end
    end

    def simple_tree
      simplize_tree tree
    end<commit_msg>dump Condition earlier<commit_after>require 'codily/elements/condition'

module Codily
  class Dumper
    def initialize(root)
      @root = root
    end

    attr_reader :root

    def tree
      # :children:
      #   service: (element_tree)
      #     KEY:
      #       :self: Elements::Base
      #       :children:
      #         healthcheck:
      #           KEY:
      #             :self: Elements::Base
      @tree ||= {self: root, children: {}}.tap do |tree|
        root.elements.each_key.sort_by { |klass| [klass.path.size, klass == Elements::Condition ? 0 : 1] }.each do |klass|
          elements = root.list_element(klass)

          elements.each do |key, element|
            parents = element.parents
            subtree = parents.inject(tree) { |r,i| r[:children][i.class.name_for_attr][i.key] }
            (subtree[:children][element.class.name_for_attr] ||= {})[element.key] = {self: element, children: {}}
          end
        end
      end
    end

    def simple_tree
      simplize_tree tree
    end
{'fraction_non_alphanumeric': 0.12214901165737456, 'fraction_numerical': 0.0010136847440446021, 'mean_word_length': 1.8944281524926687, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7017328', 'n_tokens_mistral': 616, 'n_tokens_neox': 606, 'n_words': 133}