| 195 | !is_cjk_punctuation_delimiter(spans[word_end].text)) { |
| 196 | ++word_end; |
| 197 | } |
| 198 | const auto last = spans[word_end - 1].text; |
| 199 | words.push_back({ |
| 200 | word_start, |
| 201 | word_end, |
| 202 | spans[word_start].start, |
| 203 | spans[word_end - 1].end, |
| 204 | is_sentence_break(last), |
| 205 | is_clause_break(last), |
| 206 | }); |
| 207 | span_pos = word_end; |
| 208 | } |
| 209 | return words; |
| 210 | } |
| 211 | |
| 212 | // A run of hanzi, kana or Hangul without punctuation has no word boundary, so it used to come back as one chunk over |
| 213 | // the budget, which a model with a per-chunk length limit cuts short. Cut such words into about equal pieces, as |
| 214 | // Japanese mode does, but only between two CJK letters, so tags, numbers and Latin text inside the word stay whole. A |
| 215 | // word without such a boundary, like a long Latin word, stays whole. |
| 216 | std::vector<WordRange> fit_cjk_runs( |
| 217 | const std::vector<Utf8Span> & spans, |
| 218 | const std::vector<WordRange> & words, |
| 219 | int64_t codepoint_budget) { |
| 220 | const auto budget = static_cast<size_t>(codepoint_budget); |
| 221 | std::vector<WordRange> out; |
| 222 | out.reserve(words.size()); |
no test coverage detected