}
@SuppressWarnings("unchecked")
@Override
public DataBag exec(Tuple input) throws IOException {
SentenceDetectorME sentenceDetector = new SentenceDetectorME(model);
DataBag output = bagFactory.newDefaultBag();
Object t0 = input.get(0);
if (!(t0 instanceof String)) {
throw new IOException("Expected input to be chararray, but got "
+ t0.getClass().getName());
}
Object t1 = input.get(1);
if (!(t1 instanceof DataBag)) {
throw new IOException("Expected input to be bag of links, but got "
+ t1.getClass().getName());
}
Object t2 = input.get(2);
if (!(t1 instanceof DataBag)) {
throw new IOException(
"Expected input to be bag of paragraphs, but got "
+ t2.getClass().getName());
}
String text = (String) t0;
DataBag links = (DataBag) t1;
DataBag paragraphBag = (DataBag) t2;
// convert the bag of links as absolute spans over the text
List<Span> linkSpans = new ArrayList<Span>();
for (Tuple l : links) {
linkSpans.add(new Span((Integer) l.get(1), (Integer) l.get(2),
(String) l.get(0)));
}
Collections.sort(linkSpans);
// iterate of the paragraph and extract sentence locations
int order = 0;
for (Tuple p : paragraphBag) {
Integer beginParagraph = (Integer) p.get(1);
Integer endParagraph = (Integer) p.get(2);
Span[] spans = sentenceDetector.sentPosDetect(text.substring(
beginParagraph, endParagraph));
for (Span sentenceRelative : spans) {
// for each sentence found in that paragraph, compute the
// absolute span of the text
order++;