throw new TerminateToolException(-1, "Failed to load the properties file!");
}
// TODO: It should not just throw Exception.
EntityLinker entityLinker;
try {
entityLinker = EntityLinkerFactory.getLinker(entityType, properties);
}
catch (Exception e) {
throw new TerminateToolException(-1, "Failed to instantiate the Entity Linker: " + e.getMessage());
}
PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
perfMon.start();
try {
ObjectStream<String> untokenizedLineStream = new PlainTextByLineStream(
new SystemInputStreamFactory(), SystemInputStreamFactory.encoding());
List<NameSample> document = new ArrayList<NameSample>();
String line;
while ((line = untokenizedLineStream.read()) != null) {
if (line.trim().isEmpty()) {
// Run entity linker ... and output result ...
StringBuilder text = new StringBuilder();
Span sentences[] = new Span[document.size()];
Span[][] tokensBySentence = new Span[document.size()][];
Span[][] namesBySentence = new Span[document.size()][];
for (int i = 0; i < document.size(); i++) {
NameSample sample = document.get(i);
namesBySentence[i] = sample.getNames();
int sentenceBegin = text.length();
Span[] tokens = new Span[sample.getSentence().length];
// for all tokens
for (int ti = 0; ti < sample.getSentence().length; ti++) {
int tokenBegin = text.length();
text.append(sample.getSentence()[ti]);
text.append(" ");
tokens[i] = new Span(tokenBegin, text.length());
}
tokensBySentence[i] = tokens;
sentences[i] = new Span(sentenceBegin, text.length());
text.append("\n");
}
List<Span> linkedSpans = entityLinker.find(text.toString(), sentences, tokensBySentence, namesBySentence);
for (int i = 0; i < linkedSpans.size(); i++) {
System.out.println(linkedSpans.get(i));
}