// Send request
wr = new BufferedWriter(new OutputStreamWriter(
connection.getOutputStream(),UTF8));
} catch (IOException e) {
IOUtils.closeQuietly(wr);
throw new EngineException("Unable to open connection to "+
spotlightUrl,e);
}
try {
if (spotlightSpotter != null && !spotlightSpotter.isEmpty()){
wr.write("spotter=");
wr.write(URLEncoder.encode(spotlightSpotter, "UTF-8"));
wr.write('&');
}
if (spotlightDisambiguator != null
&& !spotlightDisambiguator.isEmpty()){
wr.write("disambiguator=");
wr.write(URLEncoder.encode(spotlightDisambiguator, "UTF-8"));
wr.write('&');
}
if (spotlightTypesRestriction != null
&& !spotlightTypesRestriction.isEmpty()) {
wr.write("types=");
wr.write(URLEncoder.encode(spotlightTypesRestriction, "UTF-8"));
wr.write('&');
}
if (spotlightSupport != null && !spotlightSupport.isEmpty()) {
wr.write("support=");
wr.write(URLEncoder.encode(spotlightSupport, "UTF-8"));
wr.write('&');
}
if (spotlightConfidence != null && !spotlightConfidence.isEmpty()) {
wr.write("confidence=");
wr.write(URLEncoder.encode(spotlightConfidence, "UTF-8"));
wr.write('&');
}
if (spotlightSparql != null && !spotlightSparql.isEmpty()
&& spotlightTypesRestriction == null) {
wr.write("sparql=");
wr.write(URLEncoder.encode(spotlightSparql, "UTF-8"));
wr.write('&');
}
wr.write("text=");
wr.write(URLEncoder.encode(text, "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(
"The platform does not support encoding " + UTF8.name(),e);
} catch (IOException e) {
throw new EngineException("Unable to write 'plain/text' content "
+ "for ContentItem "+contentItemUri+" to "
+ spotlightUrl,e);
} finally {
IOUtils.closeQuietly(wr);
}
InputStream is = null;
Document xmlDoc;
try {
// Get Response
is = connection.getInputStream();
xmlDoc = loadXMLFromInputStream(is);
} catch (IOException e) {
throw new EngineException("Unable to spot Entities with"
+ "Dbpedia Spotlight Annotate RESTful Serice running at "
+ spotlightUrl,e);
} catch(SAXException e) {
throw new EngineException("Unable to parse Response from "
+ "Dbpedia Spotlight Annotate RESTful Serice running at "
+ spotlightUrl,e);
} finally {
IOUtils.closeQuietly(is);
}