============================ Call through ProtocolBuffers ============================ This topic describes how to call the RaSC service, prepared in :doc:`rasc_basic`, through ProtocolBuffers. The client will be implemented in Java. Complete :doc:`rasc_basic` to start the RaSC service in advance. First, download and unzip the RaSC client sample package. .. code-block:: bash $ wget https://alaginrc.nict.go.jp/rasc/resources/rasc-client-1.0.0.zip $ unzip rasc-client-1.0.0.zip The package contains the following files: .. code-block:: text rasc-client-1.0.0/ + lib/ + ... ((Required libraries) + ClientProtcolBuffers/ + build.xml + src/ (Source files) + ClientProtcolBuffers.java ClientProtocolBuffers.java is a sample code for ProtocolBuffers clients implemented in Java. *ClientProtcolBuffers/src/ClientProtcolBuffers.java* .. code-block:: java :linenos: import java.net.MalformedURLException; import java.net.URL; import jp.go.nict.langrid.client.impl.protobuf.PbClientFactory; import jp.go.nict.wisdom.wrapper.api.TextAnalysisService; public class ClientProtcolBuffers { /** * ProtocolBuffers client sample. * * @param args args[0] String passed to the user program */ public static void main(String[] args) { try { if(args.length <= 0){ System.out.println("Specify in the argument the string to be passed to the user program."); return; } TextAnalysisService s = new PbClientFactory().create(TextAnalysisService.class, new URL("http://localhost:8080/___WAR_NAME___/pbServices/___SERVICE_NAME___")); System.out.println(args[0]); System.out.println("--- result ---"); System.out.println(s.analyze(args[0])); } catch (MalformedURLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } Use ``PbClientFactory#create()`` to create ``TextAnalysisService``. The client calls ``TextAnalysisService#analyze()``. Specify ``http://localhost:8080/___WAR_NAME___/pbServices/___SERVICE_NAME___`` as an endpoint (address to call a service). These must be set according to ``___WAR_NAME___`` and ``___SERVICE_NAME___`` set in :doc:`rasc_basic`. Call analyze() to call the user program. It is assumed that args[0] is given to the user program as the string to be processed. cf. *jp.go.nict.wisdom.wrapper.api.TextAnalysisService* Interface class .. code-block:: java :linenos: :emphasize-lines: 4 package jp.go.nict.wisdom.wrapper.api; public interface TextAnalysisService { String analyze(String text) throws Exception; String[] analyzeArray(String[] text) throws Exception; } ``build.xml`` for the ProtocolBuffers client is as follows. *ClientProtcolBuffers/build.xml* .. code-block:: xml :linenos: ``ant`` creates the ``build`` folder, compiles the Java source, and packages class files as ``build/clientProtocolBuffers.jar`` and ``clientProtocolBuffers.jar``. You can do this by the following commands: .. code-block:: bash $ cd rasc-client-1.0.0/ClientProtcolBuffers/ $ ant Run the ProtocolBuffers client as follows. You can specify a character string to be passed to the user program in the argument. .. code-block:: bash $ cd build/ $ java -jar clientProtocolBuffers.jar "He runs the company." He runs the company. --- result --- ROOT ROOT ROOT ROOT -1 ROOT ROOT runs run VBZ VB 1 runs run VBZ VB 1 verb_arg12 ARG1 He he PRP PRP 0 runs run VBZ VB 1 verb_arg12 ARG2 company company NN NN 3 the the DT DT 2 det_arg1 ARG1 company company NN NN 3