<commit_before># encoding: utf-8
module Mongoid
  module Extensions
    module Hash

      # Evolves each value in the hash to an object id if it is convertable.
      #
      # @example Convert the hash values.
      #   { field: id }.__evolve_object_id__
      #
      # @return [ Hash ] The converted hash.
      #
      # @since 3.0.0
      def __evolve_object_id__
        update_values(&:__evolve_object_id__)
      end

      # Mongoizes each value in the hash to an object id if it is convertable.
      #
      # @example Convert the hash values.
      #   { field: id }.__mongoize_object_id__
      #
      # @return [ Hash ] The converted hash.
      #
      # @since 3.0.0
      def __mongoize_object_id__
        update_values(&:__mongoize_object_id__)
      end

      # Consolidate the key/values in the hash under an atomic $set.
      #
      # @example Consolidate the hash.
      #   { name: "Placebo" }.__consolidate__
      #
      # @return [ Hash ] A new consolidated hash.
      #
      # @since 3.0.0
      def __consolidate__(klass)
        consolidated = {}
        each_pair do |key, value|
          if key =~ /\$/
            value.each_pair do |_key, _value|
              value[_key] = mongoize_for(key, klass, _key, _value)
            end
            (consolidated[key] ||= {}).merge!(value)
          else
            (consolidated["$set"] ||= {}).merge!(key => mongoize_for(key, klass, key, value))
          end
        end
        consolidated
      end

      # Check if the hash is part of a blank relation criteria.
      #
      # @example Is the hash blank criteria?
      #   {}.blank_criteria?
      #
      # @return [ true, false ] If the hash is blank criteria.
      #
      # @since 3.1.0
      def blank_criteria?
        self == { "_id" => { "$in" => [] }}
      end

      # Deletes an id value from the hash.
      #
      # @example Delete an id value.
      #   {}.delete_id<commit_msg>Fix hash consolidation for renaming field queries<commit_after># encoding: utf-8
module Mongoid
  module Extensions
    module Hash

      # Evolves each value in the hash to an object id if it is convertable.
      #
      # @example Convert the hash values.
      #   { field: id }.__evolve_object_id__
      #
      # @return [ Hash ] The converted hash.
      #
      # @since 3.0.0
      def __evolve_object_id__
        update_values(&:__evolve_object_id__)
      end

      # Mongoizes each value in the hash to an object id if it is convertable.
      #
      # @example Convert the hash values.
      #   { field: id }.__mongoize_object_id__
      #
      # @return [ Hash ] The converted hash.
      #
      # @since 3.0.0
      def __mongoize_object_id__
        update_values(&:__mongoize_object_id__)
      end

      # Consolidate the key/values in the hash under an atomic $set.
      #
      # @example Consolidate the hash.
      #   { name: "Placebo" }.__consolidate__
      #
      # @return [ Hash ] A new consolidated hash.
      #
      # @since 3.0.0
      def __consolidate__(klass)
        consolidated = {}
        each_pair do |key, value|
          if key == '$rename'
            #todo validate for collection column
            value.each_pair do |_key, _value|
              value[_key] = _value.to_s
            end
          elsif key =~ /\$/
            value.each_pair do |_key, _value|
              value[_key] = mongoize_for(key, klass, _key, _value)
            end
            (consolidated[key] ||= {}).merge!(value)
          else
            (consolidated["$set"] ||= {}).merge!(key => mongoize_for(key, klass, key, value))
          end
        end
        consolidated
      end

      # Check if the hash is part of a blank relation criteria.
      #
      # @example Is the hash blank criteria?
      #   {}.blank_criteria?
      #
      # @return [ true, false ] If the hash is blank criteria.
      #
      # @since 3.1.0
      def blank_criteria?
        self == { "_id" => { "$in" => [] }}
      end

      # Deletes an id value from the hash.
      #
      # @example Delete an id value.
      #   {}.delete_id
{'fraction_non_alphanumeric': 0.09941520467836257, 'fraction_numerical': 0.006335282651072124, 'mean_word_length': 1.733022636484687, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '7033885', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1255, 'n_words': 380}