Teneo Developers

Annotations

This section provides basic information about how to work with annotations. For more information, please see the Teneo Engine Scripting API.

Creating an annotation

The following Teneo Engine Scripting API method creates a new annotation instance for the given data:

groovy

1Annotation createAnnotation(String _sName,
2			int _iSentenceIndex,
3			Set<Integer> _zWordIndices,
4			Map<String,Object> _mVariables)
5

The annotation parameters are:

  • _sName – the name of the annotation, which must follow the same naming conventions as Language Objects. Thus, names must be written in uppercase and cannot contain whitespace or other reserved characters (spaces, tabs, newlines…)
  • _iSentenceIndex – the index in the user input's List<SentenceI> to which this annotation belongs (the first sentence has index 0)
  • _zWordIndices – the indices in the SentenceI's List<WordData> to which this annotation belongs (the first word has index 0)
  • _mVariables – an arbitrary collection of key/value pairs; pass null if no variables are required.

The method throws the following exceptions:

  • NullPointerException – If the name is null or the word indices map is null
  • IllegalArgumentException – If the name is empty, the sentence index is negative or not less than the number of sentences, the word indices map contains a negative index or an index not less than the word count of the selected sentence, or the variables map contains a null key.

Note: passing a value for the parameter _mVariables is optional. The annotation can also be created by _.createAnnotation(_sName, _iSentenceIndex, _zWordIndices, null).

Annotations basic information is covered in the following subsections. Further information is available in the Engine Scripting API documentation.

Annotation Class Method

These are the available methods for class Annotation:

Modifier and TypeMethod and Description
booleanequals(Object _other)
Compares this annotation to the specified object.
StringgetName()
Returns the name of this annotation.
intgetSentenceIndex()
Returns the index in the List<Sentence
Map<String, Object>getVariable()
Returns the variables (and their value) associated with this annotation.
Set<Integer>getWordIndices()
Returns the indices into the List<WordData> contained in a sentence
inthashCode()
StringtoString()

Annotations Interface Methods

Instances of type Annotation are managed in a container that implements the interface Annotations that provides the following methods; they are accessible using the syntax .getInputAnnotations (), e.g. _.getInputAnnotations().add(annotation).

Modifier and TypeMethod and Description
voidadd(Annotation_annotation)
Adds the given annotation to the annotations data.
voidclear()
Removes all annotations.
booleanContains(Annotation_annotation)
Returns true if an annotation equal to the given annotation is present in the annotations data.
Set<Annotation>getAll()
Returns all annotations.
Set<Annotation>getByName(String _sName)
Returns all annotations with the given name, for all sentences.
Set<Annotation>getByName(String _sName, int _iSentenceIndex)
Returns all annotations with the given name, in the specified sentence.
Set<Annotation>getBySentenceIndex(int _iSentenceIndex)
Returns all annotations with the given sentences index.
Set<Annotation>getByVariable(String _sVariableName)
Returns all annotations with a variable of the given name, for all sentences.
Set<Annotation>getByVariable(String _sVariableName, int _iSentenceIndex)
Returns all annotations with a variable of the given name, in the specified sentence.
Set<Annotation>getByWordIndex(int _iWordIndex)
Returns all annotations containing the given word index, for all sentences.
Set<Annotation>getByWordIndex(int _iWordIndex, int _iSentenceIndex)
Returns all annotations containing the given word index, in the specified sentence.
Set<String>getNames()
Returns the names of all annotations, for all sentences.
Set<String>getNames(Int _iSentenceIndex)
Returns the name of all annotations, in the specified sentence.
voidRemove(Annotation_annotation)
Removes the annotation from the annotations data which is equal to the given annotation, if it’s present.