Javascript Annotator

The Javascript Annotator allows annotations to be generated by executing a program or expression written in JavaScript.

The layer manager has two modes of operation:

Label Mapping
new annotation labels are generated from a small JavaScript expression operating on the label from a given source layer.
Full Script
a full script is given the whole annotation graph, which it can traverse, process, and add annotations to.

Label Mapping

The label of each annotation from the source layer directly generates the label of one annotation on the destination layer.

For each distinct label on the source layer, the specified expression is executed on the label, and the result of the expression is saved on the destination layer.

Some illustrative examples:

  • length - saves the length of the source label on the destination layer,
    e.g. test4
  • toUpperCase() - converts all lowercase letters to uppercase,
    e.g. testTEST
  • replace(/[aeiou]/g,"") - removes all vowels,
    e.g. testtst
  • replace(/[aeiou]/g,"V").replace(/[^aeiou]/g,"C") - replaces all vowels with V and all non-vowels with C,
    e.g. testCVCC

Full Script

The script is executed for each transcript, with a variable called transcript which stores the transcript's Annotation Graph. transcript can be traversed to inspect annotations, and can have annotations added to it (on this layer only), which will be saved back to LaBB-CAT's annotation store when the script completes.

The transcript variable is populated with annotations from the layers that are ticked on the panel to the right of the script. Only those layers will be available to the script, no other layers are loaded.

The script might look something like the following, which tags each word with its length:

// for each turn in the transcript
for each (turn in transcript.all("turns")) {
  if (annotator.cancelling) break; // cancelled by the user
  // for each word
  for each (word in turn.all("transcript")) {
    // tag the word with it's length
    word.createTag("length", "length: " + word.label.length());
    log("Tagged word: " + word.label);
  } // next word
} // next turn