<commit_before>require 'opal/hike_path_finder'

module Opal
  class PathReader
    def initialize(file_finder = HikePathFinder.new)
      @file_finder = file_finder
    end

    def read(path)
      full_path = expand(path)
      return nil if full_path.nil?
      File.open(full_path, 'rb:UTF-8'){|f| f.read}
    end

    def expand(path)
      if Pathname.new(path).absolute? || path =~ %r{\A\.?\.#{File::SEPARATOR}}
        path
      else
        file_finder.find(path)
      end
    end

    def paths
      file_finder.paths
    end

    def append_paths(*paths)
      file_finder.append_paths(*paths)
    end

    private

    attr_reader :file_finder
  end
end
<commit_msg>Use Opal::REGEXP_START in path reader<commit_after>require 'opal/regexp_anchors'
require 'opal/hike_path_finder'

module Opal
  class PathReader
    RELATIVE_PATH_REGEXP = %r{#{Opal::REGEXP_START}\.?\.#{File::SEPARATOR}}

    def initialize(file_finder = HikePathFinder.new)
      @file_finder = file_finder
    end

    def read(path)
      full_path = expand(path)
      return nil if full_path.nil?
      File.open(full_path, 'rb:UTF-8'){|f| f.read}
    end

    def expand(path)
      if Pathname.new(path).absolute? || path =~ RELATIVE_PATH_REGEXP
        path
      else
        file_finder.find(path)
      end
    end

    def paths
      file_finder.paths
    end

    def append_paths(*paths)
      file_finder.append_paths(*paths)
    end

    private

    attr_reader :file_finder
  end
end

{'fraction_non_alphanumeric': 0.09973045822102426, 'fraction_numerical': 0.0013477088948787063, 'mean_word_length': 2.613138686131387, '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': '6503771', 'n_tokens_mistral': 528, 'n_tokens_neox': 510, 'n_words': 104}