@Override public void performAction( Annotation aAnnot, Annotation bAnnot ) { if ( iv_selector == SELECT_A ) { aAnnot.removeFromIndexes(); } else if (iv_selector == SELECT_B) { bAnnot.removeFromIndexes(); } else { aAnnot.removeFromIndexes(); bAnnot.removeFromIndexes(); } } }
@Override public void performAction( Annotation aAnnot, Annotation bAnnot ) { if ( iv_selector == SELECT_A ) { aAnnot.removeFromIndexes(); } else if (iv_selector == SELECT_B) { bAnnot.removeFromIndexes(); } else { aAnnot.removeFromIndexes(); bAnnot.removeFromIndexes(); } } }
/** * Remove all annotations of the type provided in the Collection except the annotations stored * in the collection. * * @param jCas * for annotation removal. * @param annotations * which should be kept in the JCas. */ private void removeAnnotationsExceptGiven(JCas jCas, Collection<? extends Annotation> annotations) { if (annotations.isEmpty()) { throw new IllegalArgumentException("Annotation list should not be empty!"); } Collection<? extends Annotation> foundAnnotations = JCasUtil.select(jCas, annotations .iterator().next().getClass()); List<Annotation> toDelete = new ArrayList<Annotation>(); for (Annotation annotation : foundAnnotations) { if (!annotations.contains(annotation)) { toDelete.add(annotation); } } for (Annotation a : toDelete) { a.removeFromIndexes(); } }
@Override public void process(JCas jCas) throws AnalysisEngineProcessException { boolean hasRodent = false; for (LinnaeusSpecies sp : select(jCas, LinnaeusSpecies.class)) { // e.g. species:ncbi:9685 int species = parseInt(sp.getMostProbableSpeciesId().substring( "species:ncbi:".length())); if (NCBI_MURIDAE.contains(species)) { hasRodent = true; break; } } if (!hasRodent) { // Copy the tokens into a new collection to avoid // ConcurrentModificationExceptions if (className.equals("all")) { for (TOP t : newArrayList(select(jCas, TOP.class))) t.removeFromIndexes(); } else { for (Annotation a : newArrayList(select(jCas, aClass))) a.removeFromIndexes(); } } }
private static void rmDup(LinkedList<Annotation> markables) { HashSet<Annotation> rm = new HashSet<>(); HashMap<String,Annotation> keep = new HashMap<>(); for (int i = 0; i < markables.size(); i++) { Annotation m1 = markables.get(i); String key = m1.getBegin() + "-" + m1.getEnd(); if(!keep.containsKey(key)){ keep.put(key, m1); }else{ Annotation m2 = keep.get(key); if(m2 instanceof DemMarkable && m1 instanceof NEMarkable){ rm.add(m2); keep.put(key,m1); }else if(m1 instanceof DemMarkable && m2 instanceof NEMarkable){ rm.add(m1); }else{ // doesn't matter, they're probably both NE's rm.add(m1); } } } for (Annotation a : rm) a.removeFromIndexes(); } }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { Set<IntPair> s = new HashSet<IntPair>(); Set<Annotation> toRemove = new HashSet<Annotation>(); for (Annotation a : JCasUtil.select(jcas, clazz)) { IntPair ip = new IntPair(a.getBegin(), a.getEnd()); if (s.contains(ip)) { toRemove.add(a); } else { s.add(ip); } } for (Annotation a : toRemove) { a.removeFromIndexes(); } }
private static void removeHistoryOf(JCas jCas) { FSIterator<Annotation> iter = jCas.getAnnotationIndex(NEMarkable.type).iterator(); ArrayList<Annotation> rm = new ArrayList<>(); while(iter.hasNext()){ NEMarkable m = (NEMarkable) iter.next(); if(m.getCoveredText().equalsIgnoreCase("history of")){ rm.add(m); } } for(Annotation a: rm){ a.removeFromIndexes(); } }
private static void removeHistoryOf(JCas jCas) { FSIterator<Annotation> iter = jCas.getAnnotationIndex(NEMarkable.type).iterator(); ArrayList<Annotation> rm = new ArrayList<>(); while(iter.hasNext()){ NEMarkable m = (NEMarkable) iter.next(); if(m.getCoveredText().equalsIgnoreCase("history of")){ rm.add(m); } } for(Annotation a: rm){ a.removeFromIndexes(); } }
private void removeAnnotations(JCas jcas, int type) { FSIterator<Annotation> itr = jcas.getJFSIndexRepository().getAnnotationIndex(type).iterator(); List<Annotation> toRemove = new ArrayList<Annotation>(); while (itr.hasNext()) { Annotation annotation = itr.next(); toRemove.add(annotation); } for (Annotation anno : toRemove) { anno.removeFromIndexes(); } }
private void removeAnnotations(JCas jcas, int type) { FSIterator<Annotation> itr = jcas.getJFSIndexRepository().getAnnotationIndex(type).iterator(); List<Annotation> toRemove = new ArrayList<Annotation>(); while (itr.hasNext()) { Annotation annotation = itr.next(); toRemove.add(annotation); } for (Annotation anno : toRemove) { anno.removeFromIndexes(); } }
public void findNAddMatches(JCas jcas, Class evidenceTypeClass, String evidenceTypeShortName) { FSIndex annoIndex = jcas.getAnnotationIndex(evidenceTypeClass); FSIterator annoIter = annoIndex.iterator(); ArrayList<Annotation> scheduledRemoval = new ArrayList<>(); ArrayList<Annotation> scheduledSaving = new ArrayList<>(); while (annoIter.hasNext()) { Annotation evidenceAnnotation = (Annotation) annoIter.next(); HashMap<String, AnnotationDefinition> conclusions = findMatches(evidenceAnnotation, evidenceTypeClass, evidenceConceptGetFeatures.get(evidenceTypeShortName), ruleMap.get(evidenceTypeClass), new HashMap<>()); if (conclusions.size() > 0) { if (removeEvidenceConcept) scheduledRemoval.add(evidenceAnnotation); addToScheduledSaving(jcas, evidenceTypeShortName, conclusions, evidenceAnnotation, scheduledSaving); } } for (Annotation annotation : scheduledRemoval) { annotation.removeFromIndexes(); } for (Annotation annotation : scheduledSaving) { annotation.addToIndexes(); } return; }
/** * Checks if the annotation is of the type to be retained. If not, removes * it from the index. Uses helper method isValid(Annotation). */ @Override public void process( JCas jcas ) throws AnalysisEngineProcessException { removeList.clear(); // iterate over source objects in JCas JFSIndexRepository indexes = jcas.getJFSIndexRepository(); FSIterator<Annotation> srcObjItr = indexes.getAnnotationIndex( retainAnnType).iterator(); while (srcObjItr.hasNext()) { Annotation ann = srcObjItr.next(); if ( !isValid( ann ) ) removeList.add(ann); } for (int i = 0; i < removeList.size(); i++) removeList.get(i).removeFromIndexes(); }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { Set<Annotation> toDelete = null; if (deleteSource) { toDelete = new HashSet<Annotation>(); } for (Annotation anno : JCasUtil.select(jcas, sourceClass)) { Annotation newAnnotation = AnnotationFactory.createAnnotation(jcas, anno.getBegin(), anno.getEnd(), targetClass); if (deleteSource) toDelete.add(anno); if (!(targetFeatureName.isEmpty() || targetFeatureValue.isEmpty())) { Feature feature = newAnnotation.getType().getFeatureByBaseName(targetFeatureName); if (feature != null) newAnnotation.setFeatureValueFromString(feature, targetFeatureValue); } } if (deleteSource) { for (Annotation a : toDelete) { a.removeFromIndexes(); } } }
/** * Checks if the annotation is of the type to be retained. If not, removes * it from the index. Uses helper method isValid(Annotation). */ @Override public void process( JCas jcas ) throws AnalysisEngineProcessException { removeList.clear(); // iterate over source objects in JCas JFSIndexRepository indexes = jcas.getJFSIndexRepository(); FSIterator<Annotation> srcObjItr = indexes.getAnnotationIndex( retainAnnType).iterator(); while (srcObjItr.hasNext()) { Annotation ann = srcObjItr.next(); if ( !isValid( ann ) ) removeList.add(ann); } for (int i = 0; i < removeList.size(); i++) removeList.get(i).removeFromIndexes(); }
/** * returns the number of annotations of specified type in the */ public static int countAnnotationsInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); ann.removeFromIndexes(); return annIdx.size(); }
/** * returns the number of annotations of specified type in the */ public static int countAnnotationsInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); ann.removeFromIndexes(); return annIdx.size(); }
/** * For correct behavior, requires types to be listed in TypePriorities so that the subiterator works as expected */ public static FSIterator getAnnotationsIteratorInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); FSIterator<?> itr = annIdx.subiterator(ann); ann.removeFromIndexes(); return itr; }
/** * For correct behavior, requires types to be listed in TypePriorities so that the subiterator works as expected */ public static FSIterator getAnnotationsIteratorInSpan(JCas jcas, int type, int beginSpan, int endSpan) { Annotation ann = new Annotation(jcas, beginSpan, endSpan); ann.addToIndexes(); AnnotationIndex<?> annIdx = jcas.getAnnotationIndex(type); FSIterator<?> itr = annIdx.subiterator(ann); ann.removeFromIndexes(); return itr; }
/** * Because FastNER and FastCNER may have overlapped matches. * * @param intervalTree * @param concept */ private void checkOverlap(IntervalST intervalTree, Annotation concept) { Interval1D interval = new Interval1D(concept.getBegin(), concept.getEnd()); Annotation overlapped = (Annotation) intervalTree.get(interval); if (overlapped != null && (overlapped.getEnd() != concept.getBegin() && concept.getEnd() != overlapped.getBegin())) { if ((overlapped.getEnd() - overlapped.getBegin()) < (concept.getEnd() - concept.getBegin())) { overlapped.removeFromIndexes(); intervalTree.remove(new Interval1D(overlapped.getBegin(), overlapped.getEnd())); intervalTree.put(interval, concept); } else { concept.removeFromIndexes(); } } else { intervalTree.put(interval, concept); } }
/** * Remove an annotation to the JCas index, notifying UimaMonitor of the fact we have done so. * * <p>Relations that refer to the given annotation will also be removed. * * @param annot Annotation(s) to remove */ public void remove(Collection<? extends Annotation> annotations) { for (Annotation annot : annotations) { if (annot instanceof Recordable) { try { addToHistory( annot.getCAS().getJCas(), HistoryEvents.createAdded((Recordable) annot, referrer)); } catch (CASException e) { monitor.error("Unable to add to history on remove", e); } } if (annot instanceof Entity) { for (Relation r : getRelations((Entity) annot)) { monitor.entityRemoved(r.getType().getName()); r.removeFromIndexes(); } } monitor.entityRemoved(annot.getType().getName()); annot.removeFromIndexes(); } }