Module: Gliner::PositionIteration

Included in:
Classifier, SpanExtractor
Defined in:
lib/gliner/position_iteration.rb

Instance Method Summary collapse

Instance Method Details

#each_position_width(seq_len, prepared, max_width) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gliner/position_iteration.rb', line 5

def each_position_width(seq_len, prepared, max_width)
  return enum_for(:each_position_width, seq_len, prepared, max_width) unless block_given?

  (0...seq_len).each do |pos|
    start_word = prepared.pos_to_word_index[pos]
    next unless start_word

    (0...max_width).each do |width|
      end_word = start_word + width
      next if end_word >= prepared.text_len

      yield pos, start_word, width
    end
  end
end