<commit_before># REPL commands
class REPL
  def initialize(file_path)
    @path = file_path
    load_file
    show_repl
  end

  def load_file
    lines = File.readlines(@path)
    @objects = []

    lines.each do |line|
      item = Item.new(line)
      @objects.push(item)
    end
  end

  def show_repl
    while true
      line_num ||= 1
      ("%03d" % line_num + ' > ').display
      statement = $stdin.gets.chomp

      puts eval(statement.strip)

      line_num += 1
    end
  end

  def display_list(items)
    items.each do |o|
      puts " " + o.content
    end
  end

  def eval(statement)
    output_text = ""

    case statement
    when /((^exit$)|(^quit$))/i # Exit application
      exit
    when /^show(\s+all)?$/i
      display_list @objects
    end

    output_text
  end
end

# Object for each item in file

class Item
  attr_reader :tags, :content

  def initialize(text)
    @content = text.chomp
    @tags = Item.get_tags(text)
  end
<commit_msg>Add "load" command and consider absolute or relative paths.<commit_after>require 'pathname'

class REPL
  def initialize(file_path)
    @path = file_path
    load_file
    show_repl
  end

  def load_file
    lines = File.readlines(@path)
    @objects = []

    lines.each do |line|
      item = Item.new(line)
      @objects.push(item)
    end

    puts "  #{@objects.length} items loaded from: #{@path}"
  rescue
    puts "  Error: failed to load file: #{@path}"
  end

  def show_repl
    while true
      line_num ||= 1
      ("%03d" % line_num + ' > ').display
      statement = $stdin.gets.chomp

      puts eval(statement.strip)

      line_num += 1
    end
  end

  def display_list(items)
    items.each do |o|
      puts " " + o.content
    end
  end

  def eval(statement)
    output_text = ""

    case statement
    when /((^exit$)|(^quit$))/i
      #Exit application
      exit
    when /^show(\s+all)?$/i
      #Display all loaded items
      display_list @objects
    when /^load\s+((?<path>[^\'\"\s]+)|([\'\"](?<path>.*)[\'\"]))$/i
      #Load a file's items
      @path = $~[:path]

      # Expand relative path
      if not /([a-zA-Z]:)?(\\\\[a-zA-Z0-9_.-]+)+\\\\?/.match(@path)
        @path = File.expand_path(@path, Dir.pwd)
      end

      load_file
    end

    output_text
  end
end

# Object for each item in file

class Item
  attr_reader :tags, :content

  def initialize(text)
    @content = text.chomp
    @tags = Item.get_tags(text)
  end

{'fraction_non_alphanumeric': 0.13396149119213438, 'fraction_numerical': 0.004096681687832855, 'mean_word_length': 2.2301587301587302, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3117779', 'n_tokens_mistral': 895, 'n_tokens_neox': 859, 'n_words': 218}