【问题标题】:No alternative languages in Microsoft Translator v. 3.0 Detect JSON ResponseMicrosoft Translator v. 3.0 中没有替代语言检测 JSON 响应
【发布时间】:2021-05-24 14:34:10
【问题描述】:

根据Microsoft Translator 3.0 documentation,Detect 端点的 JSON 响应正文应包含以下属性:

  • alternatives:一系列其他可能的语言。数组的每个元素都是另一个具有上述相同属性的对象:语言、分数、isTranslationSupported 和 isTransliterationSupported。

这是来自Translator Quickstart web page 的请求正文示例:

[
    { "Text": "Ich würde wirklich gern Ihr Auto um den Block fahren ein paar Mal." }
]

这是一个预期的响应正文:

[
    {
        "alternatives": [
            {
                "isTranslationSupported": true,
                "isTransliterationSupported": false,
                "language": "nl",
                "score": 0.92
            },
            {
                "isTranslationSupported": true,
                "isTransliterationSupported": false,
                "language": "sk",
                "score": 0.77
            }
        ],
        "isTranslationSupported": true,
        "isTransliterationSupported": false,
        "language": "de",
        "score": 1.0
    }
]

但是,当我在语言检测端点中使用相同的请求正文时,我只能得到一种得分为 1.0 的语言:

import requests, uuid, json

# Add your subscription key and endpoint
subscription_key = "XXXXXXXXXXXXXXXXXX"
endpoint = "https://api.cognitive.microsofttranslator.com"

# Add your location, also known as region. The default is global.
# This is required if using a Cognitive Services resource.
location = "global"

path = '/detect'
constructed_url = endpoint + path

params = {
'api-version': '3.0'
}
constructed_url = endpoint + path

headers = {
'Ocp-Apim-Subscription-Key': subscription_key,
'Ocp-Apim-Subscription-Region': location,
'Content-type': 'application/json',
'X-ClientTraceId': str(uuid.uuid4())
}

# You can pass more than one object in body.
body = [{
'text': 'Ich würde wirklich gern Ihr Auto um den Block fahren ein paar Mal.'
}]

request = requests.post(constructed_url, params=params, headers=headers, json=body)
response = request.json()

print(json.dumps(response, sort_keys=True, ensure_ascii=False, indent=4, separators=(',', ': ')))

[
    {
        "isTranslationSupported": true,
        "isTransliterationSupported": false,
        "language": "de",
        "score": 1.0
    }
]

有人知道我在这里缺少什么吗?

【问题讨论】:

  • 我相信只有在检测到时才会提供替代方案。你的句子可能是明确的一种语言。你试过其他的句子吗?
  • 是的,我尝试了 MS Docs 中的一些其他句子,其中有一些检测到的替代品以及我自己的句子,但我一直只得到一种语言,得分为 1.0。跨度>
  • Github上跟进这个问题。

标签: python azure microsoft-translator


【解决方案1】:

经过测试,我尝试使用nodejs、官方restapi、C#语言进行测试。得到相同的结果。而且我可以调试一下,发现Alternatives总是空的。

所以我确信官方文档不是最新的。

现在你得到的回应是正确的。你可以在这个页面submit feedback

【讨论】:

    猜你喜欢
    • 2019-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-29
    • 1970-01-01
    • 2015-01-29
    • 1970-01-01
    • 2011-12-30
    相关资源
    最近更新 更多