如何接收词对齐信息How to receive word alignment information

接收词对齐信息Receiving word alignment information

若要接收对齐信息,请使用 Translate 方法,并包含可选的 includeAlignment 参数。To receive alignment information, use the Translate method and include the optional includeAlignment parameter.

对齐信息格式Alignment information format

对齐将作为以下格式的字符串值返回给源的每个词。Alignment is returned as a string value of the following format for every word of the source. 每个词的信息由一个空格分隔,其中包括非空格分隔的语言(脚本),比如中文:The information for each word is separated by a space, including for non-space-separated languages (scripts) like Chinese:

[[SourceTextStartIndex]:[SourceTextEndIndex][TgtTextStartIndex]:[TgtTextEndIndex]] *[[SourceTextStartIndex]:[SourceTextEndIndex]�[TgtTextStartIndex]:[TgtTextEndIndex]] *

对齐字符串示例:“0:0-7:10 1:2-11:20 3:4-0:3 3:4-4:6 5:5-21:21”。Example alignment string: "0:0-7:10 1:2-11:20 3:4-0:3 3:4-4:6 5:5-21:21".

换而言之,冒号分隔开始和结束索引,连字符分隔语言,空格分隔词。In other words, the colon separates start and end index, the dash separates the languages, and space separates the words. 一个单词可能与另一种语言中的 0 个、1 个或多个单词比对,而比对的词可能是不连续的。One word may align with zero, one, or multiple words in the other language, and the aligned words may be non-contiguous. 当没有可用的对齐信息时,Alignment 元素将为空。When no alignment information is available, the Alignment element will be empty. 在这种情况下,该方法不会返回任何错误。The method returns no error in that case.

限制Restrictions

目前,仅针对语言对的子集返回对齐:Alignment is only returned for a subset of the language pairs at this point:

  • 从英语到任何其他语言;from English to any other language;
  • 从任何其他语言到英语,简体中文、繁体中文和拉脱维亚语到英语除外from any other language to English except for Chinese Simplified, Chinese Traditional, and Latvian to English
  • 从日语到韩语或从韩语到日语;如果句子是预录翻译,则不会收到对齐信息。from Japanese to Korean or from Korean to Japanese You will not receive alignment information if the sentence is a canned translation. 预录翻译示例有“This is a test”、“I love you”,以及其他高频率句子。Example of a canned translation is "This is a test", "I love you", and other high frequency sentences.

示例Example

示例 JSONExample JSON

[
  {
    "translations": [
      {
        "text": "Kann ich morgen Ihr Auto fahren?",
        "to": "de",
        "alignment": {
          "proj": "0:2-0:3 4:4-5:7 6:10-25:30 12:15-16:18 17:19-20:23 21:28-9:14 29:29-31:31"
        }
      }
    ]
  }
]