Class: NeedlemanWunschAligner::ExampleParagraphAndSentenceAligner
- Inherits:
-
NeedlemanWunschAligner
- Object
- NeedlemanWunschAligner
- NeedlemanWunschAligner::ExampleParagraphAndSentenceAligner
- Defined in:
- lib/needleman_wunsch_aligner/example_paragraph_and_sentence_aligner.rb
Constant Summary
Constants inherited from NeedlemanWunschAligner
Instance Method Summary collapse
-
#compute_score(left_el, top_el) ⇒ Object
Get score for alignment pair of paragraphs and sentences.
- #default_gap_penalty ⇒ Object
- #gap_indicator ⇒ Object
Methods inherited from NeedlemanWunschAligner
#get_optimal_alignment, #initialize, #inspect_alignment, #inspect_matrix
Constructor Details
This class inherits a constructor from NeedlemanWunschAligner
Instance Method Details
#compute_score(left_el, top_el) ⇒ Object
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] return [Integer]
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/needleman_wunsch_aligner/example_paragraph_and_sentence_aligner.rb', line 20 def compute_score(left_el, top_el) 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 ⇒ Object
42 43 44 |
# File 'lib/needleman_wunsch_aligner/example_paragraph_and_sentence_aligner.rb', line 42 def default_gap_penalty -10 end |
#gap_indicator ⇒ Object
46 47 48 |
# File 'lib/needleman_wunsch_aligner/example_paragraph_and_sentence_aligner.rb', line 46 def gap_indicator { type: :gap } end |