Reputation: 1
According to the Microsoft Translator 3.0 documentation the JSON Response body for the Detect endpoint should contain the following property:
Here is an example of a Request body from the Translator Quickstart web page:
[
{ "Text": "Ich würde wirklich gern Ihr Auto um den Block fahren ein paar Mal." }
]
And here is an expected Response body:
[
{
"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
}
]
However, when I use the same Request body in my language detection endpoint, I only get one language with the score of 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
}
]
Does anyone have an idea what I am missing here?
Upvotes: 0
Views: 155
Reputation: 22114
After tested, I have try to use nodejs, offical restapi, and C# language to test. Get same result. And I can debug it, find Alternatives
is always null.
So I am sure offical document is not lastest.
Now the response you got is right. You can submit feedback
in this page.
Upvotes: 0