Example #1
0
  public static void send(Socket sa, String data) throws IOException {
    byte[] content = data.getBytes();

    byte[] length = String.format("%04d", content.length).getBytes();

    byte[] buf = new byte[1024];
    int reslen;
    int rc;
    //  Bounce the message back.
    InputStream in = sa.getInputStream();
    OutputStream out = sa.getOutputStream();

    out.write(length);
    out.write(content);

    System.out.println("sent " + data.length() + " " + data);
    int to_read = 4; // 4 + greeting_size
    int read = 0;
    while (to_read > 0) {
      rc = in.read(buf, read, to_read);
      read += rc;
      to_read -= rc;
      System.out.println("read " + rc + " total_read " + read + " to_read " + to_read);
    }
    System.out.println(String.format("%02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3]));
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    reslen = Integer.valueOf(new String(buf, 0, 4));

    in.read(buf, 0, reslen);
    System.out.println("recv " + reslen + " " + new String(buf, 0, reslen));
  }
  /** Test method for {@link com.mychaelstyle.nlp.Juman#parse(java.lang.String)}. */
  @Test
  public void testParse() {
    Juman juman = new Juman();
    try {
      ObjectNode result =
          juman.parse("本システムは,計算機による日本語の解析の研究を目指す多くの研究者に共通に使える形態素解析ツールを提供するために開発されました。");
      assertThat(result, notNullValue());
      System.out.println(result.toString());

      result = juman.parse("JUMANは、日本語の形態素解析システムです。");
      System.out.println(result.toString());

      result = juman.parse("人手で整備した辞書に基づいており、ChaSenの元となったシステム。");
      System.out.println(result.toString());

    } catch (IOException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }