Skip to content

Commit

Permalink
Set encoding of StringEntity #9, add pipelineLanguage extraction sett…
Browse files Browse the repository at this point in the history
…ing #10
  • Loading branch information
stkenny committed Mar 14, 2021
1 parent fed2a05 commit 695f657
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class StanfordNLP extends NERServiceBase implements NERService {
private final static URI SERVICEBASEURL = createUri("http://localhost:9000");
private final static URI DOCUMENTATIONURI = createUri("https://stanfordnlp.github.io/CoreNLP/ner.html");
private final static String[] SERVICESETTINGS = {"NLP Service URL"};
private final static String[] EXTRACTIONSETTINGS = {"applyNumericClassifiers", "applyFineGrained"};
private final static String[] EXTRACTIONSETTINGS = {"applyNumericClassifiers", "applyFineGrained", "pipelineLanguage"};

/**
* Creates a new Stanford NLP service connector
Expand All @@ -37,6 +37,7 @@ public StanfordNLP() {
super(SERVICEBASEURL, null, SERVICESETTINGS, EXTRACTIONSETTINGS);
setExtractionSettingDefault("applyNumericClassifiers", "false");
setExtractionSettingDefault("applyFineGrained", "true");
setExtractionSettingDefault("pipelineLanguage", "default");
}

/**
Expand All @@ -56,6 +57,7 @@ protected HttpUriRequest createExtractionRequest(final String text, final Map<St
final HttpPost request = new HttpPost(requestUrl);
request.setHeader("Accept", "application/json");
request.setHeader("User-Agent", "Refine NER Extension");
request.setHeader("Content-Type", "UTF-8");
request.setEntity(body);
return request;
}
Expand All @@ -65,7 +67,7 @@ protected HttpUriRequest createExtractionRequest(final String text, final Map<St
*/
protected HttpEntity createExtractionRequestBody(final String text, final Map<String, String> extractionSettings)
throws UnsupportedEncodingException {
return new StringEntity(text);
return new StringEntity(text, "UTF-8");
}

/**
Expand Down Expand Up @@ -101,7 +103,8 @@ protected URI createExtractionRequestUrl(final String text, final Map<String, St
builder.addParameter("properties", "{\"annotators\":\"ner\","
+ "\"ner.applyNumericClassifiers\":\""
+ extractionSettings.get("applyNumericClassifiers") + "\","
+ "\"ner.applyFineGrained\":\"" + extractionSettings.get("applyFineGrained") + "\"}"
+ "\"ner.applyFineGrained\":\"" + extractionSettings.get("applyFineGrained") + "\","
+ "\"pipelineLanguage\":\"" + extractionSettings.get("pipelineLanguage") + "\"}"
);

return builder.build();
Expand Down

0 comments on commit 695f657

Please sign in to comment.