MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / GetPrecompiledCharsMap

Method GetPrecompiledCharsMap

external/sentencepiece/src/builder.cc:287–323  ·  view source on GitHub ↗

static

Source from the content-addressed store, hash-verified

285
286// static
287util::Status Builder::GetPrecompiledCharsMap(absl::string_view name,
288 std::string *output) {
289 CHECK_OR_RETURN(output);
290
291 if (name == "identity") {
292 output->clear();
293 return util::OkStatus();
294 }
295
296 std::string result;
297
298#ifndef DISABLE_EMBEDDED_DATA
299 for (size_t i = 0; i < kNormalizationRules_size; ++i) {
300 const auto *blob = &kNormalizationRules_blob[i];
301 if (blob->name == name) {
302 output->assign(blob->data, blob->size);
303 CHECK_OR_RETURN(IsValidNormalizerData(*output));
304 return util::OkStatus();
305 }
306 }
307#else // DISABLE_EMBEDDED_DATA
308 {
309 const std::string filename =
310 absl::StrCat(util::JoinPath(GetDataDir(), name), ".bin");
311 auto input = filesystem::NewReadableFile(filename, true /* is binary */);
312 if (input->status().ok()) {
313 input->ReadAll(output);
314 CHECK_OR_RETURN(IsValidNormalizerData(*output));
315 return util::OkStatus();
316 }
317 }
318#endif // DISABLE_EMBEDDED_DATA
319
320 return util::StatusBuilder(util::StatusCode::kNotFound, GTL_LOC)
321 << "No precompiled charsmap is found: " << name << " in "
322 << GetDataDir();
323}
324
325#ifdef ENABLE_NFKC_COMPILE
326namespace {

Callers

nothing calls this directly

Calls 11

OkStatusFunction · 0.85
IsValidNormalizerDataFunction · 0.85
JoinPathFunction · 0.85
GetDataDirFunction · 0.85
NewReadableFileFunction · 0.85
StatusBuilderClass · 0.85
assignMethod · 0.80
okMethod · 0.80
ReadAllMethod · 0.80
clearMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected