Text replace(Text tokens, const std::vector<std::size_t> &spans, const MapNgrams &map_words){ if (tokens.size() == 0) return {}; // return empty vector for empty text unsigned int filler = UINT_MAX; // use largest limit as filler bool match = false; for (std::size_t span : spans) { // substitution starts from the longest sequences if (tokens.size() < span) continue; for (std::size_t i = 0; i < tokens.size() - (span - 1); i++){ Ngram ngram(tokens.begin() + i, tokens.begin() + i + span); auto it = map_words.find(ngram); if (it != map_words.end()) { //unsigned int id = map_words[ngram]; //if (id) { match = true; std::fill(tokens.begin() + i + 1, tokens.begin() + i + span, filler); // fill subsequent tokens tokens[i] = it->second; } } } if (match) tokens.erase(std::remove(tokens.begin(), tokens.end(), filler), tokens.end()); return tokens; }
/** * Synthesize text and return frames. **/ TTSResultPtr TTSManager::SynthesizeText(Text& text) { TTSResultPtr results = std::make_shared<TTSResult>(); for (auto it = text.begin() ; it != text.end(); ++it) { // synthesize and cat frames TTSResultPtr result = SynthesizeTextFragment(*it); results->append(*result); } return results; }
int main(void) { Text T; auto I = T.begin(); }
Config::Config(std::string const & filename) { Text text = {readFile(filename, false)}; Text::const_iterator iter = text.begin(); root.parse(iter, text.end()); }