Simple Translation

With the Lilt API you can perform simple translation requests, similar to what you may know from other translation APIs. All you need to provide is a memory_id (your machine translation system in Lilt) and a source sentence.

First, you need to know the ID of the memory you want to use for translation or create a new one. Once you have identified your memory, you can make a simple translation request and it returns an array with the translated string:

$ curl "https://lilt.com/2/translate?key=MYAPIKEY&memory_id=MYMEMORY&source=Diese%20Seite%20oeffnet%20in%20einem%20neuen%20Fenster"

["This page opens in a new Window"]

The search for and translation with a memory is best done programmatically, e.g.:

# Python; Note: This is just a stub
def find_memory(name, srcLang, trgLang):
    # implement GET /memories and search for name and language pair
    ...
    return memory_id

def translate(source, srcLang, trgLang):
    memory_id = find_memory(memory_name, srcLang, trgLang)
    payload = {"key": lilt_api_key, "memory_id": memory_id, "source": source}
    res = requests.get(lilt_api_url + "/translate", params=payload, verify=False)
    return res.json()[0]

N-Best and Rich Translation Information

In some cases you may be interested in getting alternative translations. With the Lilt API you can ask for the top n scoring translations with the parameter n:

# Python; Note: This is just a stub
def translate(source, srcLang, trgLang):
    memory_id = find_memory(memory_name, srcLang, trgLang)
    payload = {"key": lilt_api_key, "memory_id": memory_id, "source": source, "n": "5"}
    res = requests.get(lilt_api_url + "/translate", params=payload, verify=False)
    for n, translation in enumerate(res.json()):
        print "translation %d: %s" % (n+1, translation)

And you will be given the top 5 translations:

translation 1: This page opens in a new Window
translation 2: This site opens in a new Window
translation 3: The page opens in a new Window
translation 4: The page opens in a new Window
translation 5: This page opens in a new window

If you are interested in more information such as alignment or provenance (TM, Lexicon, ...) you add rich=true to your request:

# Python; Note: This is just a stub
def translate(source, srcLang, trgLang):
    memory_id = find_memory(memory_name, srcLang, trgLang)
    payload = {"key": lilt_api_key, "memory_id": memory_id, "source": source, "rich": "true"}
    res = requests.get(lilt_api_url + "/translate", params=payload, verify=False)

The result is a json Translation object which looks like this example:

{
    "sourceDelimiters": ["", " ", " ", " ", " ", "", ""],
    "translation": [
    {
        "sourceContextHash": 0,
        "target": "A authentication is not required .",
        "align": "0-0 1-1 2-2 3-3 4-4 5-5",
        "provenance": "0 1 0 0 2 0",
        "score": 2.6358553e-09,
        "targetWithTags": "A authentication is not required.",
        "isTMMatch": false,
        "targetDelimiters": ["", " ", " ", " ", " ", "", ""]
    }
    ],
    "procTime": 72,
    "untokenizedSource": "Eine Legitimierung ist nicht erforderlich.",
    "tokenizedSource": "Eine Legitimierung ist nicht erforderlich ."
}

Alignment

The alignment information in align is simply a string of source-target indices separated by whitespace.

Provenance

The provenance string helps you identify where the suggested translation is coming from. A 0 indicates that the token comes from our general MT system. Non-zero values indicate that the token is from the memory. A positive value means it is a match from your custom MT or TM; a negative value means it is a match from your termbase. The value is incremented with each match.

Translation Memory Matches

TM matches are indicated by the isTMMatch flag and have a provenance string of 1's. The type of match is shown in the score value - e.g. an exact match has "score": 1 and a 75% fuzzy match has "score": 0.75. Note that we don't show fuzzy matches < 75% because most of the time the MT will be better for those.


To learn more, see the full API reference.

Still need help? Get in touch!
Last updated on 16th July 2018