public virtual void LoadDefaultClassifier(bool crf) { try { if (crf) { classifier = CRFClassifier.GetDefaultClassifier(); } else { classifier = CMMClassifier.GetDefaultClassifier(); } } catch (Exception e) { string message = "Error loading default " + (crf ? "CRF" : "CMM"); string title = (crf ? "CRF" : "CMM") + " Load Error"; message += "\nMessage: " + e.Message; DisplayError(title, message); return; } RemoveTags(); BuildTagPanel(); BuildExtractButton(); }
/// <summary>Load a classifier from a file or the default.</summary> /// <remarks> /// Load a classifier from a file or the default. /// The default is specified by passing in /// <see langword="null"/> /// . /// </remarks> public virtual void LoadClassifier(string resource) { try { if (resource != null) { classifier = CRFClassifier.GetClassifier(resource); } else { // default classifier in jar classifier = CRFClassifier.GetDefaultClassifier(); } } catch (Exception e) { // we catch Throwable, since we'd also like to be able to get an OutOfMemoryError string message; if (resource != null) { message = "Error loading classpath CRF: " + resource; } else { message = "Error loading default CRF"; } log.Info(message); string title = "CRF Load Error"; string msg = e.ToString(); if (msg != null) { message += '\n' + msg; } DisplayError(title, message); return; } RemoveTags(); BuildTagPanel(); // buildExtractButton(); extractButton.SetEnabled(true); extract.SetEnabled(true); }
// end static class NERClient /// <summary>Starts this server on the specified port.</summary> /// <remarks> /// Starts this server on the specified port. The classifier used can be /// either a default one stored in the jar file from which this code is /// invoked or you can specify it as a filename or as another classifier /// resource name, which must correspond to the name of a resource in the /// /classifiers/ directory of the jar file. /// Default port is 4465. /// When run in server mode, additional properties can be specified /// on the command line and will be passed to the model loaded. /// Usage: /// <c>java edu.stanford.nlp.ie.NERServer [-loadClassifier fileOrResource|-client] -port portNumber</c> /// </remarks> /// <param name="args">Command-line arguments (described above)</param> /// <exception cref="System.Exception">If file or Java class problems with serialized classifier</exception> public static void Main(string[] args) { Properties props = StringUtils.ArgsToProperties(args); string loadFile = props.GetProperty("loadClassifier"); string loadJarFile = props.GetProperty("loadJarClassifier"); string client = props.GetProperty("client"); string portStr = props.GetProperty("port", "4465"); props.Remove("port"); // so later code doesn't complain if (portStr == null || portStr.Equals(string.Empty)) { log.Info(Usage); return; } string charset = "utf-8"; string encoding = props.GetProperty("encoding"); if (encoding != null && !string.Empty.Equals(encoding)) { charset = encoding; } int port; try { port = System.Convert.ToInt32(portStr); } catch (NumberFormatException) { log.Info("Non-numerical port"); log.Info(Usage); return; } // default output format for if no output format is specified if (props.GetProperty("outputFormat") == null) { props.SetProperty("outputFormat", "slashTags"); } if (client != null && !client.Equals(string.Empty)) { // run a test client for illustration/testing string host = props.GetProperty("host"); NERServer.NERClient.CommunicateWithNERServer(host, port, charset); } else { AbstractSequenceClassifier asc; if (!StringUtils.IsNullOrEmpty(loadFile)) { asc = CRFClassifier.GetClassifier(loadFile, props); } else { if (!StringUtils.IsNullOrEmpty(loadJarFile)) { asc = CRFClassifier.GetClassifier(loadJarFile, props); } else { asc = CRFClassifier.GetDefaultClassifier(props); } } new NERServer(port, asc, charset).Run(); } }