Przykład wywołanie narzędzia fextor dla krótkich tekstów w Javie

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.json.JSONObject;

public class demo2 {

    static private final String user = "adrsemailowy@prosze.zmienic";
    static private final String nlprestURL = "http://ws.clarin-pl.eu/nlprest2/base/";

    public static String nlpResultDownload(String id) throws IOException {
        URL url = new URL(nlprestURL + "download" + id);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setRequestMethod("GET");
        if (conn.getResponseCode() == 200) {
            InputStream is = conn.getInputStream();
            ByteArrayOutputStream result = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int length;
            while ((length = is.read(buffer)) != -1) {
                result.write(buffer, 0, length);
            }   
            return result.toString("UTF-8");

        } else {
            throw new IOException("Error downloading file");
        }
    }

    private static String getRes(Response res) throws IOException {
        if (res.getStatus() != 200) {
            throw new IOException("Error in nlprest processing");
        }
        return res.readEntity(String.class);
    }

    public static String nlpProcess(String lpmn, String text) throws IOException, InterruptedException {
        JSONObject request = new JSONObject();
        Client client = ClientBuilder.newClient();
        request.put("text", text);
        request.put("lpmn", lpmn);
        request.put("user", user);
        String taskid = client.target(nlprestURL + "startTask").request().
                post(Entity.entity(request.toString(), MediaType.APPLICATION_JSON)).readEntity(String.class);

        String status = "";
        JSONObject jsonres = new JSONObject();
        while (!status.equals("DONE")) {
            String res = getRes(client.target(nlprestURL + "getStatus/" + taskid).request().get());

            jsonres = new JSONObject(res);

            status = jsonres.getString("status");
            if (status.equals("ERROR")) {
                throw new IOException("Error in processing");
            }
            if (status.equals("PROCESSING")) {
                System.out.println(String.format("%.2f", jsonres.getDouble("value") * 100) + "%");
            }
            if (status.equals("DONE")) {
                System.out.println("100%");
            }
            Thread.sleep(500);
        }
        return jsonres.getJSONArray("value").getJSONObject(0).getString("fileID");
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        String text="Ala ma kota. Andrzej poszedł do szpitala i długo nie wracał.";
        String lpmn = "any2txt|wcrft2({\"morfeusz2\":false})|fextor({\"features\": \"mm_stat\"})";
        String id = nlpProcess(lpmn, text);
        String json=nlpResultDownload(id);
        System.out.println(json);
        System.out.println("Done");
    }
}