<commit_before>module LevenshteinRb
  class LevenshteinDistance

    # Ruby implementation of
    # Levenshtein distance algorithm
    # that measures the similarity of
    # two strings.
    #
    # Highly inspired by:
    # http://rosettacode.org/wiki/Levenshtein_distance#Ruby

    # A demonstration; the table of numbers is the
    # "recurrence matrix". ε means the "empty word".
    #
    #    | ε T o r
    #  -----------
    #  ε | 0 1 2 3
    #  T | 1 0 1 2
    #  i | 2 1 1 2
    #  e | 3 2 2 2
    #  r | 4 3 3 2
    #            ↑
    #          This last value is the Levenshtein distance

    class RecurrenceMatrix

      attr_reader :store

      delegate :[], :[]=, to: :store

      def initialize(m, n)
        @store = Array.new(m+1) { Array.new(n+1) }

        (0..m).each { |i| store[i][0] = i }
        (0..n).each { |j| store[0][j] = j }
      end

    end

    attr_reader :s, :t, :m, :n, :d

    def initialize(a_string, another_string)
      @s, @t = a_string, another_string
      @m, @n = s.length.to_i, t.length.to_i
      @d     = RecurrenceMatrix.new(m, n) # d is simply the default notation for a recurrence matrix in literature
    end

    def to_i
      # If one of the strings is empty,
      # and the other string has length n
      # it takes exactly n steps to "build"
      # this string starting with the empty
      # word<commit_msg>Replace delegate with naive delegation implementation<commit_after>module LevenshteinRb
  class LevenshteinDistance

    # Ruby implementation of
    # Levenshtein distance algorithm
    # that measures the similarity of
    # two strings.
    #
    # Highly inspired by:
    # http://rosettacode.org/wiki/Levenshtein_distance#Ruby

    # A demonstration; the table of numbers is the
    # "recurrence matrix". ε means the "empty word".
    #
    #    | ε T o r
    #  -----------
    #  ε | 0 1 2 3
    #  T | 1 0 1 2
    #  i | 2 1 1 2
    #  e | 3 2 2 2
    #  r | 4 3 3 2
    #            ↑
    #          This last value is the Levenshtein distance

    class RecurrenceMatrix

      attr_reader :store

      def [](index)
        store[index]
      end

      def []=(index, value)
        store[index] = value
      end

      def initialize(m, n)
        @store = Array.new(m+1) { Array.new(n+1) }

        (0..m).each { |i| store[i][0] = i }
        (0..n).each { |j| store[0][j] = j }
      end

    end

    attr_reader :s, :t, :m, :n, :d

    def initialize(a_string, another_string)
      @s, @t = a_string, another_string
      @m, @n = s.length.to_i, t.length.to_i
      @d     = RecurrenceMatrix.new(m, n) # d is simply the default notation for a recurrence matrix in literature
    end

    def to_i
      # If one of the strings is empty,
      # and the other string has length n
      # it takes exactly n steps to "build"
      # this string starting with the empty
      # word
{'fraction_non_alphanumeric': 0.10701876302988186, 'fraction_numerical': 0.018068102849200834, 'mean_word_length': 1.8703888334995016, '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': '4543442', 'n_tokens_mistral': 1044, 'n_tokens_neox': 951, 'n_words': 329}