Using the API

Top  Previous  Next

The CTexT NCHLT Web Services can be accessed via a RESTful API.

 

API Calls

 

Step 1:

 

Generate a valid session ID using the following POST call:

 

http://{server:port}/CTexTWebAPI/services/setuser

 

When making this API call, the request header must contain the following property:

 

Key: Authorization

Value: Basic aGVsZW4ncyBzdGludCBhcyBsZWFndWUgbWFuYWdlcg==

 

The response will be a JSON object containing a string array labeled token.

 

Example of reponse:

 

{"token":["4E3EDB46C33517701FC18F540FEBD5EE"]}

 

Step 2:

 

The API can then be called using a GET call and should always consist of the following information:

 

http://{server:port}/CTexTWebAPI/services?core={technology}&lang={code}&text={text}

 

Where the following is required:

 

the server (and optional port number) on which the service is being hosted
the technology, either by number or shortened name
the two letter language code, as defined in Technologies and Supported Languages
the URL escaped Unicode text that should be processed by the technology
The token obtained using step 1 must be included in the request header as the authToken property

 

Examples:

 

http://127.0.0.1:8080/CTexTWebAPI/services?core=pos&lang=AF&text=teks+om+te+toets

http://v-ctx-lnx7.nwu.ac.za:8080/CTexTWebAPI/services?core=2&lang=EN&text=helen's+stint+as+league+manager

 

API parameter values:

 

Language (lang)

Code

Afrikaans

af

English

en

isiNdebele

nr

isiXhosa

xh

isiZulu

zu

Sesotho sa Leboa

nso

Sesotho

st

Setswana

tn

SiSwati

ss

Tshivenḓa

ve

Xitsonga

ts

 

Technology (core)

Param name

Param code

Tokeniser

token

1

Sentence Separator

sentence

2

Phrase Chunker

pc

3

Part of Speech tagger

pos

4

Named Entity Recognition

ner

5

Language Identifier

lid

6

Optical Character Recognition

ocr

7

 

Using files with the API

 

Files can also be uploaded for processing (as long as they are smaller than 20Mb), through the curl tools or a multi-part form data, such as using curl. A valid authToken must be included in the request header.

An example of this would be:

 

curl -F "file=@C:\Users\user\Desktop\Temp\Test.jpg" --form language=af --form core=ocr -X POST http://127.0.0.1:8080/CTexTWebAPI/services/file