lib/llt/tokenizer/worker.rb
# One ugly method, but we don't want to slow it down even more
One ugly method, but we don't want to slow it down even more
One ugly method but we don ' t want to slow it down even more
def align_metrical_text
        m = ArrayScanner.new(@metric_text)
        b = ArrayScanner.new(@bare_text)
        loop do
          x = m.scan
          y = b.scan
          no_meter = wo_meter(x)
          unless no_meter == y
            if @marked_enclitics.include?(y)
              clean_encl_re = /{y.dup.delete(@marker)}$/
              unless index = no_meter =~ clean_encl_re
                x = m.current
                index = wo_meter(x) =~ clean_encl_re
              end
              insert!(slice_encl!(x, index), m.pos - 1)
            elsif encl = ENCLITICS.find { |e| no_meter.end_with?(e) }
              index = no_meter =~ /{encl}$/
              insert!(slice_encl!(x, index), m.pos)
             We need to do the same if merge words were present.
             The last metric element was quam, the bare element is quamdiu.
             We append if the last metric element + the next metric element
             is the same as the bare element.
            elsif y.end_with?('.') || merged_words_present?(no_meter, y, m)
              append_from_deleted_index!(x, m.pos)
            end
          end
          break if b.eoa?
        end
      end
def align_metrical_text m = ArrayScanner . new ( @metric_text ) b = ArrayScanner . new ( @bare_text ) loop do x = m . scan y = b . scan no_meter = wo_meter ( x ) unless no_meter == y if @marked_enclitics . include? ( y ) clean_encl_re = / #{ y . dup . delete ( @marker ) } $ / unless index = no_meter =~ clean_encl_re x = m . current index = wo_meter ( x ) =~ clean_encl_re end insert! ( slice_encl! ( x , index ) , m . pos - 1 ) elsif encl = ENCLITICS . find { | e | no_meter . end_with? ( e ) } index = no_meter =~ / #{ encl } $ / insert! ( slice_encl! ( x , index ) , m . pos ) elsif y . end_with? ( '.' ) || merged_words_present? ( no_meter , y , m ) append_from_deleted_index! ( x , m . pos ) end end break if b . eoa? end end
One ugly method, but we don't want to slow it down even more
One ugly method but we don ' t want to slow it down even more
# metric element # bare element # we don't have to do anything if the dequantified metric element # was the same as the bare element - the metric_text was right # at this position # If the bare element was a marked enclitic, it must have been # shifted. We're looking for the next metric token, that has it # attached and try to find the string index where it starts to # slice it of. # Usually the metric element just scanned (y) will have it, if we # don't find it, a double shift has occured and it should sit right # at the current element of the metric ArrayScanner (m). # The enclitic (sliced of x) has to be inserted one position before. # If the dequantified metric element has an enclitic attached, the # option shifting: false must have been given. The enclitic will # follow right after in the @bare_text, we can therefore slice and # insert right in place (the next # scan round will reveal that # enclitic in metric_text == enclitic in bare_text # If the bare element has a dot attached, it must have been an # abbreviation. # The . will appear right afterwards in the metric text. We can # delete it and append it to the last scanned metric element (x) # # We need to do the same if merge words were present. # The last metric element was quam, the bare element is quamdiu. # We append if the last metric element + the next metric element # is the same as the bare element.