Class: TextAlignment::MixedAlignment
- Inherits:
-
Object
- Object
- TextAlignment::MixedAlignment
- Defined in:
- lib/text_alignment/mixed_alignment.rb
Instance Attribute Summary collapse
-
#common_elements ⇒ Object
readonly
Returns the value of attribute common_elements.
-
#mapped_elements ⇒ Object
readonly
Returns the value of attribute mapped_elements.
-
#position_map_begin ⇒ Object
readonly
Returns the value of attribute position_map_begin.
-
#position_map_end ⇒ Object
readonly
Returns the value of attribute position_map_end.
-
#sdiff ⇒ Object
readonly
Returns the value of attribute sdiff.
-
#similarity ⇒ Object
readonly
Returns the value of attribute similarity.
-
#str1_match_final ⇒ Object
readonly
Returns the value of attribute str1_match_final.
-
#str1_match_initial ⇒ Object
readonly
Returns the value of attribute str1_match_initial.
-
#str2_match_final ⇒ Object
readonly
Returns the value of attribute str2_match_final.
-
#str2_match_initial ⇒ Object
readonly
Returns the value of attribute str2_match_initial.
Instance Method Summary collapse
-
#initialize(_str1, _str2, mappings = nil) ⇒ MixedAlignment
constructor
A new instance of MixedAlignment.
- #transform_a_span(span) ⇒ Object
- #transform_begin_position(begin_position) ⇒ Object
- #transform_denotations!(denotations) ⇒ Object
- #transform_end_position(end_position) ⇒ Object
- #transform_hdenotations(hdenotations) ⇒ Object
- #transform_spans(spans) ⇒ Object
Constructor Details
#initialize(_str1, _str2, mappings = nil) ⇒ MixedAlignment
Returns a new instance of MixedAlignment.
20 21 22 23 24 25 26 27 28 |
# File 'lib/text_alignment/mixed_alignment.rb', line 20 def initialize(_str1, _str2, mappings = nil) raise ArgumentError, "nil string" if _str1.nil? || _str2.nil? mappings ||= TextAlignment::CHAR_MAPPING str1 = _str1.dup str2 = _str2.dup _compute_mixed_alignment(str1, str2, mappings) end |
Instance Attribute Details
#common_elements ⇒ Object (readonly)
Returns the value of attribute common_elements.
16 17 18 |
# File 'lib/text_alignment/mixed_alignment.rb', line 16 def common_elements @common_elements end |
#mapped_elements ⇒ Object (readonly)
Returns the value of attribute mapped_elements.
16 17 18 |
# File 'lib/text_alignment/mixed_alignment.rb', line 16 def mapped_elements @mapped_elements end |
#position_map_begin ⇒ Object (readonly)
Returns the value of attribute position_map_begin.
15 16 17 |
# File 'lib/text_alignment/mixed_alignment.rb', line 15 def position_map_begin @position_map_begin end |
#position_map_end ⇒ Object (readonly)
Returns the value of attribute position_map_end.
15 16 17 |
# File 'lib/text_alignment/mixed_alignment.rb', line 15 def position_map_end @position_map_end end |
#sdiff ⇒ Object (readonly)
Returns the value of attribute sdiff.
14 15 16 |
# File 'lib/text_alignment/mixed_alignment.rb', line 14 def sdiff @sdiff end |
#similarity ⇒ Object (readonly)
Returns the value of attribute similarity.
17 18 19 |
# File 'lib/text_alignment/mixed_alignment.rb', line 17 def similarity @similarity end |
#str1_match_final ⇒ Object (readonly)
Returns the value of attribute str1_match_final.
18 19 20 |
# File 'lib/text_alignment/mixed_alignment.rb', line 18 def str1_match_final @str1_match_final end |
#str1_match_initial ⇒ Object (readonly)
Returns the value of attribute str1_match_initial.
18 19 20 |
# File 'lib/text_alignment/mixed_alignment.rb', line 18 def str1_match_initial @str1_match_initial end |
#str2_match_final ⇒ Object (readonly)
Returns the value of attribute str2_match_final.
18 19 20 |
# File 'lib/text_alignment/mixed_alignment.rb', line 18 def str2_match_final @str2_match_final end |
#str2_match_initial ⇒ Object (readonly)
Returns the value of attribute str2_match_initial.
18 19 20 |
# File 'lib/text_alignment/mixed_alignment.rb', line 18 def str2_match_initial @str2_match_initial end |
Instance Method Details
#transform_a_span(span) ⇒ Object
38 39 40 |
# File 'lib/text_alignment/mixed_alignment.rb', line 38 def transform_a_span(span) {begin: @position_map_begin[span[:begin]], end: @position_map_end[span[:end]]} end |
#transform_begin_position(begin_position) ⇒ Object
30 31 32 |
# File 'lib/text_alignment/mixed_alignment.rb', line 30 def transform_begin_position(begin_position) @position_map_begin[begin_position] end |
#transform_denotations!(denotations) ⇒ Object
46 47 48 |
# File 'lib/text_alignment/mixed_alignment.rb', line 46 def transform_denotations!(denotations) denotations.map!{|d| d.begin = @position_map_begin[d.begin]; d.end = @position_map_end[d.end]; d} unless denotations.nil? end |
#transform_end_position(end_position) ⇒ Object
34 35 36 |
# File 'lib/text_alignment/mixed_alignment.rb', line 34 def transform_end_position(end_position) @position_map_end[end_position] end |
#transform_hdenotations(hdenotations) ⇒ Object
50 51 52 53 |
# File 'lib/text_alignment/mixed_alignment.rb', line 50 def transform_hdenotations(hdenotations) return nil if hdenotations.nil? hdenotations.collect{|d| d.dup.merge({span:transform_a_span(d[:span])})} end |
#transform_spans(spans) ⇒ Object
42 43 44 |
# File 'lib/text_alignment/mixed_alignment.rb', line 42 def transform_spans(spans) spans.map{|span| transform_a_span(span)} end |