private static Target prepareOneTarget(JCas view, Collection<Token> tokens) { int countTokens = tokens.size(); if (countTokens == 0) // check; null means no Tokens for target. return null; Target aTarget = new Target(view); FSArray annots = new FSArray(view, countTokens); aTarget.setTargetAnnotations(annots); Iterator<Token> itr = tokens.iterator(); int begin = -1; // I am using -1 as "not set yet". int end=0; for(int i=0; i < countTokens; i++) { Token t = itr.next(); if (begin == -1) // if not set. begin = t.getBegin(); end = t.getEnd(); // we are assuming that collection tokens is ordered. annots.set(i, t); } aTarget.setBegin(begin); aTarget.setEnd(end); aTarget.addToIndexes(); return aTarget; }
textTarget.setTargetAnnotations(textAnnots); hypoTarget.setTargetAnnotations(hypoAnnots);
/** * Prepare target instance for given view using given annotations * * @param view * View to prepare target instance on * @param annot * Annotation to add to given target instance * @return prepared target instance */ private Target prepareTarget(JCas view, Annotation annot) { // prepare a Target instance. Target target = new Target(view); // prepare a FSArray instance, put the target annotations in it. FSArray tAnnots = new FSArray(view, 1); tAnnots.set(0, annot); // the FSArray is prepared. Put it on field "targetAnnotations" target.setTargetAnnotations(tAnnots); // set begin - end value of the Target annotation (just like any // annotation) // setting of begin and end of Target is a convention. // - begin as the earliest "begin" (among Target-ed annotations) // - end as the latest "end" (among Target-ed annotations) target.setBegin(annot.getBegin()); target.setEnd(annot.getEnd()); // add it to the index (just like any annotation) target.addToIndexes(); return target; }
queryAnnots.set(0, ntype); tg.setTargetAnnotations(queryAnnots); tg.setBegin(queryStart); tg.setEnd(queryEnd); FSArray entryAnnots = new FSArray(entryView, 1); entryAnnots.set(0, ntype); tg.setTargetAnnotations(entryAnnots); tg.setBegin(entryStart); tg.setEnd(entryEnd);
hypoAnnots.set(0, hypoToken); textTarget.setTargetAnnotations(textAnnots); hypoTarget.setTargetAnnotations(hypoAnnots);