std::string DecoderFactory::unpackReplabels()

in recipes/streaming_convnets/inference/inference/decoder/Decoder.cpp [189:225]


std::string DecoderFactory::unpackReplabels(const std::string& input) const {
  std::string output = "";
  std::string prevTkn = "";

  const int len = input.length();
  for (int i = 0; i < len;) {
    const unsigned char c = (unsigned char)(input[i]);
    int curTknBytes = nUTF8Bytes(c);
    if (curTknBytes == -1 || i + curTknBytes > len) {
      throw std::runtime_error(
          "unpackReplabels() failed due to invalid UTF-8 : " + input);
    }

    int rep = -1;
    const std::string curToken(
        input.begin() + i, input.begin() + i + curTknBytes);
    if (isInt(curToken)) {
      rep = std::stoi(curToken);
    }

    // Replabel
    if (rep > 0 && rep <= repetitionLabel_) {
      for (int j = 0; j < rep; j++) {
        output += prevTkn;
      }
      prevTkn = "";
    }
    // Normal case
    else {
      output += curToken;
      prevTkn = curToken;
    }
    i += curTknBytes;
  }

  return output;
}