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

Function Normalize

external/sentencepiece/src/builder.cc:124–154  ·  view source on GitHub ↗

Normalizes `src` with `chars_map` and returns normalized Chars. `max_len` specifies the maximum length of the key in `chars_map`.

Source from the content-addressed store, hash-verified

122// Normalizes `src` with `chars_map` and returns normalized Chars.
123// `max_len` specifies the maximum length of the key in `chars_map`.
124Builder::Chars Normalize(const Builder::CharsMap &chars_map,
125 const Builder::Chars &src, int max_len) {
126 CHECK_GE(max_len, 1);
127 Builder::Chars normalized;
128
129 for (size_t i = 0; i < src.size();) {
130 Builder::CharsMap::const_iterator it = chars_map.end();
131 const size_t slice = std::min<size_t>(i + max_len, src.size());
132 // starts with the longest prefix.
133 Builder::Chars key(src.begin() + i, src.begin() + slice);
134 while (!key.empty()) {
135 it = chars_map.find(key);
136 if (it != chars_map.end()) {
137 break;
138 }
139 key.pop_back(); // remove the last character.
140 }
141
142 // Consumes one character when no rule is found.
143 if (it == chars_map.end()) {
144 normalized.push_back(src[i]);
145 ++i;
146 } else {
147 std::copy(it->second.begin(), it->second.end(),
148 std::back_inserter(normalized));
149 i += it->first.size();
150 }
151 }
152
153 return normalized;
154}
155
156bool IsValidNormalizerData(absl::string_view blob_data) {
157 NormalizerSpec spec;

Callers 4

RemoveRedundantMapMethod · 0.85
NormalizeMethod · 0.85
NormalizeMethod · 0.85
NormalizeMethod · 0.85

Calls 6

copyFunction · 0.85
sizeMethod · 0.45
endMethod · 0.45
beginMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected