/// <summary>Client that runs data through a StanfordCoreNLPServer either just for testing or for command-line text processing.</summary> /// <remarks> /// Client that runs data through a StanfordCoreNLPServer either just for testing or for command-line text processing. /// This runs the pipeline you specify on the /// text in the file(s) that you specify (with -file or -filelist) and sends some results to stdout. /// The current code in this main method assumes that each line of the file /// is to be processed separately as a single sentence. /// A site must be specified with a protocol like "https:" in front of it. /// Example usage:<br /> /// java -mx6g edu.stanford.nlp.pipeline.StanfordCoreNLP -props properties -backends site1:port1,site2:port2 <br /> /// or just -host https://foo.bar.com [-port 9000] /// </remarks> /// <param name="args">List of required properties</param> /// <exception cref="System.IO.IOException">If IO problem</exception> /// <exception cref="System.TypeLoadException">If class loading problem</exception> public static void Main(string[] args) { // // process the arguments // // extract all the properties from the command line // if cmd line is empty, set the properties to null. The processor will search for the properties file in the classpath // if (args.length < 2) { // log.info("Usage: " + StanfordCoreNLPClient.class.getSimpleName() + " -host <hostname> -port <port> ..."); // System.exit(1); // } Properties props = StringUtils.ArgsToProperties(args); bool hasH = props.Contains("h"); bool hasHelp = props.Contains("help"); if (hasH || hasHelp) { string helpValue = hasH ? props.GetProperty("h") : props.GetProperty("help"); StanfordCoreNLP.PrintHelp(System.Console.Error, helpValue); return; } // Create the backends IList <StanfordCoreNLPClient.Backend> backends = new List <StanfordCoreNLPClient.Backend>(); string defaultBack = "http://localhost:9000"; string backStr = props.GetProperty("backends"); if (backStr == null) { string host = props.GetProperty("host"); string port = props.GetProperty("port"); if (host != null) { if (port != null) { defaultBack = host + ':' + port; } else { defaultBack = host; } } } foreach (string spec in props.GetProperty("backends", defaultBack).Split(",")) { Matcher matcher = UrlPattern.Matcher(spec.Trim()); if (matcher.Matches()) { string protocol = matcher.Group(1); if (protocol == null) { protocol = "http"; } string host = matcher.Group(2); int port = 80; string portStr = matcher.Group(3); if (portStr != null) { port = System.Convert.ToInt32(portStr); } backends.Add(new StanfordCoreNLPClient.Backend(protocol, host, port)); } } log.Info("Using backends: " + backends); // Run the pipeline StanfordCoreNLPClient client = new StanfordCoreNLPClient(props, backends); client.Run(); try { client.Shutdown(); } catch (Exception) { } }