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 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; }
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 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 }; } }
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); }
/** 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()); }
public static int getCandidatePosition(Annotation candidate, List<Token> tokens) { int position = -1; for (int i = 0; i < tokens.size(); i++) { if (tokens.get(i).getBegin() == candidate.getBegin() && tokens.get(i).getEnd() == candidate.getEnd()) { position = i; } } return position; }
/** 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()); }
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 void process(JCas jCas) throws AnalysisEngineProcessException { if (windowClass != null) { for (Annotation window : JCasUtil.select(jCas, windowClass)) { String text = window.getCoveredText(); createParentheticals(jCas, text, window.getBegin()); } } else { String text = jCas.getDocumentText(); createParentheticals(jCas, text, 0); } }