<commit_before>module Parse

  # Parse a JSON representation into a fully instantiated
  # class. obj can be either a string or a Hash as parsed
  # by JSON.parse
  # @param class_name [Object]
  # @param obj [Object]
  def Parse.parse_json(class_name, obj)

    if obj.nil?
      nil
    # String
    elsif obj.is_a? String
      parse_json class_name, JSON.parse(obj)

    # Array
    elsif obj.is_a? Array
      obj.collect { |o| parse_json(class_name, o) }

    # Hash
    elsif obj.is_a? Hash

      # If it's a datatype hash
      if obj.has_key?(Protocol::KEY_TYPE)
        parse_datatype obj
      elsif obj.size == 1 && obj.has_key?(Protocol::KEY_RESULTS) && obj[Protocol::KEY_RESULTS].is_a?(Array)
        obj[Protocol::KEY_RESULTS].collect { |o| parse_json(class_name, o) }
      else # otherwise it must be a regular object, so deep parse it avoiding re-JSON.parsing raw Strings
        Parse::Object.new class_name, Hash[obj.map{|k,v| [k, v.is_a?(String) ? v : parse_json(nil, v)]}]
      end

    else
      obj
    end
  end

  def Parse.parse_datatype(obj)
    type = obj[Protocol::KEY_TYPE]

    case type
      when Protocol::TYPE_POINTER
        Parse::Pointer.new obj
      when Protocol::TYPE_BYTES
        Parse::Bytes.new obj
      when Protocol::TYPE_DATE
        Parse::Date.new obj
    end
  end
end
<commit_msg>we've already JSON.parsed in the client so remove special casing of String here<commit_after>module Parse

  # Parse a JSON representation into a fully instantiated
  # class. obj can be either a string or a Hash as parsed
  # by JSON.parse
  # @param class_name [Object]
  # @param obj [Object]
  def Parse.parse_json(class_name, obj)

    if obj.nil?
      nil

    # Array
    elsif obj.is_a? Array
      obj.collect { |o| parse_json(class_name, o) }

    # Hash
    elsif obj.is_a? Hash

      # If it's a datatype hash
      if obj.has_key?(Protocol::KEY_TYPE)
        parse_datatype obj
      elsif obj.size == 1 && obj.has_key?(Protocol::KEY_RESULTS) && obj[Protocol::KEY_RESULTS].is_a?(Array)
        obj[Protocol::KEY_RESULTS].collect { |o| parse_json(class_name, o) }
      else # otherwise it must be a regular object, so deep parse it avoiding re-JSON.parsing raw Strings
        Parse::Object.new class_name, Hash[obj.map{|k,v| [k, parse_json(nil, v)]}]
      end

    # primitive
    else
      obj
    end
  end

  def Parse.parse_datatype(obj)
    type = obj[Protocol::KEY_TYPE]

    case type
      when Protocol::TYPE_POINTER
        Parse::Pointer.new obj
      when Protocol::TYPE_BYTES
        Parse::Bytes.new obj
      when Protocol::TYPE_DATE
        Parse::Date.new obj
    end
  end
end

{'fraction_non_alphanumeric': 0.0980761976612599, 'fraction_numerical': 0.0007544322897019992, 'mean_word_length': 2.729957805907173, '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': '6391241', 'n_tokens_mistral': 885, 'n_tokens_neox': 860, 'n_words': 250}