class NeedlemanWunschAligner::ExampleParagraphAndSentenceAligner

Public Instance Methods

compute_score(left_el, top_el, row_index, col_index) click to toggle source

Get score for alignment pair of paragraphs and sentences. Aligner prioritizes alignment of paragraphs over that of sentences.

       p/1   p/2   p/nil s/a   s/b   s/nil
p/1    25    -25   -25   -250  -250  -250
p/2          25    -25   -250  -250  -250
p/nil              25    -250  -250  -250
s/a                      10    -10   -10
s/b                            10    -10
s/nil                                10

@param left_el [Hash] @param top_el [Hash] @param row_index [Integer] zero based row index, origin is at top. @param col_index [Integer] zero based column index, origin is to the left. @return [Integer]

# File lib/needleman_wunsch_aligner/example_paragraph_and_sentence_aligner.rb, line 21
def compute_score(left_el, top_el, row_index, col_index)
  score = 0
  if left_el[:type] == top_el[:type]
    # Match on type (paragraph vs. sentence)
    case left_el[:type]
    when :paragraph
      score += left_el[:id] == top_el[:id] ? 25 : -25
    when :sentence
      score += left_el[:id] == top_el[:id] ? 10 : -10
    else
      raise "Handle this: #{ [left_el, top_el].inspect }"
    end
  elsif [left_el, top_el].any? { |e| :paragraph == e[:type] }
    # Difference in type, one is :paragraph. This is more significant
    # than sentences.
    score += -250
  else
    raise "Handle this: #{ [left_el, top_el].inspect }"
  end
  score
end
default_gap_penalty() click to toggle source
# File lib/needleman_wunsch_aligner/example_paragraph_and_sentence_aligner.rb, line 43
def default_gap_penalty
  -10
end
gap_indicator() click to toggle source
# File lib/needleman_wunsch_aligner/example_paragraph_and_sentence_aligner.rb, line 47
def gap_indicator
  { type: :gap }
end