根据Microsoft Translator 3.0 documentation,检测端点的JSON响应体应包含以下属性:
下面是来自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
}
]
有人知道我在这里遗漏了什么吗
经过测试,我尝试使用nodejs、officerestapi和C语言进行测试。得到同样的结果。我可以调试它,发现
Alternatives
总是空的所以我确信官方文件不是最新的
现在你得到的回答是正确的。您可以在本页中
submit feedback
相关问题 更多 >
编程相关推荐