mark_best_candidate

in lib/twitter_cldr/segmentation/brahmic_break_engine.rb [160:196]


      def mark_best_candidate(cursor, end_pos, state)
        
        found_best = false

        
        if cursor.position < end_pos
          loop do
            words_matched = 1

            if state.words[state.words_found + 1].candidates(cursor, dictionary, end_pos) > 0
              if words_matched < 2
                
                state.words[state.words_found].mark_current
                words_matched = 2
              end

              
              break if cursor.position >= end_pos

              
              loop do
                
                if state.words[state.words_found + 2].candidates(cursor, dictionary, end_pos) > 0
                  state.words[state.words_found].mark_current
                  found_best = true
                  break
                end

                break unless state.words[state.words_found + 1].back_up(cursor)
              end
            end

            break unless state.words[state.words_found].back_up(cursor) && !found_best
          end
        end
      end