<commit_before># encoding: utf-8
module KindleClippings
  
  class Parser
    ['clipping', 'clippingresult'].each { |file| require File.expand_path(File.dirname(__FILE__) + '/' + file) }
    
    def parse_file(path)
      parse(File.open(path, :encoding => "UTF-8").read)
    end
    
    def parse(filecontent)
      @clippings = ClippingResult.new
      
      filecontent.split("=" * 10).each do |clipping|
        
        a_clipping = parse_clipping(clipping)
        
        if a_clipping
          @clippings << a_clipping
        end
        
        
      end
      @clippings
    end
    
    private
    
    def parse_clipping(clipping)
      clipping.lstrip!
      
      lines = Array.new
      <commit_msg>Forcing UTF-8 encoding broke 1.8.* compatibility.<commit_after># encoding: utf-8
module KindleClippings
  
  class Parser
    ['clipping', 'clippingresult'].each { |file| require File.expand_path(File.dirname(__FILE__) + '/' + file) }
    
    def parse_file(path)
      
      file_content = String.new
      
      if RUBY_VERSION =~ /^1\.8/
        file_content = open(path).read
      else
        file_content = File.open(path, :encoding => "UTF-8").read
      end
      
      parse(file_content)
    end
    
    def parse(filecontent)
      @clippings = ClippingResult.new
      
      filecontent.split("=" * 10).each do |clipping|
        
        a_clipping = parse_clipping(clipping)
        
        if a_clipping
          @clippings << a_clipping
        end
        
        
      end
      @clippings
    end
    
    private
    
    def parse_clipping(clipping)
      clipping.lstrip!
      
      lines = Array.new
      
{'fraction_non_alphanumeric': 0.09783913565426171, 'fraction_numerical': 0.0078031212484993995, 'mean_word_length': 1.7969798657718121, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '6502018', 'n_tokens_mistral': 540, 'n_tokens_neox': 527, 'n_words': 102}