<commit_before>##
# Test data for use in populations so we don't need redis, mgrep, 4store, etc
def gzip_read(path)
  data = nil
  Zlib::GzipReader.open(path) do |gz|
    begin
      data = Marshal.load(gz.read)
    ensure
      gz.close
    end
  end
  data
end
$test_converted = gzip_read(File.expand_path("../data/converted.dump.gz", __FILE__))
$test_annotations = gzip_read(File.expand_path("../data/annotations.dump.gz", __FILE__))
$test_annotation_counts = gzip_read(File.expand_path("../data/annotation_counts.dump.gz", __FILE__))
$test_annotation_counts_anc = gzip_read(File.expand_path("../data/annotation_counts_anc.dump.gz", __FILE__))
$test_ancestors = gzip_read(File.expand_path("../data/ancestors.dump.gz", __FILE__))
$test_latest_sub = gzip_read(File.expand_path("../data/latest_sub.dump.gz", __FILE__))

##
# Monkeypatched mock methods for use in populations so we don't need redis, mgrep, 4store, etc
class RI::Population::LabelConverter
  def convert(mgrep_matches)
    $test_converted[mgrep_matches]
  end
end

module MockMGREP
  def annotate(text,longword,wholeword=true)
    $test_annotations[text]
  end
end

class RI::Population::Mgrep::Client
  include MockMGREP
end

class MockMGREPClient
  include MockMGREP
end

class RI::Population::Class
  def retrieve_ancestors(acronym, submission_id)
    $test_ancestors[self.xxhash]
  end
end

class RI::Population::Manager
  def latest_submissions_sparql
    $test_latest_sub<commit_msg>Add extra argument for test mock<commit_after>##
# Test data for use in populations so we don't need redis, mgrep, 4store, etc
def gzip_read(path)
  data = nil
  Zlib::GzipReader.open(path) do |gz|
    begin
      data = Marshal.load(gz.read)
    ensure
      gz.close
    end
  end
  data
end
$test_converted = gzip_read(File.expand_path("../data/converted.dump.gz", __FILE__))
$test_annotations = gzip_read(File.expand_path("../data/annotations.dump.gz", __FILE__))
$test_annotation_counts = gzip_read(File.expand_path("../data/annotation_counts.dump.gz", __FILE__))
$test_annotation_counts_anc = gzip_read(File.expand_path("../data/annotation_counts_anc.dump.gz", __FILE__))
$test_ancestors = gzip_read(File.expand_path("../data/ancestors.dump.gz", __FILE__))
$test_latest_sub = gzip_read(File.expand_path("../data/latest_sub.dump.gz", __FILE__))

##
# Monkeypatched mock methods for use in populations so we don't need redis, mgrep, 4store, etc
class RI::Population::LabelConverter
  def convert(mgrep_matches, annotations)
    $test_converted[mgrep_matches]
  end
end

module MockMGREP
  def annotate(text,longword,wholeword=true)
    $test_annotations[text]
  end
end

class RI::Population::Mgrep::Client
  include MockMGREP
end

class MockMGREPClient
  include MockMGREP
end

class RI::Population::Class
  def retrieve_ancestors(acronym, submission_id)
    $test_ancestors[self.xxhash]
  end
end

class RI::Population::Manager
  def latest_submissions_sparql
    $test_latest_sub
{'fraction_non_alphanumeric': 0.11462585034013606, 'fraction_numerical': 0.0013605442176870747, 'mean_word_length': 5.297644539614561, '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': '1427945', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1035, 'n_words': 207}