Model

For ease of use, the ELG internal API has been represented as a prebuilt python model using pydantic.
For technical documentation, see below.
For more information on the API itself, see:

https://european-language-grid.readthedocs.io/en/stable/all/A3_API/LTInternalAPI.html

base

Request

class elg.model.base.Request.Request(*, type: str = None, params: dict = None)

Representation of a service invocation request. Intended to be abstract, subclasses should be initiated with their specific type

Subclasses

type: str

(required in subclass) the type of request

params: dict

(optional) vendor specific params, up to service implementor to decide how to interpret these

Response

class elg.model.base.ResponseObject.ResponseObject(*, type: str, warnings: List[elg.model.base.StatusMessage.StatusMessage] = None)

Representation of a successful completion response. Abstract, subclasses must instantiate this with their own type

Subclasses

type: str

(required in subclass) the type of response

warnings: List[elg.model.base.StatusMessage.StatusMessage]

(optional) messages describing any warnings on response

Annotation

class elg.model.base.Annotation.Annotation(*, start: numbers.Number, end: numbers.Number, sourceStart: numbers.Number = None, sourceEnd: numbers.Number = None, features: dict = None)

Representation of a single annotation with respect to either one or two streams of data.

start(Number, required)
Type

annotation start location (in response)

end(Number, required)
Type

annotation end location (in response)

source_start(Number, required in cases)
Type

annotation start location (in source)

source_end(Number, required in cases)
Type

annotation end location (in source)

features(dict, optional)
Type

arbitrary json metadata about content

Failure

class elg.model.base.Failure.Failure(*, errors: List[elg.model.base.StatusMessage.StatusMessage])

Details of a failed task

errors: List[elg.model.base.StatusMessage.StatusMessage]

(required) List of status messages describing the failure

Progress

class elg.model.base.Progress.Progress(*, percent: float, message: elg.model.base.StatusMessage.StatusMessage = None)

Details of an in progress task Some LT services can take a long time to process each request - likely useful to keep caller updated

percent: float

(required) completion percentage

message: elg.model.base.StatusMessage.StatusMessage

(optional) message describing progress report

StatusMessages

class elg.model.base.StatusMessage.StatusMessage(*, code: str, params: List[str], text: str, detail: Dict = None)

Represents a single status message, in a form amenable to internationalisation.

Each message contains a code, which can be looked up in a list to find the actual text in any of the available languages. The text can contain numbered placeholders of the form <code>{0}</code>, which are filled in with values specified in the “params” property. The “text” property provides a single fallback text to be used if the specified code cannot be found in the lookup table.

code: str

(required) status code to be found in lookup table

params: List[str]

(required) values to fill in message placeholder

text: str

(required) fallback text to be used if specified code cannot be found in lookup table

detail: Dict

(optional) arbitrary further details that don’t need translation (e.g. stacktrace)

StandardMessages

class elg.model.base.StandardMessages.StandardMessages

This class provides easy access to the standard set of ELG status messages that are provided by default by the platform and should be fully translated in the ELG user interface. If you use codes other than these standard ones in your services then you should also try to contribute translations of your messages into as many languages as possible for the benefit of other ELG users.

Implementation note: This class is auto-generated from elg-messages.properties - to add new message codes you should edit the property files, then run /utils/generate_standard_messages.py. Do not edit this class directly.

classmethod generate_elg_request_invalid(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.request.invalid

classmethod generate_elg_request_missing(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.request.missing

classmethod generate_elg_request_type_unsupported(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.request.type.unsupported

classmethod generate_elg_request_property_unsupported(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.request.property.unsupported

classmethod generate_elg_request_too_large(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.request.too.large

classmethod generate_elg_request_text_mimetype_unsupported(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.request.text.mimeType.unsupported

classmethod generate_elg_request_audio_format_unsupported(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.request.audio.format.unsupported

classmethod generate_elg_request_audio_samplerate_unsupported(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.request.audio.sampleRate.unsupported

classmethod generate_elg_request_structuredtext_property_unsupported(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.request.structuredText.property.unsupported

classmethod generate_elg_response_property_unsupported(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.response.property.unsupported

classmethod generate_elg_response_texts_property_unsupported(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.response.texts.property.unsupported

classmethod generate_elg_response_classification_property_unsupported(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.response.classification.property.unsupported

classmethod generate_elg_response_invalid(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.response.invalid

classmethod generate_elg_response_type_unsupported(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.response.type.unsupported

classmethod generate_elg_service_not_found(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.service.not.found

classmethod generate_elg_service_internalerror(params=[], detail={}, lang='en')

Generate StatusMessage for code: elg.service.internalError


request

TextRequest

class elg.model.request.TextRequest.TextRequest(*, type: str = 'text', params: dict = None, content: str, mimeType: str = 'text/plain', features: Dict = None, annotations: Dict[str, List[elg.model.base.Annotation.Annotation]] = None)

Request representing a single piece of text, optionally with associated markup Subclass of elg.model.base.Request.Request

For example a list of paragraphs or sentences, or a corpus of documents, each divided into sentences. While this could be represented as standoff annotations in a plain “text” request, the structured format is more suitable for certain types of tools.

type: str

(required) the type of request must be “text”

content: str

(optional) text content

mimeType: str

(optional) mime type of request, default “text/plain”

features: Dict

(optional) arbitrary json metadata about content

annotations: Dict[str, List[elg.model.base.Annotation.Annotation]]

(optional) optional annotations on request

Structured Text Request

class elg.model.request.StructuredTextRequest.Text(*, content: str = None, mimeType: str = 'text/plain', features: dict = None, annotations: Dict[str, List[elg.model.base.Annotation.Annotation]] = None, texts: List = None)

A single node in a structured text request.

Each text can have an associated score (for example a confidence value for multiple alternative translations or transcriptions) and optional annotations, which can be linked to both the result text in this object and to the original source material from the corresponding request.

content: str

(optional) text content

mime_type: str

(optional) mime type of request, default “text/plain”

features: dict

(optional) arbitrary json metadata about content

annotations: Dict[str, List[elg.model.base.Annotation.Annotation]]

(optional) optional annotations on request

texts: List

(optional) recursive, same structure (should be List[Text] but postponed annotations introduced post python 3.6)

classmethod either_content_or_text(values)

ensures only either the “content” or the “text” fields are present

class elg.model.request.StructuredTextRequest.StructuredTextRequest(*, type: str = 'structuredText', params: dict = None, texts: List[elg.model.request.StructuredTextRequest.Text])

Request representing text with some structure. Subclass of elg.model.base.Request.Request

For example a list of paragraphs or sentences, or a corpus of documents, each divided into sentences. Whilst this could be represented as standoff annotations in a plain “text” request, the structured format is more suitable for certain types of tools.

type: str

(required) the type of request must be “structuredText”

texts: List[elg.model.request.StructuredTextRequest.Text]

(required) the actual text object with the text content

Audio Request

class elg.model.request.AudioRequest.AudioRequest(*, type: str = 'audio', params: dict = None, content: bytes = None, generator: Any = None, format: str = 'LINEAR16', sampleRate: int = None, features: Dict = None, annotations: Dict[str, List[elg.model.base.Annotation.Annotation]] = None)

Request representing a piece of audio - the actual audio data will be sent as a separate request. Subclass of elg.model.base.Request.Request

type: str

(required) the type of request must be “audio”

content: bytes

(optional) audio itself, if not being sent as separate stream

generator: Any

(optional) generator that provide the audio itself

format: str

(required) format of audio request. must be either “LINEAR16” (default) or “MP3”

sample_rate: int

(optional) sample rate of audio

features: Dict

(optional) arbitrary json metadata about content

annotations: Dict[str, List[elg.model.base.Annotation.Annotation]]

(optional) optional annotations on request

classmethod format_must_be_specific(v)

(validator) ensures the format of the audio request is either “LINEAR16” or “MP3”

classmethod generator_must_be_iterable(v)

(validator) ensures the iterator field of the audio request is either None or an Iterable

classmethod from_file(filename, format: Optional[str] = None, sample_rate: Optional[int] = None, features: Optional[Dict] = None, annotations: Optional[Dict[str, List[elg.model.base.Annotation.Annotation]]] = None, streaming: bool = False, blocksize: int = 1024)

allows you to generate audio request from file


response

AnnotationsResponse

class elg.model.response.AnnotationsResponse.AnnotationsResponse(*, type: str = 'annotations', warnings: List[elg.model.base.StatusMessage.StatusMessage] = None, features: dict = None, annotations: Dict[str, List[elg.model.base.Annotation.Annotation]] = None)

Response representing standoff annotations over a single stream of data (e.g. information extraction results). Subclass of elg.model.base.ResponseObject.ResponseObject

type: str

(required) the type of response must be “annotations”

features: dict

(optional) arbitrary json metadata about content

annotations: Dict[str, List[elg.model.base.Annotation.Annotation]]

(optional) optional annotations on request

classmethod either_features_or_annotations(values)

(validator) ensures either the “features” or “annotations” fields are present

AudioResponse

class elg.model.response.AudioResponse.AudioResponse(*, type: str = 'audio', warnings: List[elg.model.base.StatusMessage.StatusMessage] = None, content: str, format: str, features: dict = None, annotations: Dict[str, List[elg.model.base.Annotation.Annotation]] = None)

Response representing audio data with optional standoff annotations (e.g. text-to-speech results) Subclass of elg.model.base.ResponseObject.ResponseObject

type: str

(required) type of response

content: str

(required) base64 encoded audio for short audio snippets

format: str

either “LINEAR16” or “MP3”

Type

(required) specifies audio format used

features: dict

(required) arbitrary json metadata about content

annotations: Dict[str, List[elg.model.base.Annotation.Annotation]]

(required) optional annotations on response

classmethod format_must_be_specific(v)

(validator) ensures the format of the audio response is either “LINEAR16” or “MP3”

to_file(filename)

(validator) writes audio response to file

Classification Response

class elg.model.response.ClassificationResponse.ClassesResponse(*, class: str = None, score: float = None)

Classification object: classification and score (optional likelihood of classification) Subclass of elg.model.base.ResponseObject.ResponseObject

class_field: str

(required) labelled class

score: float

(optional) confidence score in class

class elg.model.response.ClassificationResponse.ClassificationResponse(*, type: str = 'classification', warnings: List[elg.model.base.StatusMessage.StatusMessage] = None, classes: List[elg.model.response.ClassificationResponse.ClassesResponse] = None)

Response encapsulating one or more classifications of the whole input message, optionally with confidence scores attached.

type: str

(required) type of response

classes: List[elg.model.response.ClassificationResponse.ClassesResponse]

(optional) list of classifications, zero or more allowed

TextsResponse

class elg.model.response.TextsResponse.TextsResponseObject(*, role: str = None, content: str = None, texts: List = None, score: int = None, features: dict = None, annotations: Dict[str, List[elg.model.base.Annotation.Annotation]] = None)

Object representing a structured piece of text. Recursive.

role: str

(optional) the role of this node in the response

content: str

(optional) string of translated/transcribed text

texts: List

(optional) list of same structures, recursive

score: int

(optional) confidence of response

features: dict

(optional) arbitrary JSON metadata about content

annotations: Dict[str, List[elg.model.base.Annotation.Annotation]]

(optional) optional annotations on request

classmethod either_content_or_text(values)

(validator) ensures either the “content” or “text” fields are present

class elg.model.response.TextsResponse.TextsResponse(*, type: str = 'texts', warnings: List[elg.model.base.StatusMessage.StatusMessage] = None, texts: List[elg.model.response.TextsResponse.TextsResponseObject])

Response consisting of a set of one or more new texts, each with optional annotations attached to it. Subclass of elg.model.base.ResponseObject.ResponseObject

For example a set of possible translations produced by a translation tool or possible transcriptions produced by a speech-to-text recogniser.

type: str

(optional) type of response, must be “texts”

texts: List[elg.model.response.TextsResponse.TextsResponseObject]

(optional) list of objects representing a structured text response