def calculate_with_diff
      progress_bar = nil
      if @config[:show_progress]
        progress_bar = ProgressBar.create format: '%a |%B| %p%% %e', length: 80, smoothing: 0.5,
                                         total: @sources.length*(@sources.length-1)/2
      end

      matrix = {}
      @sources.each_with_index do |a,i|
        a_id = id_of(a)
        a_text = text_of(a)

        @sources[i + 1..-1].each do |b|
          b_id   = id_of(b)
          b_text = text_of(b)

          stats = FastHtmlDiff::DiffBuilder.new(a_text, b_text).statistics

          # http://en.wikipedia.org/wiki/Dice%27s_coefficient
          total_count = 2 * stats[:matches][:words] + stats[:insertions][:words] + stats[:deletions][:words]
          similarity = 2 * stats[:matches][:words] / total_count.to_f

          # Build the similarity matrix,
          matrix[a_id] ||= {a_id => 1}
          matrix[a_id][b_id] = similarity
          matrix[b_id] ||= {b_id => 1}
          matrix[b_id][a_id] = similarity

          progress_bar.increment unless progress_bar.nil?
        end
      end
      matrix
    end
def calculate_with_diff
      progress_bar = nil
      if @config[:show_progress]
        progress_bar = ProgressBar.create format: '%a |%B| %p%% %e', length: 80, smoothing: 0.5,
                                         total: @sources.length*(@sources.length-1)/2
      end

      matrix = {}
      @sources.each_with_index do |a,i|
        a_id = id_of(a)
        a_text = text_of(a)

        @sources[i + 1..-1].each do |b|
          b_id   = id_of(b)
          b_text = text_of(b)

          stats = FastHtmlDiff::DiffBuilder.new(a_text, b_text).statistics

          # http://en.wikipedia.org/wiki/Dice%27s_coefficient
          total_count = 2 * stats[:matches][:words] + stats[:insertions][:words] + stats[:deletions][:words]
          similarity = 2 * stats[:matches][:words] / total_count.to_f

          # Build the similarity matrix,
          matrix[a_id] ||= {a_id => 1}
          matrix[a_id][b_id] = similarity
          matrix[b_id] ||= {b_id => 1}
          matrix[b_id][a_id] = similarity

          progress_bar.increment unless progress_bar.nil?
        end
      end
      matrix
    end
Create a similarity matrix, using diff as the similarity measure, based on the difference of WORDS (not characters)
 (only counts insertions and deletions, not substitution and transposition).