示例#1
0
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;
}
示例#2
0
/**
* 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;
}
示例#3
0
文件: main.cpp 项目: CCJY/coliru
int main(void) {
    Text T;

    auto I = T.begin();
}
示例#4
0
文件: config.cpp 项目: fiddleplum/kit
Config::Config(std::string const & filename)
{
	Text text = {readFile(filename, false)};
	Text::const_iterator iter = text.begin();
	root.parse(iter, text.end());
}