Java Code Examples for org.apache.uima.jcas.tcas.Annotation#removeFromIndexes()

The following examples show how to use org.apache.uima.jcas.tcas.Annotation#removeFromIndexes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UimaSupport.java    From baleen with Apache License 2.0 6 votes vote down vote up
/**
 * 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 annotations 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();
  }
}
 
Example 2
Source File: SkipSomePosAnnotator2.java    From bluima with Apache License 2.0 6 votes vote down vote up
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {

	for (Token t : select(jCas, Token.class)) {

		// filter by POS
		String pos = t.getPos();
		if (pos == null)
			pos = "UNKNOWN";
		if (SKIP_POS.contains(pos)) {
			for (Annotation a : selectCovered(jCas, Annotation.class,
			        t.getBegin(), t.getEnd())) {
				if (BlueCasUtil.haveSameBeginEnd(t, a)
				        && BIO_ANNOTATIONS.contains(a.getClass()))
					a.removeFromIndexes(jCas);
			}
		}
	}
}
 
Example 3
Source File: NerMicroservice.java    From newsleak with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Remove unlikely annotation.
 *
 * @param annotations
 *            removal candidates
 */
private void cleanAnnotation(Collection<? extends Annotation> annotations) {
	for (Annotation a : annotations) {
		// less than two letters
		String ne = a.getCoveredText();
		if (ne.replaceAll("[^\\p{L}]", "").length() < 2) {
			log.log(Level.FINEST, "Removing Named Entity: " + ne);
			a.removeFromIndexes();
		}
	}
}
 
Example 4
Source File: RemoveAnnotationsAnnotator.java    From bluima with Apache License 2.0 5 votes vote down vote up
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {

    // 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();
    }
}
 
Example 5
Source File: FilterIfNotRodent.java    From bluima with Apache License 2.0 5 votes vote down vote up
@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();
        }
    }
}
 
Example 6
Source File: AnnotOverlapFilter.java    From bluima with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {

    //First, one use java reflection to check the existence of the given
    //annotation's classes.
    Class<? extends Annotation> protectedAnnotationClass;
    List<Class<? extends Annotation>> filteredAnnotationClasses = new LinkedList<Class<? extends Annotation>>();

    try {

        protectedAnnotationClass = (Class<? extends Annotation>) Class
                .forName(protectedAnnotationClassName);
        for (String filteredAnnotationClassName : filteredAnnotationsClassNames) {
            filteredAnnotationClasses
                    .add((Class<? extends Annotation>) Class
                            .forName(filteredAnnotationClassName));
        }

    } catch (ClassNotFoundException e) {
        throw new AnalysisEngineProcessException(e);
    }

    //Then, one simply go through all pairs of the existing annotations
    //verifying if they overlap (distance = -1)
    List<Annotation> toDelete = new LinkedList<Annotation>();
    for (Annotation protectedOccurrence : select(jCas,
            protectedAnnotationClass)) {

        for (Class<? extends Annotation> filteredAnnotationClass : filteredAnnotationClasses) {
            for (Annotation filteredAnnotOccurrence : select(jCas,
                    filteredAnnotationClass)) {
                boolean overlap = BlueCasUtil.distance(protectedOccurrence,
                        filteredAnnotOccurrence) == -1;
                if (overlap) {
                    toDelete.add(protectedOccurrence);
                }
            }
        }

    }

    for (Annotation annot : toDelete) {
        annot.removeFromIndexes();
    }
}