Skip to content

Commit

Permalink
latest english jar
Browse files Browse the repository at this point in the history
  • Loading branch information
J38 authored and Stanford NLP committed Jan 13, 2016
1 parent f398d5e commit d86cef3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ coref.big.gender.number = edu/stanford/nlp/models/dcoref/gender.data.gz
coref.zh.dict = edu/stanford/nlp/models/dcoref/zh-attributes.txt.gz

coref.addMissingAnnotations = true
coref.specialCaseNewswire = true

# Evaluation
coref.path.scorer.conll = /scr/nlp/data/conll-2012/scorer/v8.01/scorer.pl
Expand Down
4 changes: 1 addition & 3 deletions src/edu/stanford/nlp/pipeline/MentionAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import edu.stanford.nlp.trees.TreeCoreAnnotations;
import edu.stanford.nlp.util.ArraySet;
import edu.stanford.nlp.util.CoreMap;
import edu.stanford.nlp.util.PropertiesUtils;

/**
* This class adds mention information to an Annotation.
Expand Down Expand Up @@ -70,8 +69,7 @@ public void annotate(Annotation annotation) {
docID = "";
}
if (docID.contains("nw") && corefProperties.getProperty("coref.input.type", "raw").equals("conll") &&
corefProperties.getProperty("coref.language", "en").equals("zh") &&
PropertiesUtils.getBool(corefProperties,"coref.specialCaseNewswire")) {
corefProperties.getProperty("coref.language", "en").equals("zh")) {
CorefProperties.setRemoveNested(corefProperties, false);
} else {
CorefProperties.setRemoveNested(corefProperties, true);
Expand Down
62 changes: 34 additions & 28 deletions src/edu/stanford/nlp/pipeline/StanfordCoreNLPServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@
/**
* This class creates a server that runs a new Java annotator in each thread.
*
* @author Gabor Angeli
* @author Arun Chaganty
*/
public class StanfordCoreNLPServer implements Runnable {

protected static int DEFAULT_PORT = 9000;
protected static int DEFAULT_TIMEOUT = 5000;

Expand Down Expand Up @@ -77,10 +74,10 @@ public StanfordCoreNLPServer(int port, int timeout) throws IOException {
serverPort = port;
timeoutMilliseconds = timeout;

defaultProps = PropertiesUtils.asProperties(
"annotators", "tokenize, ssplit, pos, lemma, ner, parse, depparse, dcoref, natlog, openie",
"inputFormat", "text",
"outputFormat", "json");
defaultProps = new Properties();
defaultProps.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, depparse, dcoref, natlog, openie");
defaultProps.setProperty("inputFormat", "text");
defaultProps.setProperty("outputFormat", "json");

// Generate and write a shutdown key
String tmpDir = System.getProperty("java.io.tmpdir");
Expand Down Expand Up @@ -141,7 +138,7 @@ private static Map<String, String> getURLParams(URI uri) throws UnsupportedEncod
* @throws IOException Thrown if we cannot read the POST data.
* @throws ClassNotFoundException Thrown if we cannot load the serializer.
*/
private static Annotation getDocument(Properties props, HttpExchange httpExchange) throws IOException, ClassNotFoundException {
private Annotation getDocument(Properties props, HttpExchange httpExchange) throws IOException, ClassNotFoundException {
String inputFormat = props.getProperty("inputFormat", "text");
switch (inputFormat) {
case "text":
Expand Down Expand Up @@ -200,7 +197,7 @@ private StanfordCoreNLP mkStanfordCoreNLP(Properties props) {
*
* @throws IOException Thrown if the HttpExchange cannot communicate the error.
*/
private static void respondError(String response, HttpExchange httpExchange) throws IOException {
private void respondError(String response, HttpExchange httpExchange) throws IOException {
httpExchange.getResponseHeaders().add("Content-Type", "text/plain");
httpExchange.sendResponseHeaders(HTTP_ERR, response.length());
httpExchange.getResponseBody().write(response.getBytes());
Expand All @@ -216,7 +213,7 @@ private static void respondError(String response, HttpExchange httpExchange) thr
*
* @throws IOException Thrown if the HttpExchange cannot communicate the error.
*/
private static void respondBadInput(String response, HttpExchange httpExchange) throws IOException {
private void respondBadInput(String response, HttpExchange httpExchange) throws IOException {
httpExchange.getResponseHeaders().add("Content-Type", "text/plain");
httpExchange.sendResponseHeaders(HTTP_BAD_INPUT, response.length());
httpExchange.getResponseBody().write(response.getBytes());
Expand Down Expand Up @@ -322,7 +319,6 @@ public String getContentType(Properties props, StanfordCoreNLP.OutputFormat of)
outputSerializerName.equals(ProtobufAnnotationSerializer.class.getName())) {
return "application/x-protobuf";
}
//noinspection fallthrough
default:
return "application/octet-stream";
}
Expand All @@ -342,7 +338,7 @@ public void handle(HttpExchange httpExchange) throws IOException {
ann = getDocument(props, httpExchange);
of = StanfordCoreNLP.OutputFormat.valueOf(props.getProperty("outputFormat", "json").toUpperCase());

if (ann.get(CoreAnnotations.TextAnnotation.class).isEmpty()) {
if (ann.get(CoreAnnotations.TextAnnotation.class).length() == 0) {
// Handle direct browser connections (i.e., not a POST request).
log("[" + httpExchange.getRemoteAddress() + "] Interactive connection");
staticPageHandle.handle(httpExchange);
Expand Down Expand Up @@ -492,7 +488,9 @@ public void handle(HttpExchange httpExchange) throws IOException {
Future<String> json = corenlpExecutor.submit(() -> {
try {
// Get the document
Properties props = PropertiesUtils.asProperties("annotators", "tokenize,ssplit,pos,lemma,ner");
Properties props = new Properties() {{
setProperty("annotators", "tokenize,ssplit,pos,lemma,ner");
}};
Annotation doc = getDocument(props, httpExchange);
if (!doc.containsKey(CoreAnnotations.SentencesAnnotation.class)) {
StanfordCoreNLP pipeline = mkStanfordCoreNLP(props);
Expand Down Expand Up @@ -559,12 +557,19 @@ public void handle(HttpExchange httpExchange) throws IOException {
});

// Send response
byte[] response = new byte[0];
try {
byte[] response = json.get(5, TimeUnit.SECONDS).getBytes();
sendAndGetResponse(httpExchange, response);
response = json.get(5, TimeUnit.SECONDS).getBytes();
} catch (InterruptedException | ExecutionException | TimeoutException e) {
respondError("Timeout when executing TokensRegex query", httpExchange);
}
if (response.length > 0) {
httpExchange.getResponseHeaders().add("Content-Type", "text/json");
httpExchange.getResponseHeaders().add("Content-Length", Integer.toString(response.length));
httpExchange.sendResponseHeaders(HTTP_OK, response.length);
httpExchange.getResponseBody().write(response);
httpExchange.close();
}
}
}

Expand All @@ -583,7 +588,9 @@ public void handle(HttpExchange httpExchange) throws IOException {
Future<String> json = corenlpExecutor.submit(() -> {
try {
// Get the document
Properties props = PropertiesUtils.asProperties("annotators", "tokenize,ssplit,pos,lemma,ner,depparse");
Properties props = new Properties() {{
setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,depparse");
}};
Annotation doc = getDocument(props, httpExchange);
if (!doc.containsKey(CoreAnnotations.SentencesAnnotation.class)) {
StanfordCoreNLP pipeline = mkStanfordCoreNLP(props);
Expand Down Expand Up @@ -648,24 +655,24 @@ public void handle(HttpExchange httpExchange) throws IOException {
});

// Send response
byte[] response = new byte[0];
try {
byte[] response = json.get(5, TimeUnit.SECONDS).getBytes();
sendAndGetResponse(httpExchange, response);
response = json.get(5, TimeUnit.SECONDS).getBytes();
} catch (InterruptedException | ExecutionException | TimeoutException e) {
respondError("Timeout when executing Semgrex query", httpExchange);
}
if (response.length > 0) {
httpExchange.getResponseHeaders().add("Content-Type", "text/json");
httpExchange.getResponseHeaders().add("Content-Length", Integer.toString(response.length));
httpExchange.sendResponseHeaders(HTTP_OK, response.length);
httpExchange.getResponseBody().write(response);
httpExchange.close();
}
}
}

private static void sendAndGetResponse(HttpExchange httpExchange, byte[] response) throws IOException {
if (response.length > 0) {
httpExchange.getResponseHeaders().add("Content-Type", "text/json");
httpExchange.getResponseHeaders().add("Content-Length", Integer.toString(response.length));
httpExchange.sendResponseHeaders(HTTP_OK, response.length);
httpExchange.getResponseBody().write(response);
httpExchange.close();
}
}




/**
Expand Down Expand Up @@ -735,5 +742,4 @@ public static void main(String[] args) throws IOException {
StanfordCoreNLPServer server = new StanfordCoreNLPServer(port, timeout);
server.run();
}

}

0 comments on commit d86cef3

Please sign in to comment.