<commit_before>module Legendator
  class File
    def initialize(file)
      @file = ::File.open(::File.expand_path(file),"r")
      #fix the file encode to remove the InvalidArgument error
      @file_content = IO.read(@file).force_encoding("ISO-8859-1").encode("utf-8",replace: nil)
      #defines the subtitle's regex
      @subtitle_regex =  /(\d+)\s+(\d+:\d+:\d+,\d+)\s+-->\s+(\d+:\d+:\d+,\d+)\s+(.+)/
    end
    
    def subtitle(position)
      matches = @file_content.scan @subtitle_regex
      matched = nil
      
      matches.each do |match|
        matched ||= match if match[0] == position.to_s 
      end
			
      subtitle = {position: matched[0].to_i,starts_at: matched[1],ends_at: matched[2],text: matched[3]}
    end
  end
end
<commit_msg>Update legendator.rb<commit_after>module Legendator
  class File
    def initialize(file)
      @file = ::File.open(::File.expand_path(file),"r")
      #fix the file encode to remove the InvalidArgument error
      @file_content = IO.read(@file).force_encoding("ISO-8859-1").encode("utf-8",replace: nil)
      @subtitle_regex =  /(\d+)\s+(\d+:\d+:\d+,\d+)\s+-->\s+(\d+:\d+:\d+,\d+)\s+(.+)/
    end
    
    def subtitle(position)
      matches = @file_content.scan @subtitle_regex
      matched = nil
      
      matches.each do |match|
        matched ||= match if match[0] == position.to_s 
      end
			
      subtitle = {position: matched[0].to_i,starts_at: matched[1],ends_at: matched[2],text: matched[3]}
    end
  end
end

{'fraction_non_alphanumeric': 0.17394224311618536, 'fraction_numerical': 0.014775016789791807, 'mean_word_length': 2.8701298701298703, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6672928', 'n_tokens_mistral': 542, 'n_tokens_neox': 524, 'n_words': 101}