<commit_before>require 'rbbt/annotations'

module Entity
  class << self
    attr_accessor :formats, :entity_property_cache, :entity_list_cache
  end

  self.entity_property_cache = "cache/entity_property"
  self.entity_list_cache = "cache/entity_list"
  self.formats = {}
  
  def self.extended(base)
    base.extend Annotation unless Annotation === base

    Entity.formats[base.to_s] = base
    base.module_eval do
      class << self
        attr_accessor :template, :list_template, :action_template, :list_action_template
        alias prev_entity_extended extended
      end

      def self.extended(data)
        prev_entity_extended(data)
        data.extend AnnotatedArray if Array === data
        data
      end

      def self.format=(formats)
        formats = [formats] unless Array === formats
        formats.each do |format|
          Entity.formats[format] = self
        end
      end

      def clean_annotations
        case
        when Array === self
          self.annotated_array_clean_collect{|e| e.respond_to?(:clean_annotations)? e.clean_annotations : e}
        when String === self
          "" << self
        end
      end

      def to_yaml(*args)
        clean_annotations.to_yaml(*args)
      end

      def marshal_dump
        clean_annotations
      end

      def consolidate
        self.inject(nil){|acc,e| 
          if acc.nil?
            acc = e
          else
            acc.concat e
          end
        }
      end
    end
  end

  def property(name, &block)
    case
    when (Hash === name and name.size == 1)
      name, type = name.collect.first
    when (String === name or Symbol === name)<commit_msg>fixed a problem with repeatedly extending Entity<commit_after>require 'rbbt/annotations'

module Entity
  class << self
    attr_accessor :formats, :entity_property_cache, :entity_list_cache
  end

  self.entity_property_cache = "cache/entity_property"
  self.entity_list_cache = "cache/entity_list"
  self.formats = {}
  
  def self.extended(base)
    base.extend Annotation unless Annotation === base

    Entity.formats[base.to_s] = base
    base.module_eval do
      if not methods.include? "prev_entity_extended"
        class << self
          attr_accessor :template, :list_template, :action_template, :list_action_template
          alias prev_entity_extended extended 
        end 

        def self.extended(data)
          prev_entity_extended(data)
          data.extend AnnotatedArray if Array === data
          data
        end
      end

      def self.format=(formats)
        formats = [formats] unless Array === formats
        formats.each do |format|
          Entity.formats[format] = self
        end
      end

      def clean_annotations
        case
        when Array === self
          self.annotated_array_clean_collect{|e| e.respond_to?(:clean_annotations)? e.clean_annotations : e}
        when String === self
          "" << self
        end
      end

      def to_yaml(*args)
        clean_annotations.to_yaml(*args)
      end

      def marshal_dump
        clean_annotations
      end

      def consolidate
        self.inject(nil){|acc,e| 
          if acc.nil?
            acc = e
          else
            acc.concat e
          end
        }
      end
    end 
  end

  def property(name, &block)
    case
    when (Hash === name and name.size == 1)
      name, type = name.collect.first
    when (String === name or Symbol === name)
{'fraction_non_alphanumeric': 0.08330905913195456, 'fraction_numerical': 0.0005825808330905913, 'mean_word_length': 2.0936936936936936, 'pattern_counts': {'":': 0, '<': 15, '<?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': '187865', 'n_tokens_mistral': 1013, 'n_tokens_neox': 977, 'n_words': 248}