Module: SimpleBioC::LocationAdjuster
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.choose_offset_candidate(offset, positions) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/simple_bioc/location_adjuster.rb', line 28 def choose_offset_candidate(offset, positions) min_diff = 99999 offset = offset.to_i ret = offset positions.each do |p| diff = (offset - p).abs if diff < min_diff ret = p min_diff = diff end end return ret end |
.find_all_locations(obj, text) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/simple_bioc/location_adjuster.rb', line 17 def find_all_locations(obj, text) positions = [] return positions if obj.nil? || obj.text.nil? pos = obj.text.index(text) until pos.nil? positions << (pos + obj.offset) pos = obj.text.index(text, pos + 1) end return positions end |
Instance Method Details
#adjust_annotation_offsets ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/simple_bioc/location_adjuster.rb', line 3 def adjust_annotation_offsets obj = self return if obj.nil? obj.annotations.each do |a| positions = find_all_locations(obj, a.text) a.locations.each do |l| l.original_offset = l.offset l.offset = choose_offset_candidate(l.offset, positions) end end end |