Coverage Report

Created: 2026-10-10 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/sentencepiece/src/word_model.cc
Line
Count
Source
1
// Copyright 2016 Google Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.!
14
15
#include "word_model.h"
16
17
#include "absl/strings/string_view.h"
18
19
namespace sentencepiece {
20
namespace word {
21
22
0
Model::Model(const ModelProto& model_proto) {
23
0
  model_proto_ = &model_proto;
24
0
  InitializePieces(/* use_reserved_id_map= */ true);
25
0
}
26
27
0
Model::~Model() = default;
28
29
0
EncodeResult Model::Encode(absl::string_view normalized) const {
30
0
  if (!status().ok() || normalized.empty()) {
31
0
    return {};
32
0
  }
33
34
0
  EncodeResult output;
35
0
  for (const auto& w : SplitIntoWords(normalized)) {
36
0
    output.emplace_back(w, PieceToId(w));
37
0
  }
38
39
0
  return output;
40
0
}
41
42
}  // namespace word
43
}  // namespace sentencepiece