/** * Gets the end. * * @return the end */ public int getEnd() { return isAnnotation() ? ((Annotation)fs).getEnd() : -1; }
public static int[] getAnnotationsExtent(List<? extends Annotation> annotations) { int start = Integer.MAX_VALUE; int end = 0; for (Annotation annotation : annotations) { if (annotation.getBegin() < start) start = annotation.getBegin(); if (annotation.getEnd() > end) end = annotation.getEnd(); } return new int[] { start, end }; } }
public static boolean contains(Annotation bigAnnotation, Annotation smallAnnotation) { if (bigAnnotation == null || smallAnnotation == null) return false; if (bigAnnotation.getBegin() <= smallAnnotation.getBegin() && bigAnnotation.getEnd() >= smallAnnotation.getEnd()) return true; else return false; }
public static int countPoint (Collection<? extends Annotation> c, int b, int e) { //TODO: substitute hard-coded boundaries to flexible conditions int ret = 0; for (Annotation a : c) { int begin = a.getBegin(); int end = a.getEnd(); if (begin<end && begin>b && begin<=e) ++ret; } return ret; } }
public static int countInterval (Collection<? extends Annotation> c, int b, int e) { //TODO: substitute hard-coded boundaries to flexible conditions int ret = 0; for (Annotation a : c) if (a.getBegin()>b && a.getEnd()<e) ++ret; return ret; }
static String format(Annotation ann) { String result; if (ann.getEnd() == Integer.MIN_VALUE || ann.getBegin() == Integer.MAX_VALUE) { result = "<no-spanned-text>"; } else { result = String.format("\"%s\"[%d,%d]", ann.getCoveredText(), ann.getBegin(), ann.getEnd()); } return String.format("%s(%s)", ann.getClass().getSimpleName(), result); }
static String format(Annotation ann) { String result; if (ann.getEnd() == Integer.MIN_VALUE || ann.getBegin() == Integer.MAX_VALUE) { result = "<no-spanned-text>"; } else { result = String.format("\"%s\"[%d,%d]", ann.getCoveredText(), ann.getBegin(), ann.getEnd()); } return String.format("%s(%s)", ann.getClass().getSimpleName(), result); }
/** Checks if one annotation subsumes another */ public static boolean doesSubsume(Annotation annot1,Annotation annot2) { if (annot1==null || annot2==null) return false; return annot1.getBegin()<=annot2.getBegin() && annot1.getEnd()>=annot2.getEnd() && annot1.getCoveredText().contains(annot2.getCoveredText()); }
/** Equality expressions to aid in converting between DepNodes and CAS objects */ public static boolean equalCoverage(Annotation annot1,Annotation annot2) { if (annot1==null || annot2==null) return false; return annot1.getBegin()==annot2.getBegin() && annot1.getEnd()==annot2.getEnd() && annot1.getCoveredText().equals(annot2.getCoveredText()); }
private Annotation hasAnnotation(JCas jCas, Class evidenceType, Annotation scopeAnnotation) { if (evidenceAnnotationTree.get(evidenceType) == null) { return null; } Annotation res = evidenceAnnotationTree.get(evidenceType).get(new Interval1D(scopeAnnotation.getBegin(), scopeAnnotation.getEnd())); return res; }
public static IntervalST<Annotation> indexAnnotation(JCas jcas, Class<? extends Annotation> type) { Iterator<? extends Annotation> annotationIter = JCasUtil.iterator(jcas, type); IntervalST<Annotation> index = new IntervalST<>(); while (annotationIter.hasNext()) { Annotation annotation = type.cast(annotationIter.next()); // assume there is no overlapping annotations index.put(new Interval1D(annotation.getBegin(), annotation.getEnd()), annotation); } return index; }
private void indexAnnotations(JCas jCas) { for (Class conceptType : evidenceAnnotationTree.keySet()) { FSIndex annoIndex = jCas.getAnnotationIndex(conceptType); Iterator annoIter = annoIndex.iterator(); IntervalST<Annotation> intervalST = new IntervalST<>(); while (annoIter.hasNext()) { Annotation anno = (Annotation) annoIter.next(); intervalST.put(new Interval1D(anno.getBegin(), anno.getEnd()), anno); } evidenceAnnotationTree.put(conceptType, intervalST); } }
@Override public ImmutableSpanTextLabel apply(final Annotation annotation) { final ImmutableSpan span = new ImmutableSpan(annotation.getBegin(), annotation.getEnd()); final ImmutableSpanText spanText = new ImmutableSpanText(span, annotation.getCoveredText()); final Map<Attribute, Object> attrs = createAttrMap(annotation); return new ImmutableSpanTextLabel(spanText, annotation.getType().getShortName(), attrs); }