<commit_before># encoding: utf-8
class String

  def to_pinyin
    h = Hash.new
    idx_file_path = File.expand_path('../../data/idx99-tone.txt',__FILE__)
    open(idx_file_path,'r').each do |line|
      a = line.gsub("\n","").split("\t")
      h.store a[0], a[1]
    end
    result = ""
    self.scan(/./) do |char|
      if h[char]
        result = result + h[char] + " "
      else
        result = result + char
      end
    end
    return result.rstrip
  end

end<commit_msg>Switch to a more efficient grep based search method<commit_after># encoding: utf-8
class String

  def to_pinyin
    idx_file_path = File.expand_path('../../data/idx99-tone.txt',__FILE__)
    result = ""
    self.scan(/./) do |char|
      match = %x[grep -m1 '^#{char}' #{idx_file_path}]
      if match.empty?
        result = result + char
      else
        pinyin =  match.gsub("\n","").split("\t")[1]
        result = result + pinyin + " "
      end
    end
    return result.rstrip
  end
      
end
{'fraction_non_alphanumeric': 0.15447154471544716, 'fraction_numerical': 0.01016260162601626, 'mean_word_length': 2.126984126984127, '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': '2063650', 'n_tokens_mistral': 356, 'n_tokens_neox': 347, 'n_words': 81}