Making API requests one by one can be inefficient when you have a large number of documents you wish to analyze. We’ve added a batch processing feature that makes it easier to process a large number of documents all at once using the Text Analysis API.
Steps to use this feature are as follows:
Step 1. Package all your documents in one file
Start by putting all your documents (or URLs) in one big text file – one document/URL per line. Example:
Time is an illusion. Lunchtime doubly so.
For a moment, nothing happened. Then, after a second or so, nothing continued to happen.
Step 2. Make a batch request and obtain job identifier
/batch endpoint creates a new analysis job that will be processed eventually. There are a couple of parameters that you need to provide to
||Data to be analyzed †
||Comma separated list of Text Analysis API endpoints
||classify, concepts, entities, extract, language, sentiment, summarize, hashtags
||Type of entities in your file, whether they are URLs, or texts
||The format you wish to download the batch results in (Default: json)
† Maximum file size is
All other parameters sent to
/batch will be passed down to the endpoints you’ve specified in
endpoints in an as-is manner. For example:
curl -v -H "X-Mashape-Authorization: YOUR_MASHAPE_KEY"
-F "mode=tweet" https://aylien-text.p.mashape.com/batch
Will upload contents of file
/home/amir/42, and indicates that each line is a
text (not a
URL), desired operation is sentiment analysis, and you wish to download the results in
A successful request will lead to a
201 Created, with a
Location header which indicates the URI you can poll to get the status of your submitted job. For you convenience URI is also in the body of response.
Step 3. Poll the job status information until it is finished
You can call the URI obtained from last step to see the status of your job. Your job can be in either one of these states:
completed. If your job is
completed you’ll receive
303 See Other with a
Location header indicating where you can download your results. Its also in the body of your response. Example:
curl -H "X-Mashape-Authorization: YOUR_MASHAPE_KEY"
-H "Accept: text/xml"
Sample response (
Step 4. Download your results
location value obtained from the last step, is a pre-signed S3 Object URL which you can easily download using
wget. Please note that results will be kept only for
7 days after the job is finished and will be deleted afterwards. If you fail to obtain the results during this period, you must re-submit your job.