org.apache.uima.jcas.tcas.Annotation.removeFromIndexes()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中org.apache.uima.jcas.tcas.Annotation.removeFromIndexes()方法的一些代码示例,展示了Annotation.removeFromIndexes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Annotation.removeFromIndexes()方法的具体详情如下:
包路径:org.apache.uima.jcas.tcas.Annotation
类名称:Annotation
方法名:removeFromIndexes

Annotation.removeFromIndexes介绍

暂无

代码示例

代码示例来源:origin: org.apache.ctakes/ctakes-core

@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();
    }
  }
}

代码示例来源:origin: apache/ctakes

@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();
    }
  }
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.tc/de.tudarmstadt.ukp.dkpro.tc.core-asl

/**
 * 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();
  }
}

代码示例来源:origin: ch.epfl.bbp.nlp/bluima_commons

@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();
    }
  }
}

代码示例来源:origin: apache/ctakes

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();
  }
}

代码示例来源:origin: de.unistuttgart.ims/uimautil

@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();
  }
}

代码示例来源:origin: org.apache.ctakes/ctakes-coreference

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();
  }
}

代码示例来源:origin: apache/ctakes

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();
  }
}

代码示例来源:origin: apache/ctakes

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();
  }
}

代码示例来源:origin: org.apache.ctakes/ctakes-drug-ner

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();
  }
}

代码示例来源:origin: edu.utah.bmi.nlp/nlp-core

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;
}

代码示例来源:origin: apache/ctakes

/**
 * 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();
}

代码示例来源:origin: de.unistuttgart.ims/uimautil

@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();
    }
  }
}

代码示例来源:origin: org.apache.ctakes/ctakes-core

/**
 * 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();
}

代码示例来源:origin: apache/ctakes

/**
 * 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();
}

代码示例来源:origin: org.apache.ctakes/ctakes-core

/**
 * 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();
}

代码示例来源:origin: apache/ctakes

/**
 * 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;
}

代码示例来源:origin: org.apache.ctakes/ctakes-core

/**
 * 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;
}

代码示例来源:origin: edu.utah.bmi.nlp/nlp-core

/**
 * 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);
  }
}

代码示例来源:origin: dstl/baleen

/**
 * 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();
 }
}

相关文章