Class: TextAlignment::MixedAlignment

Inherits:
Object
  • Object
show all
Defined in:
lib/text_alignment/mixed_alignment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_str1, _str2, _mappings = nil) ⇒ MixedAlignment

Returns a new instance of MixedAlignment.

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
# File 'lib/text_alignment/mixed_alignment.rb', line 20

def initialize(_str1, _str2, _mappings = nil)
	raise ArgumentError, "nil string" if _str1.nil? || _str2.nil?

	str1, str2, mappings = TextAlignment::long_to_one_mapping_preprocessing(_str1, _str2, _mappings)

	_compute_mixed_alignment(str1, str2, mappings)
end

Instance Attribute Details

#common_elementsObject (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_elementsObject (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_beginObject (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_endObject (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

#sdiffObject (readonly)

Returns the value of attribute sdiff.



14
15
16
# File 'lib/text_alignment/mixed_alignment.rb', line 14

def sdiff
  @sdiff
end

#similarityObject (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_finalObject (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_initialObject (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_finalObject (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_initialObject (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



36
37
38
# File 'lib/text_alignment/mixed_alignment.rb', line 36

def transform_a_span(span)
	{begin: @position_map_begin[span[:begin]], end: @position_map_end[span[:end]]}
end

#transform_begin_position(begin_position) ⇒ Object



28
29
30
# File 'lib/text_alignment/mixed_alignment.rb', line 28

def transform_begin_position(begin_position)
	@position_map_begin[begin_position]
end

#transform_denotations!(denotations) ⇒ Object



44
45
46
# File 'lib/text_alignment/mixed_alignment.rb', line 44

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



32
33
34
# File 'lib/text_alignment/mixed_alignment.rb', line 32

def transform_end_position(end_position)
	@position_map_end[end_position]
end

#transform_hdenotations(hdenotations) ⇒ Object



48
49
50
51
# File 'lib/text_alignment/mixed_alignment.rb', line 48

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



40
41
42
# File 'lib/text_alignment/mixed_alignment.rb', line 40

def transform_spans(spans)
	spans.map{|span| transform_a_span(span)}
end