Python

Przetwarzanie korpusu przez narzędzie wsd z pliku zip załadowanego z dysku lokalnego (zmienna in_file).
Zmiana toru polega na zmienia wartości zmiennej task, zgodnie z potokiem dla danego narzędzia (np. lpmn="any2txt|wcrft2|liner2")
Prosimy o podanie adresu e-mail w zmiennej user.

import json
import urllib2
import glob
import os
import time

user="mojadresemail" 
task="any2txt|wcrft2|wsd" 
url="http://ws.clarin-pl.eu/nlprest2/base" 

def upload(file):
        with open (file, "rb") as myfile:
            doc=myfile.read()
        return urllib2.urlopen(urllib2.Request(url+'/upload/',doc,{'Content-Type': 'binary/octet-stream'})).read();

def process(data):
        doc=json.dumps(data)
        taskid = urllib2.urlopen(urllib2.Request(url+'/startTask/',doc,{'Content-Type': 'application/json'})).read();
        time.sleep(0.2);
        resp = urllib2.urlopen(urllib2.Request(url+'/getStatus/'+taskid));
        data=json.load(resp)
        while data["status"] == "QUEUE" or data["status"] == "PROCESSING" :
            time.sleep(0.5);
            resp = urllib2.urlopen(urllib2.Request(url+'/getStatus/'+taskid));
            data=json.load(resp)
        if data["status"]=="ERROR":
            print("Error "+data["value"]);
            return None;
        return data["value"]

def main():
    in_file = 'paczka.zip'
    out_file= 'out.zip'
    global_time = time.time()
    fileid=upload(in_file)
    lpmn='filezip('+fileid+')|'+task+'|dir|makezip'
    data={'lpmn':lpmn,'user':user}
    data=process(data)
    if data!=None:
        data=data[0]["fileID"];
        content = urllib2.urlopen(urllib2.Request(url+'/download'+data)).read();
        with open (out_file, "w") as outfile:
                outfile.write(content)
    print("GLOBAL %s seconds ---" % (time.time() - global_time))

main();