class Coopy::Alignment
Attributes
comp[RW]
ha[RW]
has_addition[RW]
has_removal[RW]
hb[RW]
ia[RW]
ib[RW]
index_columns[RW]
map_a2b[RW]
map_b2a[RW]
map_count[RW]
marked_as_identical[RW]
meta[RW]
order_cache[RW]
order_cache_has_reference[RW]
reference[RW]
ta[RW]
tb[RW]
Public Class Methods
new()
click to toggle source
# File lib/lib/coopy/alignment.rb, line 7 def initialize @map_a2b = {} @map_b2a = {} @ha = @hb = 0 @map_count = 0 @reference = nil @meta = nil @comp = nil @order_cache_has_reference = false @ia = -1 @ib = -1 @marked_as_identical = false end
Public Instance Methods
a2b(a)
click to toggle source
# File lib/lib/coopy/alignment.rb, line 86 def a2b(a) @map_a2b[a] end
add_index_columns(unit)
click to toggle source
# File lib/lib/coopy/alignment.rb, line 77 def add_index_columns(unit) @index_columns = Array.new if @index_columns == nil @index_columns.push(unit) end
add_to_order(l,r,p = -2)
click to toggle source
# File lib/lib/coopy/alignment.rb, line 115 def add_to_order(l,r,p = -2) @order_cache = ::Coopy::Ordering.new if @order_cache == nil @order_cache.add(l,r,p) @order_cache_has_reference = p != -2 end
b2a(b)
click to toggle source
# File lib/lib/coopy/alignment.rb, line 90 def b2a(b) @map_b2a[b] end
count()
click to toggle source
# File lib/lib/coopy/alignment.rb, line 94 def count @map_count end
get_index_columns()
click to toggle source
# File lib/lib/coopy/alignment.rb, line 82 def get_index_columns @index_columns end
get_source()
click to toggle source
# File lib/lib/coopy/alignment.rb, line 121 def get_source @ta end
get_source_header()
click to toggle source
# File lib/lib/coopy/alignment.rb, line 129 def get_source_header @ia end
get_target()
click to toggle source
# File lib/lib/coopy/alignment.rb, line 125 def get_target @tb end
get_target_header()
click to toggle source
# File lib/lib/coopy/alignment.rb, line 133 def get_target_header @ib end
headers(ia,ib)
click to toggle source
# File lib/lib/coopy/alignment.rb, line 55 def headers(ia,ib) @ia = ia @ib = ib end
is_marked_as_identical()
click to toggle source
# File lib/lib/coopy/alignment.rb, line 300 def is_marked_as_identical @marked_as_identical end
link(a,b)
click to toggle source
# File lib/lib/coopy/alignment.rb, line 63 def link(a,b) if a != -1 @map_a2b[a] = b else @has_addition = true end if b != -1 @map_b2a[b] = a else @has_removal = true end @map_count+=1 end
mark_identical()
click to toggle source
# File lib/lib/coopy/alignment.rb, line 296 def mark_identical @marked_as_identical = true end
range(ha,hb)
click to toggle source
# File lib/lib/coopy/alignment.rb, line 45 def range(ha,hb) @ha = ha @hb = hb end
set_rowlike(flag)
click to toggle source
# File lib/lib/coopy/alignment.rb, line 60 def set_rowlike(flag) end
tables(ta,tb)
click to toggle source
# File lib/lib/coopy/alignment.rb, line 50 def tables(ta,tb) @ta = ta @tb = tb end
to_order()
click to toggle source
# File lib/lib/coopy/alignment.rb, line 104 def to_order if @order_cache != nil if @reference != nil @order_cache = nil if !@order_cache_has_reference end end @order_cache = self.to_order3 if @order_cache == nil @order_cache_has_reference = true if @reference != nil @order_cache end
to_s()
click to toggle source
# File lib/lib/coopy/alignment.rb, line 98 def to_s result = "" + "not implemented yet" + " // " + "not implemented yet" result += " (" + _hx_str(@reference.to_s) + ")" if @reference != nil result end
Protected Instance Methods
to_order3()
click to toggle source
# File lib/lib/coopy/alignment.rb, line 139 def to_order3 order = Array.new if @reference == nil _it = ::Rb::RubyIterator.new(@map_a2b.keys) while(_it.has_next) do k = _it._next unit = ::Coopy::Unit.new unit.l = k unit.r = self.a2b(k) order.push(unit) end _it2 = ::Rb::RubyIterator.new(@map_b2a.keys) while(_it2.has_next) do k1 = _it2._next if self.b2a(k1) == -1 unit1 = ::Coopy::Unit.new unit1.l = -1 unit1.r = k1 order.push(unit1) end end else _it3 = ::Rb::RubyIterator.new(@map_a2b.keys) while(_it3.has_next) do k2 = _it3._next unit2 = ::Coopy::Unit.new unit2.p = k2 unit2.l = @reference.a2b(k2) unit2.r = self.a2b(k2) order.push(unit2) end _it4 = ::Rb::RubyIterator.new(@reference.map_b2a.keys) while(_it4.has_next) do k3 = _it4._next if @reference.b2a(k3) == -1 unit3 = ::Coopy::Unit.new unit3.p = -1 unit3.l = k3 unit3.r = -1 order.push(unit3) end end _it5 = ::Rb::RubyIterator.new(@map_b2a.keys) while(_it5.has_next) do k4 = _it5._next if self.b2a(k4) == -1 unit4 = ::Coopy::Unit.new unit4.p = -1 unit4.l = -1 unit4.r = k4 order.push(unit4) end end end top = order.length remotes = Array.new locals = Array.new begin _g = 0 while(_g < top) o = _g _g+=1 if order[o].r >= 0 remotes.push(o) else locals.push(o) end end end remote_sort = lambda {|a,b| order[a].r - order[b].r } local_sort = lambda {|a1,b1| return 0 if a1 == b1 return order[a1].l - order[b1].l if order[a1].l >= 0 && order[b1].l >= 0 return 1 if order[a1].l >= 0 return -1 if order[b1].l >= 0 a1 - b1 } if @reference != nil remote_sort = lambda {|a2,b2| return 0 if a2 == b2 o1 = order[a2].r - order[b2].r if order[a2].p >= 0 && order[b2].p >= 0 o2 = order[a2].p - order[b2].p return o1 if o1 * o2 < 0 o3 = order[a2].l - order[b2].l return o3 end o1 } local_sort = lambda {|a3,b3| return 0 if a3 == b3 if order[a3].l >= 0 && order[b3].l >= 0 o11 = order[a3].l - order[b3].l if order[a3].p >= 0 && order[b3].p >= 0 o21 = order[a3].p - order[b3].p return o11 if o11 * o21 < 0 return o21 end end return 1 if order[a3].l >= 0 return -1 if order[b3].l >= 0 a3 - b3 } end remotes.sort!{|a,b| remote_sort.call(a,b)} locals.sort!{|a,b| local_sort.call(a,b)} revised_order = Array.new at_r = 0 at_l = 0 begin _g1 = 0 while(_g1 < top) o4 = _g1 _g1+=1 if at_r < remotes.length && at_l < locals.length ur = order[remotes[at_r]] ul = order[locals[at_l]] if ul.l == -1 && ul.p >= 0 && ur.p >= 0 if ur.p > ul.p revised_order.push(ul) at_l+=1 next end elsif ur.l > ul.l revised_order.push(ul) at_l+=1 next end revised_order.push(ur) at_r+=1 next end if at_r < remotes.length ur1 = order[remotes[at_r]] revised_order.push(ur1) at_r+=1 next end if at_l < locals.length ul1 = order[locals[at_l]] revised_order.push(ul1) at_l+=1 next end end end order = revised_order result = ::Coopy::Ordering.new result.set_list(order) result.ignore_parent if @reference == nil result end