org.apache.uima.cas.text.AnnotationIndex.iterator()方法的使用及代码示例

x33g5p2x  于11个月前 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(29)

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

AnnotationIndex.iterator介绍

[英]Return an iterator over annotations that can be constrained to be unambiguous.

A disambiguated iterator is defined as follows. The first annotation returned is the same as would be returned by the corresponding ambiguous iterator. If the unambiguous iterator has returned a previously, it will next return the smallest b s.t. a < b and a.getEnd() <= b.getBegin(). In other words, the b annotation's start will be large enough to not overlap the span of a.

An unambiguous iterator makes a snapshot copy of the index containing just the disambiguated items, and iterates over that. It doesn't check for concurrent index modifications (the ambiguous iterator does check for this).
[中]在可以约束为明确的注释上返回迭代器。
消歧迭代器的定义如下。返回的第一个注释与相应的不明确迭代器返回的注释相同。如果明确的迭代器先前已返回a,那么它将接下来返回最小的bs.t.a<b和a.getEnd()<=b.getBegin()。换句话说,b注释的开始将足够大,不会与a的跨度重叠。
明确的迭代器生成索引的快照副本,其中只包含消除歧义的项,并对其进行迭代。它不检查并发索引修改(不明确的迭代器会检查这一点)。

代码示例

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

public void process(CAS cas) {

  FSIterator<AnnotationFS> tokenAnnotations = cas.getAnnotationIndex(mTokenType).iterator();
  List<String> tokensList = new ArrayList<>();

  while (tokenAnnotations.hasNext()) {
   tokensList.add(tokenAnnotations.next().getCoveredText());
  }

  double[] result =
    mCategorizer.categorize(tokensList.toArray(new String[tokensList.size()]));

  String bestCategory = mCategorizer.getBestCategory(result);

  setBestCategory(cas, bestCategory);
 }
}

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

/**
 * Create a new combo iterator.
 *
 * @param cas
 *          The CAS we're operating on.
 * @param upper
 *          The type of the upper iterator, e.g., sentence.
 * @param lower
 *          The type of the lower iterator, e.g., token.
 */
public AnnotationComboIterator(CAS cas, Type upper, Type lower) {
 this.upperIt = cas.getAnnotationIndex(upper).iterator();
 this.lowerIt = cas.getAnnotationIndex(lower).iterator();
 this.upperIt.moveToFirst();
 this.lowerIt.moveToFirst();
 if (this.upperIt.isValid()) {
  final AnnotationFS upperFS = this.upperIt.get();
  this.upperBegin = upperFS.getBegin();
  this.upperEnd = upperFS.getEnd();
 } else {
  this.nextLowerChecked = true;
 }
}

代码示例来源:origin: edu.cmu.lti.oaqa.cse/cse-framework

public static Annotation getAnnotation(JCas jcas, int typeID) {
 AnnotationIndex<Annotation> index = jcas.getAnnotationIndex(typeID);
 Iterator<Annotation> it = index.iterator();
 Annotation annotation = null;
 if (it.hasNext()) {
  annotation = it.next();
 }
 return annotation;
}

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

private FSIterator<Annotation> getAllAnnotations(JCas jcas, int type) {
JFSIndexRepository indexes = jcas.getJFSIndexRepository();
FSIterator<Annotation> annotationsIter = indexes.getAnnotationIndex(type).iterator();
  //	while (segmentItr.hasNext()) {
  //	}
return annotationsIter;
}

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

/**
* {@inheritDoc}
*/
@Override
public Iterator<Annotation> getLookupWindowIterator( final JCas jcas ) throws AnnotatorInitializationException {
 final JFSIndexRepository indexes = jcas.getJFSIndexRepository();
 return indexes.getAnnotationIndex( Sentence.type ).iterator();
}

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

public List<AnnotationFS> getAllofType(Type type) {
 List<AnnotationFS> result = new ArrayList<AnnotationFS>();
 FSIterator<AnnotationFS> iterator = cas.getAnnotationIndex(type).iterator();
 while (iterator.isValid()) {
  FeatureStructure featureStructure = iterator.get();
  result.add((AnnotationFS) featureStructure);
  iterator.moveToNext();
 }
 return result;
}

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

public static ArrayList<BaseToken> selectBaseToken (JCas jcas) {
  ArrayList<BaseToken> ret = new ArrayList<BaseToken>();
  FSIterator<?> iter = jcas.getJFSIndexRepository().getAnnotationIndex(BaseToken.type).iterator();
  while (iter.hasNext())
    ret.add((BaseToken)iter.next());
  java.util.Collections.sort(ret, new AnnotOffsetComparator());
  return ret;
}

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

public static ArrayList<Sentence> selectSentence (JCas jcas) {
  ArrayList<Sentence> ret = new ArrayList<Sentence>();
  FSIterator<Annotation> iter = jcas.getJFSIndexRepository().getAnnotationIndex(Sentence.type).iterator();
  while (iter.hasNext())
    ret.add((Sentence)iter.next());
  java.util.Collections.sort(ret, new AnnotOffsetComparator());
  return ret;
}

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

public AttributeCalculator (JCas jcas) {
  this.jcas = jcas;
  // index the base tokens and NEs by their offsets
  hbs = new Hashtable<Integer, BaseToken>();
  hbe = new Hashtable<Integer, BaseToken>();
  FSIterator iter = jcas.getJFSIndexRepository().getAnnotationIndex(BaseToken.type).iterator();
  while (iter.hasNext()) {
    BaseToken t = (BaseToken) iter.next();
    hbs.put(t.getBegin(), t);
    hbe.put(t.getEnd(), t);
  }
}

代码示例来源:origin: org.apache.opennlp/opennlp-uima

public void process(CAS cas) {

  FSIterator<AnnotationFS> tokenAnnotations = cas.getAnnotationIndex(mTokenType).iterator();
  List<String> tokensList = new ArrayList<>();

  while (tokenAnnotations.hasNext()) {
   tokensList.add(tokenAnnotations.next().getCoveredText());
  }

  double[] result =
    mCategorizer.categorize(tokensList.toArray(new String[tokensList.size()]));

  String bestCategory = mCategorizer.getBestCategory(result);

  setBestCategory(cas, bestCategory);
 }
}

代码示例来源:origin: edu.cmu.lti.oaqa.cse/cse-framework

public static Annotation getFirst(JCas jcas, Type type) {
 AnnotationIndex<Annotation> index = jcas.getAnnotationIndex(type);
 FSIterator<Annotation> iterator = index.iterator();
 if (iterator.hasNext())
  return (Annotation) iterator.next();
 return null;
}

代码示例来源:origin: edu.cmu.lti.oaqa.ecd/uima-ecd

public static Annotation getFirst(JCas jcas, Type type) {
 AnnotationIndex<Annotation> index = jcas.getAnnotationIndex(type);
 FSIterator<Annotation> iterator = index.iterator();
 if (iterator.hasNext())
  return (Annotation) iterator.next();
 return null;
}

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

private void extractAndSaveDocKey(JCas jcas, Document doc) {
  AnnotationIndex<Annotation> idx = jcas
      .getAnnotationIndex(DocKey.typeIndexID);
  FSIterator<Annotation> annoIterator = idx.iterator();
  if (annoIterator.hasNext())
    this.saveDocKey(doc, (DocKey) annoIterator.next());
}

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

@SuppressWarnings("unchecked")
  public static <T extends AnnotationFS> FeaturePathIterator<T> create(CAS aCas, Type aType,
      String aPath)
    throws FeaturePathException
  {
    FSIterator<T> iterator = ((AnnotationIndex<T>) aCas.getAnnotationIndex(aType))
        .iterator();
    final FeaturePathInfo fp = new FeaturePathInfo();
    fp.initialize(aPath);
    return new FeaturePathIterator<T>(iterator, fp);
  }
}

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

private void updateIterators(CAS cas, Type basicType, FilterManager filter,
    AnnotationFS additionalWindow) {
 if (additionalWindow != null) {
  this.basicIt = cas.getAnnotationIndex(basicType).subiterator(additionalWindow);
 } else {
  this.basicIt = cas.getAnnotationIndex(basicType).iterator();
 }
 currentIt = filter.createFilteredIterator(cas, basicType);
}

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

private void updateIterators(CAS cas, Type basicType, FilterManager filter,
    AnnotationFS additionalWindow) {
 if (additionalWindow != null) {
  this.basicIt = cas.getAnnotationIndex(basicType).subiterator(additionalWindow);
 } else {
  this.basicIt = cas.getAnnotationIndex(basicType).iterator();
 }
 currentIt = filter.createFilteredIterator(cas, basicType);
}

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

/** Find the sentence in which an Annotation lives **/
public static Sentence getSentence( JCas jCas, Annotation annot ) {
  FSIterator sentences = jCas.getAnnotationIndex(Sentence.type).iterator();
  while (sentences.hasNext()) {
    Sentence sentence = (Sentence) sentences.next();
    if (doesSubsume(sentence,annot)) {
      return sentence;
    }
  }
  return null;
}

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

/** Returns the first ConllDependencyNode in the CAS w/ same begin and end as the given Annotation **/	
public static ConllDependencyNode getDependencyNode(JCas jCas, Annotation annot) {
  AnnotationIndex nodeIndex = jCas.getAnnotationIndex(ConllDependencyNode.type);
  FSIterator nodeIterator = nodeIndex.iterator();
  while (nodeIterator.hasNext()) {
    ConllDependencyNode node = (ConllDependencyNode) nodeIterator.next();
    if (equalCoverage(annot,node)) {
      return node;
    }
  }
  return null;
}

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

@Override
  public void process(JCas aJCas) throws AnalysisEngineProcessException {
//        removeDoctors(aJCas);
    removeHistoryOf(aJCas);
    FSIterator<Annotation> iter = aJCas.getJFSIndexRepository().getAnnotationIndex(Markable.type).iterator();
    expandToNP(aJCas, FSIteratorToList.convert(iter));
    mergeNP(aJCas);
    elevateAdjectives(aJCas);
    iter = aJCas.getJFSIndexRepository().getAnnotationIndex(Markable.type).iterator();
    rmDup(FSIteratorToList.convert(iter));
  }

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

public String calcmNPHead () {
  Annotation a = m.getContent();
  FSIterator iter = jcas.getJFSIndexRepository().getAnnotationIndex(LookupWindowAnnotation.type).iterator();
  while (iter.hasNext()) {
    LookupWindowAnnotation lwa = (LookupWindowAnnotation) iter.next();
    if (lwa.getBegin()<=a.getBegin() && lwa.getEnd()==a.getEnd())
      return "yes";
  }
  return "no";
}

相关文章

最新文章

更多