Skip to content

Signbank API examples

Wessel Stoop edited this page May 17, 2024 · 1 revision

Creating a Gloss Entry via the api_create_gloss Endpoint

This guide demonstrates how to create a gloss entry in the Signbank database using the /dictionary/api_create_gloss/<datasetid> endpoint.

Data Preparation

First, you need to set up your data dictionary. This dictionary should include all the necessary information about the gloss you wish to add:

data = {
    'Dataset': 'NGT',
    'Lemma ID Gloss (Dutch)': 'glos',
    'Lemma ID Gloss (English)': 'glos_engels',
    'Annotation ID Gloss (Dutch)': 'glos',
    'Annotation ID Gloss (English)': 'glos_engels',
    'Senses (Dutch)': 'senses',
    'Senses (English)': 'senses_engels',
    'Handedness': 'Handeness',
    'Strong Hand': 'strongHand',
    'Weak Hand': 'weakHand',
    'Handshape Change': 'handshapeChange',
    'Relation Between Articulators': 'RelationArticulators',
    'Location': 'handLocation',
    'Relative Orientation: Movement': 'relativeOrienationMovement',
    'Relative Orientation: Location': 'relativeOrienationLocation',
    'Orientation Change': 'orientationChange',
    'Contact Type': 'contactType',
    'Movement Shape': 'MovementShape',
    'Movement Direction': 'MovementDirection',
    'Virtual Object': 'virtualObject',
    'Phonology Other': 'phonologyOther',
    'Mouth Gesture': 'mouthGesture',
    'Mouthing': 'mouthing',
    'Phonetic Variation': 'phoneticVariation',
    'Repeated Movement': 'repeatedMovement',
    'Alternating Movement': 'alternatingMovement',
    'Semantic Field': 'semanticField',
}

Sending the POST Request

With the data dictionary prepared, send a POST request to the specified endpoint. You'll need to include your session and CSRF token for authentication:

url = "https://signbank.cls.ru.nl/dictionary/api_create_gloss/5/"
cookies = {
    'cookie_notification': 'functional',
    'cookies_consent': '-1',
    'sessionid': 'your_session_id',
    'csrftoken': 'your_csrf_token',
}

response = requests.post(url, cookies=cookies, data=data)

Ajax call setup in javascript

Here is the setup of an AJAX call on signbank-dev in javascript, where you fill in the dataset ID, your token, and the data:

     $.ajax({
        url : 'https://signbank-dev.cls.ru.nl//dictionary/api_create_gloss/<datasetid>/',
        type: 'POST',
        headers: { 'Authorization': 'Bearer <SignbankToken>',
                   'Content-Type': 'application/json',
                   'Accept-Language': 'en' },
        data: JSON.stringify(data),
        dataType: "json",
        success : show_creation_results
     });

Here is an example of the JSON data, observe that the Senses are per language, as a list of lists:

var data = {
    "Dataset":"tstMH",
    "Lemma ID Gloss (Dutch)":"ROOD-STAAN",
    "Annotation ID Gloss (Dutch)":"ROOD-STAAN",
    "Senses (Dutch)":"[['debit bij bankrekening']]",
    "Lemma ID Gloss (English)":"IN-THE-RED",
    "Annotation ID Gloss (English)":"IN-THE-RED",
    "Senses (English)":"[['negative bank balance']]"
};

Here is the above AJAX call for the test dataset using your token:

     $.ajax({
        url : 'https://signbank-dev.cls.ru.nl//dictionary/api_create_gloss/1/',
        type: 'POST',
        headers: { 'Authorization': 'Bearer XXXXXXXXXXXXXXXX',
                   'Content-Type': 'application/json',
                   'Accept-Language': 'en' },
        data: JSON.stringify(data),
        dataType: "json",
        success : show_creation_results
     });

Here is the JSON output:

{"glossid":"47962","errors":[],"createstatus":"Success"}

If we try to create the same gloss again, we get error messages:

{"errors":[
     "Lemma translation for Nederlands already exists.",
     "Lemma translation for Engels already exists.",
     "This annotation already exists for language Nederlands: ROOD-STAAN",
     "This annotation already exists for language Engels: IN-THE-RED"
    ],
 "createstatus":"Failed",
 "glossid":""}

Here is an example of the JSON data for creating another gloss, this time in Dutch:

var data = {
    "Dataset":"tstMH",
    "Lemma-ID-Glos (Nederlands)":"ROZEMARIJN",
    "Annotatie-ID-Glos (Nederlands)":"ROZEMARIJN",
    "Lemma-ID-Glos (Engels)":"ROSEMARY",
    "Annotatie-ID-Glos (Engels)":"ROSEMARY"
};

Here is the above AJAX call for the test dataset using your token, setting the language to Dutch:

     $.ajax({
        url : 'https://signbank-dev.cls.ru.nl//dictionary/api_create_gloss/1/',
        type: 'POST',
        headers: { 'Authorization': 'Bearer XXXXXXXXXXXXXXXX',
                   'Content-Type': 'application/json',
                   'Accept-Language': 'nl' },
        data: JSON.stringify(data),
        dataType: "json",
        success : show_creation_results
     });

Here is the JSON output:

{"glossid":"47963","errors":[],"createstatus":"Success"}

Once again, if we try to create the same gloss again, now we get error messages in Dutch:

{"errors":[
     "Lemma-ID-Glos (Nederlands) bestaat al.",
     "Lemma-ID-Glos (Engels) bestaat al.",
     "Annotatie-ID-Glos (Nederlands) bestaat al: ROZEMARIJN",
     "Annotatie-ID-Glos (Engels) bestaat al: ROSEMARY"
    ],
 "createstatus":"Failed",
 "glossid":""}