Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Unified API Example

abhi-agg edited this page Mar 30, 2021 · 5 revisions

Goal

translate API input/output examples:

std::vector<TranslationResult> translate(std::vector<std::string> &&texts, TranslationRequest request)

Cases

For brevity and simplicity, all the tokens are represented as strings but they will be represented as ByteRange structure and

Response = std::vector<TranslationResult>

Case 1: texts contains only 1 entry (i.e. texts.size() = 1) and texts[0] contains 2 sentences

texts   : ["abc def. ghi jkl."]         // Single entry in texts that contains 2 sentences

request : {
              qualityScoreGranularity : QualityScoreGranularity::WORD
              includeSentenceMapping  : true;
              includeAlignment        : true;
          }

Response: [
              {// TranslationResult corresponding to `texts[0]`

                  originalText       : "abc def. ghi jkl."

                  translatedText     : "ABC DEF. GHI JKL."

                  qualityScores      : [
                                           {// Quality Score for 1st translated sentence ("ABC DEF.")
                                              translatedSentenceTokens  : ["AB", "C ", "DE", "F", "."]
                                              translatedSentenceScores  : [0.xx, 0.xx, 0.xx, 0.x, 0.x]
                                           },

                                           {// Quality Score for 2nd translated sentence ("GHI JKL.")
                                              translatedSentenceTokens  : ["GHI", "JKL", "."]
                                              translatedSentenceScores  : [0.xxx, 0.xxx, 0.x]
                                           }
                                       ]

                  sentenceMappings  : [  
                                         {"abc def.", "ABC DEF."},
                                         {"ghi jkl.", "GHI JKL."}
                                      ]

                  alignments        : [
                                          {// Alignment b/w 1st original Sentence and corresponding translated sentence
                                              originalSentenceViews           : [ "abc", " de", "f", "."]
                                              translatedSentenceViews         : [ "AB", "C ", "DE", "F", "."]
                                              alignmentsOriginalToTranslated  : [
                                                                                  [0.xx, 0.xx, 0.xx, 0.x, 0.x],
                                                                                  [0.xx, 0.xx, 0.xx, 0.x, 0.x],
                                                                                  [0.xx, 0.xx, 0.xx, 0.x, 0.x],
                                                                                  [0.xx, 0.xx, 0.xx, 0.x, 0.x],
                                                                                ]
                                          },
                                          {// Alignment b/w 2nd original Sentence and corresponding translated sentence
                                              originalSentenceViews           : [ "ghi", "jkl", "."]
                                              translatedSentenceViews         : [ "GHI", "JKL", "."]
                                              alignmentsOriginalToTranslated  : [
                                                                                  [0.xx, 0.xx, 0.xx],
                                                                                  [0.xx, 0.xx, 0.xx],
                                                                                  [0.xx, 0.xx, 0.xx],
                                                                                ]
                                           }    
                                      ]
              }
          ]
                         
Clone this wiki locally