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

Function ExpandUnnormalized

external/sentencepiece/src/builder.cc:98–119  ·  view source on GitHub ↗

Given an NFKD-normalized string, returns a set of all strings which are normalized into the same `nfkd`. `norm2orig` is the normalized to un-normalized character mapping.

Source from the content-addressed store, hash-verified

96// normalized into the same `nfkd`. `norm2orig` is the normalized to
97// un-normalized character mapping.
98std::vector<Builder::Chars> ExpandUnnormalized(
99 const Builder::Chars &nfkd,
100 const std::map<char32, std::set<char32>> &norm2orig) {
101 CHECK(!nfkd.empty());
102 std::vector<Builder::Chars> results;
103 for (const auto c : port::FindOrDie(norm2orig, nfkd[0])) {
104 results.push_back({c});
105 }
106 for (size_t i = 1; i < nfkd.size(); ++i) {
107 const auto &orig = port::FindOrDie(norm2orig, nfkd[i]);
108 std::vector<Builder::Chars> new_results;
109 for (const auto &r : results) {
110 for (const auto c : orig) {
111 new_results.emplace_back(r);
112 new_results.back().push_back(c);
113 }
114 }
115 results = std::move(new_results);
116 }
117 CHECK_EQ(nfkd.size(), results[0].size());
118 return results;
119}
120#endif // ENABLE_NFKC_COMPILE
121
122// Normalizes `src` with `chars_map` and returns normalized Chars.

Callers 1

BuildMapInternalFunction · 0.85

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected