你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Translator - Dictionary Examples

提供示例,说明如何在上下文中使用字典中的术语。 此操作与 Dictionary lookup结合使用。

POST {Endpoint}/Dictionary/Examples?api-version=3.0&from={from}&to={to}

URI 参数

名称 必需 类型 说明
Endpoint
path True

string

支持的认知服务终结点

api-version
query True

string

客户端所请求的 API 的版本。 值必须为 3.0

from
query True

string

指定输入文本的语言。 源语言必须是 dictionary 范围中包含的支持的语言之一。

to
query True

string

指定输出文本的语言。 目标语言必须是 dictionary 范围中包含的支持的语言之一。

请求头

名称 必需 类型 说明
X-ClientTraceId

string

客户端生成的 GUID,用于唯一标识请求。 请注意,如果使用名为 ClientTraceId 的查询参数在查询字符串中包含跟踪 ID,则可以省略此标头。

请求正文

名称 类型 说明
text

DictionaryExampleTextInput[]

请求正文

请求的正文是一个 JSON 数组。 每个数组元素都是一个具有以下属性的 JSON 对象:

  • Text- 指定要查找的术语的字符串。 这应该是前一个字典查找请求的反向翻译中 normalizedText 字段的值。 它也可以是 normalizedSource 字段的值。
  • Translation- 一个字符串,指定以前由字典查找操作返回的已翻译文本。 这应该是字典查找响应的 translations 列表中 normalizedTarget 字段的值。 该服务将返回特定源-目标字对的示例。

以下限制适用:

  • 该数组最多可具有 10 个元素。
  • 数组元素的文本值不能超过 100 个字符(包括空格)。

响应正文

成功的响应是一个 JSON 数组,其中的每个结果对应于输入数组中的一个字符串。 结果对象包括以下属性:

  • normalizedSource- 一个字符串,提供源术语的规范化形式。 通常,这应该与请求正文中匹配列表索引处的 Text 字段的值相同。
  • normalizedTarget- 一个字符串,提供目标字词的规范化形式。 通常,这应该与请求正文中匹配列表索引处的 Translation 字段的值相同。
  • examples- (源术语、目标术语) 对的示例列表。 每个列表元素都是一个具有以下属性的对象:
    • sourcePrefix- 要在 的值之前连接以形成完整示例的 sourceTerm 字符串。 不要添加空格字符,因为它在应存在时已经存在了。 此值可能为空字符串。
    • sourceTerm- 与查找的实际字词相等的字符串。 该字符串添加了 sourcePrefixsourceSuffix 以形成完整示例。 其值是分开的,因此可以在用户界面中标记,例如通过将其标为粗体。
    • sourceSuffix- 要在 的值 sourceTerm 后面连接以形成完整示例的字符串。 不要添加空格字符,因为它在应存在时已经存在了。 此值可能为空字符串。
    • targetPrefix- 一个类似于 sourcePrefix 的字符串,但目标为 。
    • targetTerm- 一个类似于 sourceTerm 的字符串,但目标为 。
    • targetSuffix- 一个类似于 sourceSuffix 的字符串,但目标为 。

响应标头

X-RequestId - 服务生成的用于标识请求的值。 它用于故障排除目的。 注意 - 如果字典中没有示例,则响应为 200 (正常) 但 examples 列表为空列表。

响应

名称 类型 说明
200 OK

DictionaryExampleResult[]

成功

Other Status Codes

ErrorMessage

错误响应。

安全性

Ocp-Apim-Subscription-Key

Type: apiKey
In: header

Ocp-Apim-Subscription-Key

Type: apiKey
In: header

Ocp-Apim-Subscription-Region

Type: apiKey
In: header

示例

DictionaryExample success example

Sample Request

POST https://api.cognitive.microsofttranslator.com/Dictionary/Examples?api-version=3.0&from=en&to=es

[
  {
    "text": "bug",
    "translation": "bicho"
  }
]

Sample Response

[
  {
    "normalizedSource": "bug",
    "normalizedTarget": "bicho",
    "examples": [
      {
        "sourcePrefix": "You feel like a ",
        "sourceTerm": "bug",
        "sourceSuffix": ".",
        "targetPrefix": "Te sientes como un ",
        "targetTerm": "bicho",
        "targetSuffix": "."
      },
      {
        "sourcePrefix": "Not to mention your friend the ",
        "sourceTerm": "bug",
        "sourceSuffix": ".",
        "targetPrefix": "Aparte de tu amigo, el ",
        "targetTerm": "bicho",
        "targetSuffix": "."
      },
      {
        "sourcePrefix": "Get on the magic ",
        "sourceTerm": "bug",
        "sourceSuffix": ".",
        "targetPrefix": "Suban al ",
        "targetTerm": "bicho",
        "targetSuffix": " mágico."
      },
      {
        "sourcePrefix": "Because this ",
        "sourceTerm": "bug",
        "sourceSuffix": " is not an insect.",
        "targetPrefix": "Porque este ",
        "targetTerm": "bicho",
        "targetSuffix": " no es un insecto."
      },
      {
        "sourcePrefix": "I still taste that ",
        "sourceTerm": "bug",
        "sourceSuffix": ".",
        "targetPrefix": "Aún tengo el sabor de ese ",
        "targetTerm": "bicho",
        "targetSuffix": "."
      }
    ]
  }
]

定义

名称 说明
DictionaryExampleResult

成功的字典示例请求示例

DictionaryExampleTextInput

字典示例请求所需的文本

Error
ErrorMessage
Examples

DictionaryExampleResult

成功的字典示例请求示例

名称 类型 说明
examples

Examples[]

normalizedSource

string

normalizedTarget

string

DictionaryExampleTextInput

字典示例请求所需的文本

名称 类型 说明
text

string

translation

string

Error

名称 类型 说明
code

string

message

string

ErrorMessage

名称 类型 说明
error

Error

Examples

名称 类型 说明
sourcePrefix

string

sourceSuffix

string

sourceTerm

string

targetPrefix

string

targetSuffix

string

targetTerm

string