Program Listing for File response.h

Return to documentation for file (src/translator/response.h)

#ifndef SRC_BERGAMOT_RESPONSE_H_
#define SRC_BERGAMOT_RESPONSE_H_

#include <cassert>
#include <string>
#include <vector>

#include "annotation.h"
#include "data/alignment.h"
#include "data/types.h"
#include "definitions.h"
#include "translator/beam_search.h"

namespace marian {
namespace bergamot {

typedef std::vector<std::vector<float>> Alignment;

struct Response {
  struct SentenceQualityScore {
    std::vector<float> wordScores;
    std::vector<SubwordRange> wordRanges;
    float sentenceScore = 0.0;
  };

  const size_t size() const { return source.numSentences(); }

  AnnotatedText source;

  AnnotatedText target;

  std::vector<SentenceQualityScore> qualityScores;

  std::vector<std::vector<std::vector<float>>> alignments;

  ByteRange getSourceSentenceAsByteRange(size_t sentenceIdx) const { return source.sentenceAsByteRange(sentenceIdx); }

  ByteRange getTargetSentenceAsByteRange(size_t sentenceIdx) const { return target.sentenceAsByteRange(sentenceIdx); }

  const std::string &getOriginalText() const { return source.text; }

  const std::string &getTranslatedText() const { return target.text; }
};

std::vector<Alignment> remapAlignments(const Response &first, const Response &second);

std::vector<ByteRange> getWordByteRanges(Response const &response, size_t sentenceIdx);

}  // namespace bergamot
}  // namespace marian

#endif  // SRC_BERGAMOT_RESPONSE_H_