Skip to content

Problem with alignment information. #23

Open

Description

@skharenko-DS

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".

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions