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

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

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

AnnotationFS.getCAS介绍

暂无

代码示例

代码示例来源:origin: CLLKazan/UIMA-Ext

/**
 * @param anno           an annotation
 * @param contextCharNum number of characters
 * @return contextCharNum characters after the given annotation
 */
public static String textAfter(AnnotationFS anno, int contextCharNum) {
  Preconditions.checkArgument(contextCharNum >= 0);
  String txt = anno.getCAS().getDocumentText();
  int begin = anno.getEnd();
  int end = Math.min(txt.length(), begin + contextCharNum);
  return txt.substring(begin, end);
}

代码示例来源:origin: de.tudarmstadt.ukp.clarin.webanno/webanno-tsv

/**
 * update a base annotation with slot annotations
 * 
 * @param linkFSesPerAnno
 *            contains list of slot annotations per a base annotation
 * @param aLinkeF
 *            The link slot annotation feature
 */
private void addSlotAnnotations(Map<AnnotationFS, List<FeatureStructure>> linkFSesPerAnno, Feature aLinkeF) {
  for (AnnotationFS anno : linkFSesPerAnno.keySet()) {
    ArrayFS array = anno.getCAS().createArrayFS(linkFSesPerAnno.get(anno).size());
    array.copyFromArray(
        linkFSesPerAnno.get(anno).toArray(new FeatureStructure[linkFSesPerAnno.get(anno).size()]), 0, 0,
        linkFSesPerAnno.get(anno).size());
    anno.setFeatureValue(aLinkeF, array);
    anno.getCAS().addFsToIndexes(anno);
  }
}

代码示例来源:origin: webanno/webanno

/**
 * update a base annotation with slot annotations
 * 
 * @param linkFSesPerAnno
 *            contains list of slot annotations per a base annotation
 * @param aLinkeF
 *            The link slot annotation feature
 */
private void addSlotAnnotations(Map<AnnotationFS, List<FeatureStructure>> linkFSesPerAnno,
    Feature aLinkeF)
{
  for (AnnotationFS anno : linkFSesPerAnno.keySet()) {
    ArrayFS array = anno.getCAS().createArrayFS(linkFSesPerAnno.get(anno).size());
    array.copyFromArray(
        linkFSesPerAnno.get(anno)
            .toArray(new FeatureStructure[linkFSesPerAnno.get(anno).size()]),
        0, 0, linkFSesPerAnno.get(anno).size());
    anno.setFeatureValue(aLinkeF, array);
    anno.getCAS().addFsToIndexes(anno);
  }
}

代码示例来源:origin: CLLKazan/UIMA-Ext

/**
 * @param anno           an annotation
 * @param contextCharNum number of characters
 * @return contextCharNum characters before the given annotation
 */
public static String textBefore(AnnotationFS anno, int contextCharNum) {
  Preconditions.checkArgument(contextCharNum >= 0);
  int begin = Math.max(0, anno.getBegin() - contextCharNum);
  int end = anno.getBegin();
  return anno.getCAS().getDocumentText().substring(begin, end);
}

代码示例来源:origin: de.tudarmstadt.ukp.clarin.webanno/webanno-io-tsv

/**
 * update a base annotation with slot annotations
 * 
 * @param linkFSesPerAnno
 *            contains list of slot annotations per a base annotation
 * @param aLinkeF
 *            The link slot annotation feature
 */
private void addSlotAnnotations(Map<AnnotationFS, List<FeatureStructure>> linkFSesPerAnno,
    Feature aLinkeF)
{
  for (AnnotationFS anno : linkFSesPerAnno.keySet()) {
    ArrayFS array = anno.getCAS().createArrayFS(linkFSesPerAnno.get(anno).size());
    array.copyFromArray(
        linkFSesPerAnno.get(anno)
            .toArray(new FeatureStructure[linkFSesPerAnno.get(anno).size()]),
        0, 0, linkFSesPerAnno.get(anno).size());
    anno.setFeatureValue(aLinkeF, array);
    anno.getCAS().addFsToIndexes(anno);
  }
}

代码示例来源:origin: fr.univ-nantes.julestar/uima-tokens-regex

public Feature getFeature(AnnotationFS annotation) {
  if(f==null) {
    /*
     * TODO Ensure that the Feature will be reset for a new TypeSystem
     */
    f = annotation.getCAS().getTypeSystem().getFeatureByFullName(feature);
  }
  return f;
}

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

private List<NGram> getNGrams(List<T> tokenList, int k)
{
  List<NGram> nGrams = new ArrayList<NGram>();
  int size = tokenList.size();
  for (int i = 0; i < (size + 1 - k); i++) {
    try {
      NGram ngram = new NGram(tokenList.get(i).getCAS().getJCas(), tokenList.get(i)
          .getBegin(), tokenList.get(i + k - 1).getEnd());
      ngram.setText(getTokenText(tokenList, i, i + k - 1));
      nGrams.add(ngram);
    }
    catch (CASException e) {
      throw new IllegalStateException(e);
    }
  }
  return nGrams;
}

代码示例来源:origin: dkpro/dkpro-core

private List<NGram> getNGrams(List<T> tokenList, int k)
{
  List<NGram> nGrams = new ArrayList<NGram>();
  int size = tokenList.size();
  for (int i = 0; i < (size + 1 - k); i++) {
    try {
      NGram ngram = new NGram(tokenList.get(i).getCAS().getJCas(), tokenList.get(i)
          .getBegin(), tokenList.get(i + k - 1).getEnd());
      ngram.setText(getTokenText(tokenList, i, i + k - 1));
      nGrams.add(ngram);
    }
    catch (CASException e) {
      throw new IllegalStateException(e);
    }
  }
  return nGrams;
}

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

/**
 * Return an annotation preceding or following of a given reference annotation.
 * 
 * @param <T>
 *          the JCas type.
 * @param aType
 *          a type.
 * @param annotation
 *          anchor annotation
 * @param index
 *          relative position to access. A negative value selects a preceding annotation while a
 *          positive number selects a following annotation.
 * @return the addressed annotation.
 * @throws IndexOutOfBoundsException
 *           if the relative index points beyond the type index bounds.
 * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
 */
@SuppressWarnings("unchecked")
public static <T extends Annotation> T selectSingleRelative(Class<T> aType,
    AnnotationFS annotation, int index) {
 CAS cas = annotation.getCAS();
 Type t = CasUtil.getType(cas, aType);
 return (T) CasUtil.selectSingleRelative(cas, t, annotation, index);
}

代码示例来源:origin: apache/uima-uimaj

public static FeatureStructure[] getDebugLogicalStructure_SubAnnotations(AnnotationFS fs) {
 // uses sub iterators - may cause apparant skipping of initial annotations due to type
 // priorities.
 return getIndexContents(fs.getCAS().getAnnotationIndex().subiterator(fs)); // built-in
 // annotation
 // index
}

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

/**
   * Returns the (one) annotation of a given type that is aligned with another annotation.
   * 
   * @param type
   *            The annotation type to be looked up.
   * @param annotation
   *            An annotation.
   * @return The annotation aligned with another annotation.
   */
  private AnnotationFS getAnnotation(Type type, AnnotationFS annotation)
  {
    List<AnnotationFS> annotations = CasUtil.selectCovered(annotation.getCAS(), type,
        annotation);
    if (annotations.size() != 1) {
      getLogger().debug(
          "Could not find matching annotation of type " + type + " for annotation: "
              + annotation.getCoveredText());
      return null;
    }

    return annotations.get(0);
  }
}

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

/**
 * Get a list of annotations of the given annotation type located between two annotations. Does
 * not use subiterators and does not respect type priorities. Zero-width annotations what lie on
 * the borders are included in the result, e.g. if the boundary annotations are [1..2] and [2..3]
 * then an annotation [2..2] is returned. If there is a non-zero overlap between the boundary
 * annotations, the result is empty. The method properly handles cases where the second boundary
 * annotations occurs before the first boundary annotation by switching their roles.
 * 
 * @param <T>
 *          the JCas type.
 * @param type
 *          a UIMA type.
 * @param ann1
 *          the first boundary annotation.
 * @param ann2
 *          the second boundary annotation.
 * @return a return value.
 * @see Subiterator
 * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
 */
public static <T extends Annotation> List<T> selectBetween(final Class<T> type,
    AnnotationFS ann1, AnnotationFS ann2) {
 return cast(CasUtil.selectBetween(CasUtil.getType(ann1.getCAS(), type), ann1, ann2));
}

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

/**
 * Convenience method to get a sub-iterator for the specified type.
 * 
 * @param <T>
 *          the iteration type.
 * @param container
 *          the containing annotation.
 * @param type
 *          the type.
 * @param ambiguous
 *          If set to <code>false</code>, resulting iterator will be unambiguous.
 * @param strict
 *          Controls if annotations that overlap to the right are considered in or out.
 * @return A sub-iterator.
 * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
 */
@SuppressWarnings("unchecked")
public static <T extends AnnotationFS> Iterator<T> iterator(AnnotationFS container,
    Class<T> type, boolean ambiguous, boolean strict) {
 CAS cas = container.getCAS();
 return ((AnnotationIndex<T>) cas.getAnnotationIndex(CasUtil.getType(cas, type))).subiterator(
     container, ambiguous, strict);
}

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

/**
 * Returns the n annotations preceding the given annotation
 * 
 * @param <T>
 *          the JCas type.
 * @param aType
 *          a type.
 * @param annotation
 *          anchor annotation
 * @param count
 *          number of annotations to collect
 * @return List of aType annotations preceding anchor annotation
 * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
 */
public static <T extends Annotation> List<T> selectPreceding(Class<T> aType,
    AnnotationFS annotation, int count) {
 Type t = CasUtil.getType(annotation.getCAS(), aType);
 return cast(CasUtil.selectPreceding(annotation.getView(), t, annotation, count));
}

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

/**
 * Returns the n annotations following the given annotation
 * 
 * @param <T>
 *          the JCas type.
 * @param aType
 *          a type.
 * @param annotation
 *          anchor annotation
 * @param count
 *          number of annotations to collect
 * @return List of aType annotations following anchor annotation
 * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
 */
public static <T extends Annotation> List<T> selectFollowing(Class<T> aType,
    AnnotationFS annotation, int count) {
 Type t = CasUtil.getType(annotation.getCAS(), aType);
 return cast(CasUtil.selectFollowing(annotation.getView(), t, annotation, count));
}

代码示例来源:origin: webanno/webanno

private static void makeChainHead(Type aType, AnnotationFS first)
{
  CAS cas = first.getCAS();
  FeatureStructure h = cas.createFS(aType);
  FSUtil.setFeature(h, "first", first);
  cas.addFsToIndexes(h);
}

代码示例来源:origin: webanno/webanno

private Set<AnnotationFS> getAttachedSpans(AnnotationFS aFs, AnnotationLayer aLayer)
{
  CAS cas = aFs.getCAS();
  Set<AnnotationFS> attachedSpans = new HashSet<>();
  TypeAdapter adapter = annotationService.getAdapter(aLayer);
  if (adapter instanceof SpanAdapter && aLayer.getAttachType() != null) {
    Type spanType = CasUtil.getType(cas, aLayer.getAttachType().getName());
    Feature attachFeature = spanType.getFeatureByBaseName(aLayer.getAttachFeature()
      .getName());
    for (AnnotationFS attachedFs : selectAt(cas, spanType, aFs.getBegin(), aFs.getEnd())) {
      if (isSame(attachedFs.getFeatureValue(attachFeature), aFs)) {
        attachedSpans.add(attachedFs);
      }
    }
  }
  return attachedSpans;
}

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

public void annotationAdded(AnnotationFS annotation, RuleMatch creator) {
 CAS cas = annotation.getCAS();
 Type t = cas.getTypeSystem().getType(TYPE);
 Feature featureRule = t.getFeatureByBaseName(FEATURE_RULE);
 Feature featureAnnotation = t.getFeatureByBaseName(FEATURE_ANNOTATION);
 Feature featureScript = t.getFeatureByBaseName(FEATURE_SCRIPT);
 Feature featureId = t.getFeatureByBaseName(FEATURE_ID);
 String ruleString = "provided";
 String ruleScript = "";
 int ruleId = -1;
 if (creator != null) {
  ruleString = verbalizer.verbalize(creator.getRule());
  ruleId = creator.getRule().getId();
  ruleScript = creator.getRule().getParent().getScript().getRootBlock().getNamespace();
 }
 FeatureStructure fs = cas.createFS(t);
 fs.setStringValue(featureRule, ruleString);
 fs.setFeatureValue(featureAnnotation, annotation);
 fs.setIntValue(featureId, ruleId);
 fs.setStringValue(featureScript, ruleScript);
 fsList.add(fs);
}

代码示例来源:origin: de.tudarmstadt.ukp.clarin.webanno/webanno-api-annotation

public static FeatureStructure[] resolve(RelationAdapter aAdapter, AnnotationFS aRelation)
  {
    Type type = aRelation.getType();
    Feature targetFeature = type.getFeatureByBaseName(aAdapter.getTargetFeatureName());
    Feature sourceFeature = type.getFeatureByBaseName(aAdapter.getSourceFeatureName());
    
    FeatureStructure targetFs;
    FeatureStructure sourceFs;
    
    if (aAdapter.getAttachFeatureName() != null) {
      Type spanType = getType(aRelation.getCAS(), aAdapter.getAttachTypeName());
      Feature arcSpanFeature = spanType.getFeatureByBaseName(aAdapter.getAttachFeatureName());
      targetFs = aRelation.getFeatureValue(targetFeature).getFeatureValue(arcSpanFeature);
      sourceFs = aRelation.getFeatureValue(sourceFeature).getFeatureValue(arcSpanFeature);
    }
    else {
      targetFs = aRelation.getFeatureValue(targetFeature);
      sourceFs = aRelation.getFeatureValue(sourceFeature);
    }
    
    return new FeatureStructure[] { sourceFs, targetFs };
  }
}

代码示例来源:origin: webanno/webanno

public static FeatureStructure[] resolve(RelationAdapter aAdapter, AnnotationFS aRelation)
  {
    Type type = aRelation.getType();
    Feature targetFeature = type.getFeatureByBaseName(aAdapter.getTargetFeatureName());
    Feature sourceFeature = type.getFeatureByBaseName(aAdapter.getSourceFeatureName());
    
    FeatureStructure targetFs;
    FeatureStructure sourceFs;
    
    if (aAdapter.getAttachFeatureName() != null) {
      Type spanType = getType(aRelation.getCAS(), aAdapter.getAttachTypeName());
      Feature arcSpanFeature = spanType.getFeatureByBaseName(aAdapter.getAttachFeatureName());
      targetFs = aRelation.getFeatureValue(targetFeature).getFeatureValue(arcSpanFeature);
      sourceFs = aRelation.getFeatureValue(sourceFeature).getFeatureValue(arcSpanFeature);
    }
    else {
      targetFs = aRelation.getFeatureValue(targetFeature);
      sourceFs = aRelation.getFeatureValue(sourceFeature);
    }
    
    return new FeatureStructure[] { sourceFs, targetFs };
  }
}

相关文章