| 26 | Model::~Model() {} |
| 27 | |
| 28 | EncodeResult Model::Encode(absl::string_view normalized) const { |
| 29 | if (!status().ok() || normalized.empty()) { |
| 30 | return {}; |
| 31 | } |
| 32 | |
| 33 | // Splits the input into character sequence |
| 34 | EncodeResult output; |
| 35 | while (!normalized.empty()) { |
| 36 | const int mblen = matcher_->PrefixMatch(normalized); |
| 37 | absl::string_view w(normalized.data(), mblen); |
| 38 | output.emplace_back(w, PieceToId(w)); |
| 39 | normalized.remove_prefix(mblen); |
| 40 | } |
| 41 | |
| 42 | return output; |
| 43 | } |
| 44 | |
| 45 | } // namespace character |
| 46 | } // namespace sentencepiece |