package org.linkgrammar;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
/**
*
* A client of the {@link LGService} when it is run in server mode. The main
* method to call is {@link parse} which produces a {@link ParseResult}. At
* a minimum, the hostname
and port
properties
* must be set beforehand. Configuration settings of the remote parser itself
* are specified with the config
property.
*
*
*
* This client is persistent in its attempts to perform a parse. By default
* it will keep trying to connect to a server indefinitely (unless the host is
* unknown). To change that,
* set the connectRetryCount
property. Also, if call to the server
* fails for whatever reason, it will retry at least once. The increase the number
* of retries, set the parseRetryCount
property.
*
*
* @author Borislav Iordanov
*
*/
public class LGRemoteClient
{
private LGConfig config = new LGConfig();
private String parserVersion;
private String hostname = "localhost";
private int port = 9000;
private int parseRetryCount = 2;
private int connectRetryCount = Integer.MAX_VALUE;
private long connectRetryWait = 1000l;
@SuppressWarnings({"unchecked"})
private ParseResult jsonToParseResult(String json)
{
JSONReader reader = new JSONReader();
Map top = (Map)reader.read(json);
ParseResult result = new ParseResult();
result.setParserVersion((String)top.get("version"));
result.setNumSkippedWords(((Number)top.get("numSkippedWords")).intValue());
for (Map x : (List