Пример #1
0
 /// <summary>Creates a new tagger server on the specified port.</summary>
 /// <param name="port">the port this NERServer listens on.</param>
 /// <param name="tagger">The classifier which will do the tagging</param>
 /// <param name="charset">The character set for encoding Strings over the socket stream, e.g., "utf-8"</param>
 /// <exception cref="System.IO.IOException">If there is a problem creating a ServerSocket</exception>
 public MaxentTaggerServer(int port, MaxentTagger.TaggerWrapper tagger, string charset)
 {
     //// Variables
     //// Constructors
     this.tagger  = tagger;
     listener     = new ServerSocket(port);
     this.charset = charset;
 }
Пример #2
0
        // 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.
        /// <p>
        /// Usage: <code>java edu.stanford.nlp.tagger.maxent.MaxentTaggerServer [-model file|-client] -port portNumber [other MaxentTagger options]</code>
        /// </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)
        {
            if (args.Length == 0)
            {
                log.Info(Usage);
                return;
            }
            // Use both Properties and TaggerConfig.  It's okay.
            Properties props   = StringUtils.ArgsToProperties(args);
            string     client  = props.GetProperty("client");
            string     portStr = props.GetProperty("port");

            if (portStr == null || portStr.Equals(string.Empty))
            {
                log.Info(Usage);
                return;
            }
            int port = 0;

            try
            {
                port = System.Convert.ToInt32(portStr);
            }
            catch (NumberFormatException)
            {
                log.Info("Non-numerical port");
                log.Info(Usage);
                System.Environment.Exit(1);
            }
            if (client != null && !client.Equals(string.Empty))
            {
                // run a test client for illustration/testing
                string host     = props.GetProperty("host");
                string encoding = props.GetProperty("encoding");
                if (encoding == null || string.Empty.Equals(encoding))
                {
                    encoding = "utf-8";
                }
                MaxentTaggerServer.TaggerClient.CommunicateWithMaxentTaggerServer(host, port, encoding);
            }
            else
            {
                TaggerConfig config = new TaggerConfig(args);
                MaxentTagger tagger = new MaxentTagger(config.GetModel(), config);
                // initializes tagger
                MaxentTagger.TaggerWrapper wrapper = new MaxentTagger.TaggerWrapper(tagger);
                new MaxentTaggerServer(port, wrapper, config.GetEncoding()).Run();
            }
        }