Search in sources :

Example 1 with Curator

use of edu.illinois.cs.cogcomp.thrift.curator.Curator in project cogcomp-nlp by CogComp.

the class CuratorClient method addRecordViewFromCurator.

/**
     * Does the network call to the Curator and fetches a record that has a particular view.
     *
     * @param text The raw text (this will be used if {@link #respectTokenization} is false.
     * @param sentences The list of tokenized sentences (will be {@code null} if
     *        {@link #respectTokenization} is true.
     * @param viewName The view to get (according to the Curator lingo.)
     * @return A {@link edu.illinois.cs.cogcomp.thrift.curator.Record} with the requested view
     */
private Record addRecordViewFromCurator(String text, List<String> sentences, String viewName) throws ServiceUnavailableException, AnnotationFailedException, TException, SocketException {
    viewName = convertCuratorViewName(viewName);
    TTransport transport = new TSocket(this.curatorHost, this.curatorPort);
    logger.debug("Calling curator on host '" + curatorHost + "', port '" + curatorPort + "' for view '" + viewName + "'...");
    try {
        ((TSocket) transport).getSocket().setReuseAddress(true);
    } catch (SocketException e) {
        logger.error("Unable to setReuseAddress!", e);
        throw e;
    }
    transport = new TFramedTransport(transport);
    TProtocol protocol = new TBinaryProtocol(transport);
    transport.open();
    Curator.Client client = new Curator.Client(protocol);
    Record newRecord;
    if (respectTokenization) {
        newRecord = client.wsprovide(viewName, sentences, forceUpdate);
    } else {
        newRecord = client.provide(viewName, text, forceUpdate);
    }
    transport.close();
    return newRecord;
}
Also used : SocketException(java.net.SocketException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) Curator(edu.illinois.cs.cogcomp.thrift.curator.Curator) Record(edu.illinois.cs.cogcomp.thrift.curator.Record) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Aggregations

Curator (edu.illinois.cs.cogcomp.thrift.curator.Curator)1 Record (edu.illinois.cs.cogcomp.thrift.curator.Record)1 SocketException (java.net.SocketException)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 TFramedTransport (org.apache.thrift.transport.TFramedTransport)1 TSocket (org.apache.thrift.transport.TSocket)1 TTransport (org.apache.thrift.transport.TTransport)1