翻译器 3.0:字典示例Translator 3.0: Dictionary Examples

提供示例,说明如何在上下文中使用字典中的术语。Provides examples that show how terms in the dictionary are used in context. 此操作与字典查找一起使用。This operation is used in tandem with Dictionary lookup.

请求 URLRequest URL

POST 请求发送到:Send a POST request to:

https://api.translator.azure.cn/dictionary/examples?api-version=3.0

请求参数Request parameters

查询字符串上传递的请求参数如下:Request parameters passed on the query string are:

查询参数Query Parameter 说明Description
api-versionapi-version 必需参数。Required parameter.
客户端所请求的 API 的版本。Version of the API requested by the client. 值必须是 3.0Value must be 3.0.
fromfrom 必需参数。Required parameter.
指定输入文本的语言。Specifies the language of the input text. 源语言必须是 dictionary 范围中包含的支持的语言之一。The source language must be one of the supported languages included in the dictionary scope.
toto 必需参数。Required parameter.
指定输出文本的语言。Specifies the language of the output text. 目标语言必须是 dictionary 范围中包含的支持的语言之一。The target language must be one of the supported languages included in the dictionary scope.

请求标头包括:Request headers include:

头文件Headers 说明Description
身份验证标头Authentication header(s) 必需的请求标头。Required request header.
请参阅用于身份验证的可用选项See available options for authentication.
Content-TypeContent-Type 必需的请求标头。Required request header.
指定有效负载的内容类型。Specifies the content type of the payload. 可能的值为:application/jsonPossible values are: application/json.
Content-LengthContent-Length 必需的请求标头。Required request header.
请求正文的长度。The length of the request body.
X-ClientTraceIdX-ClientTraceId 可选。Optional.
客户端生成的 GUID,用于唯一标识请求。A client-generated GUID to uniquely identify the request. 如果在查询字符串中使用名为 ClientTraceId 的查询参数包括了跟踪 ID,则可以省略此标头。You can omit this header if you include the trace ID in the query string using a query parameter named ClientTraceId.

请求正文Request body

请求的正文是一个 JSON 数组。The body of the request is a JSON array. 每个数组元素都是一个具有以下属性的 JSON 对象:Each array element is a JSON object with the following properties:

  • Text:一个字符串,指定要查找的术语。Text: A string specifying the term to lookup. 这应该是前一个字典查找请求的反向翻译中 normalizedText 字段的值。This should be the value of a normalizedText field from the back-translations of a previous Dictionary lookup request. 它也可以是 normalizedSource 字段的值。It can also be the value of the normalizedSource field.

  • Translation:一个字符串,指定字典查找操作先前返回的翻译文本。Translation: A string specifying the translated text previously returned by the Dictionary lookup operation. 这应该是字典查找响应的 translations 列表中 normalizedTarget 字段的值。This should be the value from the normalizedTarget field in the translations list of the Dictionary lookup response. 该服务将返回特定源-目标字对的示例。The service will return examples for the specific source-target word-pair.

示例如下:An example is:

[
    {"Text":"fly", "Translation":"volar"}
]

以下限制适用:The following limitations apply:

  • 该数组最多可具有 10 个元素。The array can have at most 10 elements.
  • 数组元素的文本值不能超过 100 个字符(包括空格)。The text value of an array element cannot exceed 100 characters including spaces.

响应正文Response body

成功的响应是一个 JSON 数组,其中的每个结果对应于输入数组中的一个字符串。A successful response is a JSON array with one result for each string in the input array. 结果对象包括以下属性:A result object includes the following properties:

  • normalizedSource:一个字符串,提供源术语的规范化形式。normalizedSource: A string giving the normalized form of the source term. 通常,这应该与请求正文中匹配列表索引处的 Text 字段的值相同。Generally, this should be identical to the value of the Text field at the matching list index in the body of the request.

  • normalizedTarget:一个字符串,给出目标术语的规范化形式。normalizedTarget: A string giving the normalized form of the target term. 通常,这应该与请求正文中匹配列表索引处的 Translation 字段的值相同。Generally, this should be identical to the value of the Translation field at the matching list index in the body of the request.

  • examples:(源术语、目标术语)对的示例列表。examples: A list of examples for the (source term, target term) pair. 每个列表元素都是一个具有以下属性的对象:Each element of the list is an object with the following properties:

    • sourcePrefix:在 sourceTerm 的值之前连接以形成完整示例的字符串。sourcePrefix: The string to concatenate before the value of sourceTerm to form a complete example. 不要添加空格字符,因为它在应存在时已经存在了。Do not add a space character, since it is already there when it should be. 此值可能为空字符串。This value may be an empty string.

    • sourceTerm:一个字符串,等于被查找的实际术语。sourceTerm: A string equal to the actual term looked up. 该字符串添加了 sourcePrefixsourceSuffix 以形成完整示例。The string is added with sourcePrefix and sourceSuffix to form the complete example. 其值是分开的,因此可以在用户界面中标记,例如通过将其标为粗体。Its value is separated so it can be marked in a user interface, e.g., by bolding it.

    • sourceSuffix:在 sourceTerm 的值之后连接以形成完整示例的字符串。sourceSuffix: The string to concatenate after the value of sourceTerm to form a complete example. 不要添加空格字符,因为它在应存在时已经存在了。Do not add a space character, since it is already there when it should be. 此值可能为空字符串。This value may be an empty string.

    • targetPrefix:一个类似于 sourcePrefix 但用于目标的字符串。targetPrefix: A string similar to sourcePrefix but for the target.

    • targetTerm:一个类似于 sourceTerm 但用于目标的字符串。targetTerm: A string similar to sourceTerm but for the target.

    • targetSuffix:一个类似于 sourceSuffix 但用于目标的字符串。targetSuffix: A string similar to sourceSuffix but for the target.

    备注

    如果字典中没有示例,则响应为“200 (正常)”,但 examples 列表为空列表。If there are no examples in the dictionary, the response is 200 (OK) but the examples list is an empty list.

示例Examples

此示例演示如何查找由英语术语 fly 及其西班牙语翻译 volar 组成的配对的示例。This example shows how to lookup examples for the pair made up of the English term fly and its Spanish translation volar.

curl -X POST "https://api.translator.azure.cn/dictionary/examples?api-version=3.0&from=en&to=es" -H "Ocp-Apim-Subscription-Key: <client-secret>" -H "Ocp-Apim-Subscription-Region: your-region" -H "Content-Type: application/json" -d "[{'Text':'fly', 'Translation':'volar'}]"

响应正文是(为清楚起见已缩写):The response body (abbreviated for clarity) is:

[
    {
        "normalizedSource":"fly",
        "normalizedTarget":"volar",
        "examples":[
            {
                "sourcePrefix":"They need machines to ",
                "sourceTerm":"fly",
                "sourceSuffix":".",
                "targetPrefix":"Necesitan máquinas para ",
                "targetTerm":"volar",
                "targetSuffix":"."
            },      
            {
                "sourcePrefix":"That should really ",
                "sourceTerm":"fly",
                "sourceSuffix":".",
                "targetPrefix":"Eso realmente debe ",
                "targetTerm":"volar",
                "targetSuffix":"."
            },
            //
            // ...list abbreviated for documentation clarity
            //
        ]
    }
]