<commit_before>module Setup
  class MappingConverter < ConverterTransformation
    include WithSourceOptions
    include RailsAdmin::Models::Setup::MappingConverterAdmin

    build_in_data_type.and(properties: { mapping: { type: {} } }).excluding(:map_attributes).referenced_by(:namespace, :name)

    field :map_attributes, type: Hash, default: {}

    validates_presence_of :target_data_type, :map_attributes

    def execute(options)
      options[:target] = do_map(options[:source])
    end

    def write_attribute(name, value)
      if name.to_s == 'map_attributes'
        value.delete('_type')
        value.delete(:_type)
        value.each do |k, v|
          if v.present? && map_model.property?(k)
            if map_model.associations[k]
              if v.is_a?(Hash)
                v.delete_if { |sub_k, sub_v| %w(source transformation_id options).exclude?(sub_k.to_s) || !sub_v.is_a?(String) || sub_v.blank? }
                value.delete(k) if v.empty?
              else
                value.delete(k)
              end<commit_msg>Including parse options methods on mapping converters<commit_after>module Setup
  class MappingConverter < ConverterTransformation
    include WithSourceOptions
    include Setup::TranslationCommon::ClassMethods
    include RailsAdmin::Models::Setup::MappingConverterAdmin

    build_in_data_type.and(properties: { mapping: { type: {} } }).excluding(:map_attributes).referenced_by(:namespace, :name)

    field :map_attributes, type: Hash, default: {}

    validates_presence_of :target_data_type, :map_attributes

    def execute(options)
      options[:target] = do_map(options[:source])
    end

    def write_attribute(name, value)
      if name.to_s == 'map_attributes'
        value.delete('_type')
        value.delete(:_type)
        value.each do |k, v|
          if v.present? && map_model.property?(k)
            if map_model.associations[k]
              if v.is_a?(Hash)
                v.delete_if { |sub_k, sub_v| %w(source transformation_id options).exclude?(sub_k.to_s) || !sub_v.is_a?(String) || sub_v.blank? }
                value.delete(k) if v.empty?
              else
                value.delete(k)
              end
{'fraction_non_alphanumeric': 0.11308709530323757, 'fraction_numerical': 0.0, 'mean_word_length': 2.8558875219683655, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1671909', 'n_tokens_mistral': 674, 'n_tokens_neox': 658, 'n_words': 127}