<commit_before># encoding: utf-8

class JsonResolver
  include CacheTools
  @@app_controller = ApplicationController.new

  def self.resolve_efficiently(question_ids, root_count, current_user, qs_data = [])
    question_ids.map.with_index do |q, idx|
      # maximum depth of 5 questions. However, avoid going too deep for
      # later questions. For example, the last question never will
      # present a subquestion, regardless if it has one. Therefore, no
      # need to query for them.
      c = root_count - idx - 1
      r = JsonResolver.new(q, [c, 5].min, qs_data[q.id.to_s])
      r.current_user = current_user
      tmp = r.resolve

      # assert the generated data looks reasonable, otherwise skip it
      unless tmp.is_a?(Hash)
        raise <<-ERR
          JSON for Question #{q.id} returned an array when it should be a Hash

          #{PP.pp(q, "")}
          ERR
      end

      tmp
    end
  end


  def initialize(question, max_depth = 5, meta = {})
    @q = question
    @meta = meta
    @max_depth = max_depth
    @qjson = {}
  end<commit_msg>bug fix for empty meta data<commit_after># encoding: utf-8

class JsonResolver
  include CacheTools
  @@app_controller = ApplicationController.new

  def self.resolve_efficiently(question_ids, root_count, current_user, qs_data = [])
    question_ids.map.with_index do |q, idx|
      # maximum depth of 5 questions. However, avoid going too deep for
      # later questions. For example, the last question never will
      # present a subquestion, regardless if it has one. Therefore, no
      # need to query for them.
      c = root_count - idx - 1
      meta = qs_data.empty? ? {} : qs_data[q.id.to_s]
      r = JsonResolver.new(q, [c, 5].min, meta)
      r.current_user = current_user
      tmp = r.resolve

      # assert the generated data looks reasonable, otherwise skip it
      unless tmp.is_a?(Hash)
        raise <<-ERR
          JSON for Question #{q.id} returned an array when it should be a Hash

          #{PP.pp(q, "")}
          ERR
      end

      tmp
    end
  end


  def initialize(question, max_depth = 5, meta = {})
    @q = question
    @meta = meta
    @max_depth = max_depth
    @qjson = {}
  end
{'fraction_non_alphanumeric': 0.09161349134001823, 'fraction_numerical': 0.004557885141294439, 'mean_word_length': 2.4621451104100944, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4893697', 'n_tokens_mistral': 684, 'n_tokens_neox': 667, 'n_words': 229}