public class StanfordCoreNLPServer
extends java.lang.Object
implements java.lang.Runnable
Modifier and Type | Class and Description |
---|---|
protected class |
StanfordCoreNLPServer.CoreNLPHandler
The main handler for taking an annotation request, and annotating it.
|
static class |
StanfordCoreNLPServer.FileHandler
Serve a file from the filesystem or classpath
|
static class |
StanfordCoreNLPServer.FinishedRequest
A callback object that lets us hook into the result of an annotation request.
|
protected static class |
StanfordCoreNLPServer.LiveHandler
A handler to let the caller know if the server is alive,
but not necessarily ready to respond to requests.
|
protected static class |
StanfordCoreNLPServer.PingHandler
A simple ping test.
|
protected static class |
StanfordCoreNLPServer.ReadyHandler
A handler to let the caller know if the server is alive AND ready to respond to requests.
|
protected class |
StanfordCoreNLPServer.SemgrexHandler
A handler for matching semgrex patterns against dependency trees.
|
protected class |
StanfordCoreNLPServer.ShutdownHandler
Sending the appropriate shutdown key will gracefully shutdown the server.
|
protected class |
StanfordCoreNLPServer.TokensRegexHandler
A handler for matching TokensRegex patterns against text.
|
protected class |
StanfordCoreNLPServer.TregexHandler
A handler for matching tregrex patterns against dependency trees.
|
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
blockList |
protected static java.lang.String |
key |
protected static int |
maxCharLength |
protected java.lang.String |
password |
protected static java.lang.String |
preloadedAnnotators |
protected boolean |
quiet |
protected com.sun.net.httpserver.HttpServer |
server |
protected java.lang.String |
serverID |
protected int |
serverPort |
protected static java.lang.String |
serverPropertiesPath |
protected boolean |
ssl |
protected boolean |
stanford |
protected int |
statusPort |
protected boolean |
strict |
protected int |
timeoutMilliseconds |
protected java.lang.String |
uriContext |
protected java.lang.String |
username |
Constructor and Description |
---|
StanfordCoreNLPServer()
Create a new Stanford CoreNLP Server, with the default parameters.
|
StanfordCoreNLPServer(int port,
int timeout,
boolean strict)
Create a new Stanford CoreNLP Server.
|
StanfordCoreNLPServer(java.util.Properties props)
Create a new Stanford CoreNLP Server with the default parameters and
pass in properties (server_id, ...).
|
StanfordCoreNLPServer(java.util.Properties props,
int port,
int timeout,
boolean strict)
Create a new Stanford CoreNLP Server.
|
Modifier and Type | Method and Description |
---|---|
java.util.Optional<com.sun.net.httpserver.HttpServer> |
getServer()
Returns the implementing Http server.
|
protected int |
getTimeout(java.util.Properties props,
com.sun.net.httpserver.HttpExchange httpExchange) |
static StanfordCoreNLPServer |
launchServer(java.lang.String[] args)
The main method.
|
static void |
main(java.lang.String[] args) |
void |
run() |
void |
run(java.util.Optional<Pair<java.lang.String,java.lang.String>> basicAuth,
java.util.function.Predicate<java.util.Properties> authenticator,
java.util.function.Consumer<StanfordCoreNLPServer.FinishedRequest> callback,
StanfordCoreNLPServer.FileHandler homepage,
boolean https,
java.util.concurrent.atomic.AtomicBoolean live)
Run the server.
|
protected com.sun.net.httpserver.HttpServer server
@ArgumentParser.Option(name="server_id", gloss="a name for this server") protected java.lang.String serverID
@ArgumentParser.Option(name="port", gloss="The port to run the server on") protected int serverPort
@ArgumentParser.Option(name="status_port", gloss="The port to serve the status check endpoints on. If different from the server port, this will run in a separate thread.") protected int statusPort
@ArgumentParser.Option(name="uriContext", gloss="The URI context") protected java.lang.String uriContext
@ArgumentParser.Option(name="timeout", gloss="The default timeout, in milliseconds") protected int timeoutMilliseconds
@ArgumentParser.Option(name="strict", gloss="If true, obey strict HTTP standards (e.g., with encoding)") protected boolean strict
@ArgumentParser.Option(name="quiet", gloss="If true, don\'t print to stdout and don\'t log every API POST") protected boolean quiet
@ArgumentParser.Option(name="ssl", gloss="If true, start the server with an [insecure!] SSL connection") protected boolean ssl
@ArgumentParser.Option(name="key", gloss="The *.jks key file to load, if -ssl is enabled. By default, it\'ll load the dummy key from the jar (but this is, of course, insecure!)") protected static java.lang.String key
@ArgumentParser.Option(name="username", gloss="The username component of a username/password basic auth credential") protected java.lang.String username
@ArgumentParser.Option(name="password", gloss="The password component of a username/password basic auth credential") protected java.lang.String password
@ArgumentParser.Option(name="preload", gloss="Cache all default annotators (if no list provided), or optionally provide comma separated list of annotators to preload (e.g. tokenize,ssplit,pos)") protected static java.lang.String preloadedAnnotators
@ArgumentParser.Option(name="serverProperties", gloss="Default properties file for server\'s StanfordCoreNLP instance") protected static java.lang.String serverPropertiesPath
@ArgumentParser.Option(name="maxCharLength", gloss="Max length string that will be processed (non-positive means no limit)") protected static int maxCharLength
@ArgumentParser.Option(name="blockList", gloss="A file containing subnets that should be forbidden from accessing the server. Each line is a subnet. They are specified as an IPv4 address followed by a slash followed by how many leading bits to maintain as the subnet mask. E.g., \'54.240.225.0/24\'.") protected static java.lang.String blockList
@ArgumentParser.Option(name="stanford", gloss="If true, do special options (domain blockList, timeout modifications) for public Stanford server") protected boolean stanford
public StanfordCoreNLPServer(java.util.Properties props, int port, int timeout, boolean strict) throws java.io.IOException
props
- A list of properties for the server (server_id, ...)port
- The port to host the server from.timeout
- The timeout (in milliseconds) for each command.strict
- If true, conform more strictly to the HTTP spec (e.g., for character encoding).java.io.IOException
- Thrown from the underlying socket implementation.public StanfordCoreNLPServer(int port, int timeout, boolean strict) throws java.io.IOException
port
- The port to host the server from.timeout
- The timeout (in milliseconds) for each command.strict
- If true, conform more strictly to the HTTP spec (e.g., for character encoding).java.io.IOException
- Thrown from the underlying socket implementation.public StanfordCoreNLPServer() throws java.io.IOException
java.io.IOException
- Thrown if we could not write the shutdown key to the a file.public StanfordCoreNLPServer(java.util.Properties props) throws java.io.IOException
java.io.IOException
- Thrown if we could not write the shutdown key to the a file.protected int getTimeout(java.util.Properties props, com.sun.net.httpserver.HttpExchange httpExchange)
public java.util.Optional<com.sun.net.httpserver.HttpServer> getServer()
public void run()
run
in interface java.lang.Runnable
run(Optional, Predicate, Consumer, StanfordCoreNLPServer.FileHandler, boolean, AtomicBoolean)
public void run(java.util.Optional<Pair<java.lang.String,java.lang.String>> basicAuth, java.util.function.Predicate<java.util.Properties> authenticator, java.util.function.Consumer<StanfordCoreNLPServer.FinishedRequest> callback, StanfordCoreNLPServer.FileHandler homepage, boolean https, java.util.concurrent.atomic.AtomicBoolean live)
public static StanfordCoreNLPServer launchServer(java.lang.String[] args) throws java.io.IOException
args
- The command line argumentsjava.io.IOException
- Thrown if we could not start / run the server.public static void main(java.lang.String[] args) throws java.io.IOException
java.io.IOException