Curl Batch Client
From Textserver wiki
1 #! /bin/sh
2
3 ########################################################################
4 #
5 # Example client to submit a batch request to TextServer
6 # SERVICENAME service, and wait for the job to be finished.
7 #
8 # Input must be a ZIP file containing one or more text files to analyze
9 # Output will be a ZIP file containing results for each input file in
10 # the requested format (XML, json, conll)
11 #
12 ########################################################################
13
14 # Get query parameters
15 echo -n "Input ZIP file: "
16 read FNAME
17 echo -n "Language: "
18 read LANGUAGE
19 echo -n "Output format (xml,json,conll,naf): "
20 read OUT
21 echo -n "TextServer username: "
22 read USERNAME
23 echo -n "TextServer password: "
24 read PWD
25
26 TEXTSERVER_URL="http://frodo.lsi.upc.edu:8080/TextWS/textservlet/ws"
27 # URL for the requested service
28 SERVICE="SERVICENAME";
29
30 # send request to server, retrieve job token ID
31 TEMPF=`mktemp -d`
32 curl -X POST \
33 --form "username=$USERNAME" \
34 --form "password=$PWD" \
35 --form "language=$LANGUAGE" \
36 --form "file=@$FNAME" \
37 --form "output=$OUT" \
38 --form "interactive=0" \
39 $TEXTSERVER_URL"/processQuery/"$SERVICE 2>/dev/null >tokenID.tmp
40
41 # check for TextServer error codes "[TS-XXX]" (invalid parameters, etc..)
42 if ( grep -q '\[TS\-' tokenID.tmp ); then
43 cat tokenID.tmp
44 rm tokenID.tmp
45 exit
46 fi
47
48 # extract job token id from response
49 TOKENID=`cat tokenID.tmp | sed '/<job_token_id>/ ! D; /<job_token_id>/ s#<job_token_id>\(.*\)</job_token_id>#\1#'`
50 rm tokenID.tmp
51 echo "Job submitted. Token id="$TOKENID