src/parser/match_lines.rb
# Determine which positive lines have the shortest exclusive distance a negative line
# As part of this no 2 positive lines can be related in similarity to a single negative line
# Note: white spaces can be removed, but by default are kept
# 
# It however does not use a stable sorting algorithm and thus could
# provide different pairings for lines that tie. Details given here:
# http://stackoverflow.com/questions/15442298/is-sort-in-ruby-stable
Determine which positive lines have the shortest exclusive distance a negative line
As part of this no 2 positive lines can be related in similarity to a single negative line
Note: white spaces can be removed, but by default are kept

It however does not use a stable sorting algorithm and thus could
provide different pairings for lines that tie.
Determine which positive lines have the shortest exclusive distance a negative line As part of this no 2 positive lines can be related in similarity to a single negative line Note : white spaces can be removed but by default are kept It however does not use a stable sorting algorithm and thus could provide different pairings for lines that tie .
def findShortestDistance(posLines, negLines, high_threshold = 0.5, low_threshold = 0.8, size_threshold = 0.5, one_to_many = false, whiteSpaces = false)
    $HIGH_THRESHOLD = high_threshold.to_f
    $LOW_THRESHOLD = low_threshold.to_f
    $SIZE_TRESHOLD = size_threshold.to_i
    $ONE_TO_MANY = one_to_many
    $removeWhiteSpaces = whiteSpaces
    posLines = replaceWhiteSpaces(posLines)
    negLines = replaceWhiteSpaces(negLines)
    used = Hash.new
    similarityIndex = findSimilarLines(posLines, negLines)
    similarityIndex.each { |i, v|
        if i != nil && !v.empty?
            v.each { |k, d|
                if used[k] == nil
                    used[k] = {i => d}
                    if !$ONE_TO_MANY
                        break
                    end
                elsif $ONE_TO_MANY && used[k][used[k].keys[0]] > d
                    used[k].delete(used[k].keys[0])
                    used[k] = {i => d}
                end
            }
        end
    }
    return used
end
def findShortestDistance ( posLines , negLines , high_threshold = 0.5 , low_threshold = 0.8 , size_threshold = 0.5 , one_to_many = false , whiteSpaces = false ) $HIGH_THRESHOLD = high_threshold . to_f $LOW_THRESHOLD = low_threshold . to_f $SIZE_TRESHOLD = size_threshold . to_i $ONE_TO_MANY = one_to_many $removeWhiteSpaces = whiteSpaces posLines = replaceWhiteSpaces ( posLines ) negLines = replaceWhiteSpaces ( negLines ) used = Hash . new similarityIndex = findSimilarLines ( posLines , negLines ) similarityIndex . each { | i , v | if i != nil && ! v . empty? v . each { | k , d | if used [ k ] == nil used [ k ] = { i => d } if ! $ONE_TO_MANY break end elsif $ONE_TO_MANY && used [ k ] [ used [ k ] . keys [ 0 ] ] > d used [ k ] . delete ( used [ k ] . keys [ 0 ] ) used [ k ] = { i => d } end } end } return used end
Determine which positive lines have the shortest exclusive distance a negative line
As part of this no 2 positive lines can be related in similarity to a single negative line
Note: white spaces can be removed, but by default are kept
Determine which positive lines have the shortest exclusive distance a negative line As part of this no 2 positive lines can be related in similarity to a single negative line Note : white spaces can be removed but by default are kept
# Positive Line Number => {Negative Line Number => distance} # i = current Positive Line Number # v = the pairs of {Negative Line Number => distance} that the current i maps to # k = the current Negative Line Number (one of, if any, that i maps to) # d = the distance calculated between posLines[i] and negLines[k] # used = the hash of values mapped by Negative Line Number => {Postive Line Number => distance} # it also indicates which mappings between positive and negative lines  #Negative Line Number => {Positive Line Number => distance} #puts "used = #{used}"
posLines
<not_specific>
negLines
<not_specific>
high_threshold
<not_specific>
low_threshold
<not_specific>
size_threshold
<not_specific>
one_to_many
<not_specific>
whiteSpaces
<not_specific>