request += line;
numLines++;
}
Annotation response = null;
boolean retry = false;
int retryCount = 0;
do{
try{
LOG.info("Sending request to the server");
WebResource r = c.resource(SPOTLIGHT_ENDPOINT);
response =
r.queryParam("text", request)
.queryParam("confidence", "" + CONFIDENCE)
.queryParam("support", "" + SUPPORT)
.queryParam("types", TYPES)
.queryParam("sparql", SPARQL)
.queryParam("policy", POLICY)
.queryParam("coreferenceResolution",
Boolean.toString(COREFERENCE_RESOLUTION))
.queryParam("spotter", SPOTTER)
.queryParam("disambiguator", DISAMBIGUATOR)
.type("application/x-www-form-urlencoded;charset=UTF-8")
.accept(MediaType.TEXT_XML)
.post(Annotation.class);
retry = false;
} catch (Exception e){
//In case of a failure, try sending the request with a 2 second delay at least three times before throwing an exception
LOG.error("Server request failed. Will try again in 2 seconds..", e);
LOG.error("Failed request payload: " +request);
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
LOG.error("Thread interrupted",e1);
}
if (retryCount++ < 3){
retry = true;
} else {
throw new AnalysisEngineProcessException("The server request failed", null);
}
}
}while(retry);
LOG.info("Server request completed. Writing to the index");
/*
* Add the results to the AnnotationIndex
*/
for (Resource resource : response.getResources()) {
JCasResource res = new JCasResource(aJCas);
res.setBegin(documentOffset + new Integer(resource.getOffset()));
res.setEnd(documentOffset + new Integer(resource.getOffset())
+ resource.getSurfaceForm().length());
res.setSimilarityScore(new Double(resource.getSimilarityScore()));