GATE Cloud on-line API
GATE Cloud provides an "on-line" API to process individual documents and return the annotated results in real time.
The online service accepts the data to be annotated as a standard HTTP POST request, and all configuration is done through HTTP protocol headers and URL query parameters. Text to be annotated can be supplied as plain text, HTML, or any of the other formats supported by GATE Embedded, and the annotated result is returned as JSON by default (with the "GATE XML" format of GATE Embedded and Developer as an alternative option).
The endpoint URL for a particular service can be found on the service’s description page linked from the services page; to process a document you must make a POST request to this URL. (For example, the English Named Entity Recognizer has the endpoint https://cloud-api.gate.ac.uk/process-document/annie-named-entity-recognizer). The POST body should be the data to be annotated, and the following headers are supported:
Request HTTP headers
-
Authorization- HTTP basic authentication with your API key credentials -
Content-Type- the MIME type of the request. This can be any of the MIME types supported by GATE, including:-
text/plain- plain text -
text/xmlorapplication/xml- XML (including GATE’s own standoff XML format) -
text/html- HTML -
application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.oasis.opendocument.text- PDF, Word and OpenDocument binary formats. -
text/x-json-twitterorapplication/json- Twitter format JSON, with the text as "text" and any pre-existing standoff annotations as "entities" -
text/x-json-datasift- DataSift format JSON -
application/fastinfoset- Fast Infoset representation of GATE XML format -
text/x-pubmedandtext/x-cochrane- documents in the textual formats used by Pubmed and the Cochrane library.
-
-
Accept- MIME type of the desired response type - see below for more details. -
Content-Encoding- the API can accept GZIP compressed request bodies, if the body is compressed setContent-Encoding: gzipto inform the server. -
Accept-Encoding- likewise, the API can return compressed responses, if your client can understand these setAccept-Encoding: gzip -
Expect: 100-continue- the API supports the standard HTTP "100 Continue" mechanism to allow it to verify the acceptability of the supplied authentication credentials and check the rate limits as soon as the request headers have been received. This way, if there is a problem with the request the client can be informed before sending the request body. If your client supports 100-continue you are encouraged to include theExpectheader.
Data to be processed
The text to be annotated should be supplied directly as the body of the POST request - there is no special request format or structure required. For example, a simple plain text request to the English Named Entity Recognizer would look like this:
POST /process/annie-named-entity-recognizer HTTP/1.1 Host: cloud-api.gate.ac.uk Content-Type: text/plain Content-Length: 23 Authorization: Basic ZXhhbXBsZS1rZXk6bG9uZy1nZW5lcmF0ZWQtcGFzc3dvcmQ= John lives in Sheffield.
Authentication
While some GATE Cloud API endpoints can accept requests without authentication, such requests are subject to a very low rate limit and daily quota, intended to be sufficient just for interactive manual experimentation with the "test this service" form. To obtain your full daily quota and higher rate limits, you must register for a GATE Cloud account and generate an API key. Each GATE Cloud user account can create many separate API keys, but they all share a single quota and rate limit at the user level.
GATE Cloud API keys are in two parts, the "key ID" and the "key password", both generated randomly when the key is generated.
|
Important
|
The "password" part of an API key is only displayed immediately after the key was generated. There is no way to recover the password once you have left this screen, so if you lose it you must generate a new key and delete the old one. |
When you make an API call to a GATE Cloud service you supply both parts (the key ID and the password) as a standard HTTP "Basic authentication" header. HTTP client libraries should all support this scheme by default, but if you need to construct the Authorization header yourself the procedure is:
-
concatenate the key ID (the "username") and the password with a colon character in between -
my-key-id:key-password -
encode the resulting string using base 64
-
the final
Authorizationheader consists of the wordBasic, a space, and the base 64 encoded username and password. In the above example the header corresponds to a key ID ofexample-keyand a key password oflong-generated-password
|
Note
|
You must use a generated API key ID and password, your GATE Cloud account username and password will not work with the REST API. |
URL query parameters
The following parameters can be passed to the service using the URL query string:
https://..../endpoint?key=value&key=value
-
annotations- annotation selector expressions specifying the annotation types you would like the service to return. You can find each service’s available selectors under "Annotation details" on the service’s detail page. If omitted, the service’s defaults will be used. Multiple selectors can be specified either by repeating the parameter (?annotations=:Person&annotations=:Location) or by providing a comma-separated list in a single parameter (?annotations=:Person,:Location). -
nextAnnotationId- all GATE annotations have a numeric identifier, which can be used for things like linking annotations into co-reference chains. The GATE XML and FastInfoset response formats (see below) include the annotation IDs in their responses. If the resulting annotations are to be inserted into an existing GATE document then it is important that the IDs returned by the service do not conflict with IDs of any existing annotations in the document. This parameter allows you to specify a minimum ID number (typically one greater than the highest ID in the source document), and it is guaranteed that the service will not return any new annotations with IDs less than this number.
Certain services may accept additional query parameters - this will be detailed on the relevant service’s own information page.
Response format
The GATE Cloud Online Processing service supports various different output formats configured by the Accept header in the request.
GATE JSON format
GATE JSON is a JSON format based on the format used by Twitter to represent entities in Tweet data. For each document, it consists of a JSON object with two properties, "text" containing the text of the document and "entities" containing the annotations as follows:
{
"text":"The text of the document",
"entities":{
"SampleAnnotationType1":[
{
"indices":[0,3],
"feature1":"value1",
"feature2":"value2"
}
],
"SampleAnnotationType2":[
{
"indices":[12,15],
"feature3":"value3"
}
]
}
}
The "entities" value is a map from annotation type to an array of annotation objects, belonging to this set, with the annotation’s position within the text represented as "indices":[start,end] (zero-based character offsets, start inclusive, end exclusive). The annotation’s features are represented as the other JSON properties of this object.
If the original document was Twitter JSON (i.e. it was sent with text/x-json-twitter MIME type), then the output JSON will attempt to preserve as far as possible the JSON structure of the original Tweet. If the original Tweet contained "entities" then the output annotations will be merged with those from the original JSON.
To request GATE JSON output, send an Accept header of application/gate+json (or application/json)
GATE Standoff XML
This is the XML based format used by GATE Developer and described in the GATE user guide.
To request GATE XML output, send an Accept header of application/gate+xml (or application/xml). The API can also return the same XML data using the binary Fast Infoset serialization mechanism, which can be requested with an Accept header of application/fastinfoset.
By default, the GATE XML response formats encode the full GATE document, including the text, document features, and the selected annotations. The annotation offsets are indexes into the text as given in the response, which may be different from the data sent in the request (e.g. for HTML and XML requests the markup tags will be stripped out by GATE leaving just the plain text, for binary formats like PDF there is no real concept of "character offsets" in the original data). But in cases where you are sending plain text to be annotated, you can opt to omit the text and receive only the annotations in the response, by adding a parameter to the Accept header:
Accept: application/gate+xml; includeText=no Accept: application/fastinfoset; includeText=no
In this case the returned XML will still have the <GateDocument> root element, but this will contain only the <AnnotationSet> elements from the GATE XML, without the <GateDocumentFeatures> or the <TextWithNodes>.
Error messages
When there is some problem preventing the correct execution of the request, an error response is returned with an HTTP status code specifying the type of the error as described below together with a human readable error message.
|
Status Code |
Description |
|
40x |
Problems with the user input |
|
50x |
Errors during the execution of the request |