MCPcopy Create free account
hub / github.com/catboost/catboost / PrepareMultitoken

Function PrepareMultitoken

library/cpp/tokenizer/multitokenutil.cpp:150–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148}
149
150NLP_TYPE PrepareMultitoken(TTokenStructure& subtokens, wchar16* buffer, size_t buflen, const wchar16* entry, size_t& len) {
151 size_t srcpos = subtokens[0].EndPos(); // the beginning of source delimiters and tokens
152 if (srcpos > buflen - 1) {
153 srcpos = buflen - 1;
154 subtokens[0].Len = srcpos - subtokens[0].Pos;
155 }
156 size_t destpos = srcpos;
157 std::char_traits<wchar16>::copy(buffer, entry, srcpos);
158
159 TCharSpan* const firsttok = &subtokens[0];
160 TCharSpan* const lasttok = firsttok + subtokens.size();
161 TCharSpan* desttok = firsttok;
162
163 // lengths of tokens are not changed, tokens can be moved only to remove delimiters
164
165 for (const TCharSpan* srctok = firsttok + 1; srctok != lasttok; ++srctok) {
166 // Check available space; truncate input if not sufficient
167 if (srctok->EndPos() >= buflen) {
168 break;
169 }
170
171 if (srctok->EndPos() + srctok->SuffixLen >= buflen) {
172 ProcessHyphenation(buffer, entry, desttok, srctok, destpos, srcpos);
173
174 if (desttok->EndPos() + desttok->SuffixLen >= buflen) {
175 Y_ASSERT(desttok->EndPos() < buflen);
176 desttok->SuffixLen = 0; // cut off the suffix
177
178 CopyTokenText(buffer, entry, srctok->Len, destpos, srcpos); // copy with no suffix
179 } else
180 CopyTokenText(buffer, entry, (srctok->Len + srctok->SuffixLen), destpos, srcpos); // copy the token with suffix
181
182 break;
183 }
184
185 ProcessHyphenation(buffer, entry, desttok, srctok, destpos, srcpos);
186 CopyTokenText(buffer, entry, (srctok->Len + srctok->SuffixLen), destpos, srcpos); // copy the token with suffix
187 }
188
189 Y_ASSERT(srcpos >= destpos);
190
191 // Multitoken->Leng
192 len = destpos;
193 subtokens.resize(desttok - firsttok + 1);
194 subtokens.back().TokenDelim = TOKDELIM_NULL;
195 return DetectNLPType(subtokens); // after PrepareMultitoken nlpType can be chagned
196}
197
198size_t AdjustSubtokens(TTokenStructure& subtokens, size_t maxLen) {
199 Y_ASSERT(!subtokens.empty());

Callers 1

MakeMultitokenEntryMethod · 0.85

Calls 8

ProcessHyphenationFunction · 0.85
CopyTokenTextFunction · 0.85
DetectNLPTypeFunction · 0.85
EndPosMethod · 0.80
copyFunction · 0.50
sizeMethod · 0.45
resizeMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected