Python Microsoft Translator v中没有其他语言。3.0检测JSON响应

Python Microsoft Translator v中没有其他语言。3.0检测JSON响应,python,azure,microsoft-translator,Python,Azure,Microsoft Translator,根据定义,检测端点的JSON响应体应包含以下属性: 备选方案:一系列其他可能的语言。数组的每个元素都是另一个具有上面列出的相同属性的对象:language、score、isTranslationSupported和isTranslationSupported 以下是来自的请求主体的示例: 这是一个预期的响应机构: [ { "alternatives": [ { "isTranslat

根据定义,检测端点的JSON响应体应包含以下属性:

  • 备选方案:一系列其他可能的语言。数组的每个元素都是另一个具有上面列出的相同属性的对象:language、score、isTranslationSupported和isTranslationSupported
以下是来自的请求主体的示例:

这是一个预期的响应机构:

[
    {
        "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
    }
]

有人知道我缺少什么吗?

经过测试,我尝试使用nodejs、officerestapi和C语言进行测试。得到同样的结果。我可以调试它,发现
备选方案
总是空的

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

现在你得到的回答是正确的。您可以在此页面中提交反馈


我认为只有在检测到的情况下才提供替代方案。你的句子可能是明确的一种语言。你试过其他句子吗?是的,我试过MS Docs中的其他句子,除了我自己的句子外,还有一些检测到的备选句子,但我只得到了一种语言的分数为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
    }
]