Text-Translation-API-V3-Python icon indicating copy to clipboard operation
Text-Translation-API-V3-Python copied to clipboard

Problem with alignment information.

Open skharenko-DS opened this issue 4 years ago • 0 comments

I have next code:

def translate(
        from_lang: str,
        to_lang: str,
        texts: List[str],
        include_alignment: bool = True
    ) -> List[JSONType]:
        constructed_url = "https://api.cognitive.microsofttranslator.com/translate"
        params = {
            "api-version": "3.0",
            "from": from_lang,
            "to": to_lang,
            "includeAlignment": include_alignment,
            "includeSentenceLength": True,
        }
        headers = {
            "Ocp-Apim-Subscription-Key": "*******",
            "Ocp-Apim-Subscription-Region": "GLOBAL",
            "Content-type": "application/json",
            "X-ClientTraceId": str(uuid.uuid4()),
        }
        body = [{"text": text} for text in texts]
        request = requests.post(
            constructed_url, params=params, headers=headers, json=body
        )
        resp = request.json()
        return resp
result = translate("de", "en", ["Artikelnummer des Kunden"])

and i have a result {'translations': [{'text': "Customer's item number", 'to': 'en', 'alignment': {'proj': '0:12-11:14 0:12-16:21 14:16-0:9'}, 'sentLen': {'srcSentLen': [24], 'transSentLen': [22]}}]} so if we look at result: Original: Artikelnummer des Kunden Translation: Customer's item number we see that we have no alignment for the original word "Kunden".

skharenko-DS avatar Dec 06 '21 11:12 skharenko-DS