org.apache.uima.cas.text.AnnotationFS类的使用及代码示例

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

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

AnnotationFS介绍

[英]Interface for Annotation Feature Structures.
[中]注释要素结构的接口。

代码示例

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

.getAnnotationIndex(containerType);
String text = containerAnnotation.getCoveredText();
 sentences[i] = cas.createAnnotation(sentenceType,
   sentPositions[i].getStart() + containerAnnotation.getBegin(),
   sentPositions[i].getEnd() + containerAnnotation.getBegin());
 cas.getIndexRepository().addFS(sentences[i]);
  logger.log(Level.FINER, "\"" + sentences[i].getCoveredText() + "\"");

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

private void addChunkAnnotation(CAS tcas, AnnotationFS[] tokenAnnotations,
                String tag, int start, int end) {
 AnnotationFS chunk = tcas.createAnnotation(mChunkType,
   tokenAnnotations[start].getBegin(), tokenAnnotations[end - 1].getEnd());
 chunk.setStringValue(mChunkFeature, tag);
 tcas.getIndexRepository().addFS(chunk);
}

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

FSIndex<AnnotationFS> tokenAnnotationIndex = tcas.getAnnotationIndex(mTokenType);
 tokens[index] = tokenAnnotation.getCoveredText();
 pos[index++] = tokenAnnotation.getFeatureValueAsString(
   mPosFeature);

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

private boolean isContaining(AnnotationFS annotation, AnnotationFS containing) {
 return (containing.getBegin() <= annotation.getBegin())
  && (containing.getEnd() >= annotation.getEnd());
}

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

public void process(CAS tcas) {
 FSIndex<AnnotationFS> sentenceIndex = tcas.getAnnotationIndex(mNameType);
  String text = nameAnnotation.getCoveredText();
  if (CAS.TYPE_NAME_STRING.equals(mStructureFeature.getRange().getName())) {
   nameAnnotation.setStringValue(mStructureFeature, text);
  } else {
   if (CAS.TYPE_NAME_BYTE.equals(mStructureFeature.getRange().getName())) {
    nameAnnotation.setByteValue(mStructureFeature, number.byteValue());
   } else if (CAS.TYPE_NAME_SHORT.equals(mStructureFeature.getRange()
     .getName())) {
    nameAnnotation.setShortValue(mStructureFeature, number.shortValue());
   } else if (CAS.TYPE_NAME_INTEGER.equals(mStructureFeature.getRange()
     .getName())) {
    nameAnnotation.setIntValue(mStructureFeature, number.intValue());
   } else if (CAS.TYPE_NAME_LONG.equals(mStructureFeature.getRange()
     .getName())) {
    nameAnnotation.setLongValue(mStructureFeature, number.longValue());
   } else if (CAS.TYPE_NAME_FLOAT.equals(mStructureFeature.getRange()
     .getName())) {
    nameAnnotation.setFloatValue(mStructureFeature, number.floatValue());
   } else if (CAS.TYPE_NAME_DOUBLE.equals(mStructureFeature.getRange()
     .getName())) {
    nameAnnotation
      .setDoubleValue(mStructureFeature, number.doubleValue());

代码示例来源:origin: hltfbk/Excitement-Open-Platform

private void processDependency(JCas jcas, Token childToken, BasicConstructionNode parentNode, String relationName, ArrayList<Token> tokenAnnotations, Sentence sentenceAnno) throws AbstractNodeCasException, ParserRunException {			
    // Taken mostly from de.tudarmstadt.ukp.dkpro.core.stanfordnlp.util.StanfordAnnotator.createDependencyAnnotation()
    
    // Known issue in DKPro
    if (relationName.equalsIgnoreCase("AUX")) {
      relationName = "AUX0";
    }

    String dependencyTypeName = DEPPACKAGE + relationName.toUpperCase();
    Type type = jcas.getTypeSystem().getType(dependencyTypeName);
    if (type == null) {
      throw new ParserRunException("Type [" + dependencyTypeName + "] mapped to tag ["
          + relationName + "] is not defined in type system");
    }
    
    Token parentTokenAnno = AbstractNodeCASUtils.nodeToToken(tokenAnnotations, parentNode);
        
    AnnotationFS anno = jcas.getCas().createAnnotation(type, sentenceAnno.getBegin(), sentenceAnno.getEnd());
    anno.setStringValue(type.getFeatureByBaseName("DependencyType"), relationName);
    anno.setFeatureValue(type.getFeatureByBaseName("Governor"), parentTokenAnno);
    anno.setFeatureValue(type.getFeatureByBaseName("Dependent"), childToken);
    jcas.addFsToIndexes(anno);
  }
}

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

public static AnnotationFS makeLinkHostMultiSPanFeatureFS(JCas aJCas, int aBegin, int aEnd,
    Feature aSpanFeature, String aValue, FeatureStructure... aLinks)
{
  Type hostType = aJCas.getTypeSystem().getType(HOST_TYPE);
  AnnotationFS hostA1 = aJCas.getCas().createAnnotation(hostType, aBegin, aEnd);
  hostA1.setFeatureValue(hostType.getFeatureByBaseName("links"),
      FSCollectionFactory.createFSArray(aJCas, asList(aLinks)));
  hostA1.setStringValue(aSpanFeature, aValue);
  aJCas.getCas().addFsToIndexes(hostA1);
  return hostA1;
}

代码示例来源:origin: org.dkpro.tc/dkpro-tc-ml

private void addTCSequenceAnnotation(JCas jcas)
{
  Type type = jcas.getCas().getTypeSystem().getType(nameSequence);
  Collection<AnnotationFS> sequenceAnnotation = CasUtil.select(jcas.getCas(), type);
  for (AnnotationFS seq : sequenceAnnotation) {
    TextClassificationSequence tcs = new TextClassificationSequence(jcas, seq.getBegin(),
        seq.getEnd());
    tcs.addToIndexes();
  }
}

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

/**
 * The individual link annotations are stored in a {@link TreeMap} (chainAnnosPerTye) with chain
 * number and link number references, sorted in an ascending order <br>
 * Iterate over each chain number and link number references and construct the chain.
 */
private void addChainAnnotations(JCas aJCas)
{
  for (Type linkType : chainAnnosPerTyep.keySet()) {
    for (int chainNo : chainAnnosPerTyep.get(linkType).keySet()) {
      Type chainType = aJCas.getCas().getTypeSystem().getType(
          linkType.getName().substring(0, linkType.getName().length() - 4) + CHAIN);
      Feature firstF = chainType.getFeatureByBaseName(FIRST);
      Feature nextF = linkType.getFeatureByBaseName(NEXT);
      FeatureStructure chain = aJCas.getCas().createFS(chainType);
      aJCas.addFsToIndexes(chain);
      AnnotationFS firstFs = chainAnnosPerTyep.get(linkType).get(chainNo).get(1);
      AnnotationFS linkFs = firstFs;
      chain.setFeatureValue(firstF, firstFs);
      for (int i = 2; i <= chainAnnosPerTyep.get(linkType).get(chainNo).size(); i++) {
        linkFs.setFeatureValue(nextF,
            chainAnnosPerTyep.get(linkType).get(chainNo).get(i));
        linkFs = chainAnnosPerTyep.get(linkType).get(chainNo).get(i);
      }
    }
  }
}

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

public static void addSourceDocumentInformation(CAS cas, File each) {
 Type sdiType = cas.getTypeSystem()
     .getType("org.apache.uima.examples.SourceDocumentInformation");
 if (sdiType != null) {
  if (cas.getAnnotationIndex(sdiType).size() == 0) {
   AnnotationFS sdi = cas.createAnnotation(sdiType, cas.getDocumentAnnotation().getBegin(),
       cas.getDocumentAnnotation().getEnd());
   Feature uriFeature = sdiType.getFeatureByBaseName("uri");
   sdi.setStringValue(uriFeature, each.toURI().getPath());
   cas.addFsToIndexes(sdi);
  }
 }
}

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

annotationsPertype = annotationsPerPostion.get(l);
Type type = getType(aJCas.getCas(), l);
Feature dependentFeature = null;
Feature governorFeature = null;
for (Feature feature : type.getFeatures()) {
  if (feature.getShortName().equals(DEPENDENT)) {
  if (feature.getShortName().equals(GOVERNOR)) {
    governorFeature = feature;
for (AnnotationFS fs : CasUtil.select(aJCas.getCas(), type)) {
  AnnotationFS depFs = (AnnotationFS) fs.getFeatureValue(dependentFeature);
  AnnotationFS govFs = (AnnotationFS) fs.getFeatureValue(governorFeature);
  Type govType = govFs.getType();
      getUnit(govFs.getBegin(), govFs.getEnd(), govFs.getCoveredText()));
  if(ambigUnits.get(govType.getName()).get(govUnit)==null){
    govUnit =  getUnit(govFs.getBegin(), govFs.getEnd(), govFs.getCoveredText());
      getUnit(depFs.getBegin(), depFs.getEnd(), depFs.getCoveredText()));
  if(ambigUnits.get(govType.getName()).get(depUnit)==null){
    depUnit =  getUnit(depFs.getBegin(), depFs.getEnd(), depFs.getCoveredText());
  if (type.getName().equals(Dependency.class.getName())){
    govType = aJCas.getCas().getTypeSystem().getType(POS.class.getName());

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

cas.setDocumentText("I listen to lectures by Prof. Gurevych sometimes.");
TypeSystem ts = cas.getTypeSystem();
Type profType = ts.getType("de.tud.Prof");
Feature profNameFeature = profType.getFeatureByBaseName("fullName");
Feature profBossFeature = profType.getFeatureByBaseName("boss");
AnnotationFS proemel = cas.createAnnotation(profType, 0, 0);
proemel.setStringValue(profNameFeature, "Hans Juergen Proeml");
cas.addFsToIndexes(proemel);
AnnotationFS gurevych = cas.createAnnotation(profType, 24, 38);
gurevych.setStringValue(profNameFeature, "Iryna Gurevych");
gurevych.setFeatureValue(profBossFeature, proemel);
cas.addFsToIndexes(gurevych);
  Feature someFeature = gurevych.getType().getFeatureByBaseName(feature);
  if (someFeature.getRange().isPrimitive()) {
    String value = gurevych.getFeatureValueAsString(someFeature);
    System.out.println(value);
    FeatureStructure value = gurevych.getFeatureValue(someFeature);
    System.out.printf("%s (%s)%n", value.getFeatureValueAsString(profNameFeature),
        value.getType());

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

private static List<AnnotationFS> getRelAnnosOnPosition(AnnotationFS aFs,
    AnnotationFS aOriginFs, AnnotationFS aTargetFs, JCas aJcas)
{
  Type type = aFs.getType();
  Feature sourceFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE);
  Feature targetFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET);
  return selectCovered(aJcas.getCas(), type, aFs.getBegin(), aFs.getEnd()).stream()
      .filter(fs -> fs.getFeatureValue(sourceFeat).equals(aOriginFs)
          && fs.getFeatureValue(targetFeat).equals(aTargetFs))
      .collect(Collectors.toList());
}

代码示例来源:origin: inception-project/inception

private List<Annotation> extractAnnotations(List<CAS> aCasses)
  {
    List<Annotation> annotations = new ArrayList<>();

    for (CAS cas : aCasses) {
      Type annotationType = CasUtil.getType(cas, layerName);
      Feature labelFeature = annotationType.getFeatureByBaseName(featureName);

      for (AnnotationFS ann : CasUtil.select(cas, annotationType)) {
        String label = ann.getFeatureValueAsString(labelFeature);
        annotations.add(new Annotation(label, ann.getBegin(), ann.getEnd()));
      }
    }

    return annotations;
  }
// end::extractAnnotations[]

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

private void copyFeatures(AnnotationFS oldFS, FeatureStructure newFS, CAS cas) {
 List<?> features = oldFS.getType().getFeatures();
 Type newType = newFS.getType();
 for (Object object : features) {
  Feature feature = (Feature) object;
  String shortName = feature.getShortName();
  Feature newFeature = newType.getFeatureByBaseName(shortName);
  if (newFeature != null) {
   if (feature.getRange().isPrimitive()) {
    String value = oldFS.getFeatureValueAsString(feature);
    newFS.setFeatureValueFromString(newFeature, value);
   } else {
    FeatureStructure value = oldFS.getFeatureValue(feature);
    newFS.setFeatureValue(newFeature, value);
   }
  }
 }
}

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

private static Stream<AnnotationFS> getMergeFS(AnnotationFS aOldFs, JCas aJCas)
{
  return selectCovered(aJCas.getCas(), aOldFs.getType(), aOldFs.getBegin(), aOldFs.getEnd())
      .stream().filter(fs -> isSameAnno(fs, aOldFs));
}

代码示例来源: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.inception.app/inception-log

public AnnotationDetails(FeatureStructure aFS)
{
  addr = WebAnnoCasUtil.getAddr(aFS);
  type = aFS.getType().getName();
  if (aFS instanceof AnnotationFS) {
    AnnotationFS annoFS = (AnnotationFS) aFS;
    begin = annoFS.getBegin();
    end = annoFS.getEnd();
    text = annoFS.getCoveredText();
  }
  else {
    begin = -1;
    end = -1;
    text = null;
  }
}

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

Stem stemAnnot = new Stem(jcas, fs.getBegin(), fs.getEnd());
stemAnnot.setValue(stemValue);
stemAnnot.addToIndexes(jcas);
Feature feat = fs.getType().getFeatureByBaseName("stem");
if (feat != null && feat.getRange() != null
    && jcas.getTypeSystem().subsumes(feat.getRange(), stemAnnot.getType())) {
  fs.setFeatureValue(feat, stemAnnot);

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

@Override
public void delete(SourceDocument aDocument, String aUsername, JCas aJCas, VID aVid)
{
  AnnotationFS fs = selectByAddr(aJCas, AnnotationFS.class, aVid.getId());
  aJCas.removeFsFromIndexes(fs);
  // delete associated attachFeature
  if (getAttachTypeName() != null) {
    Type theType = CasUtil.getType(aJCas.getCas(), getAttachTypeName());
    Feature attachFeature = theType.getFeatureByBaseName(getAttachFeatureName());
    if (attachFeature != null) {
      CasUtil.selectCovered(aJCas.getCas(), theType, fs.getBegin(), fs.getEnd()).get(0)
          .setFeatureValue(attachFeature, null);
    }
  }
  
  publishEvent(new SpanDeletedEvent(this, aDocument, aUsername, getLayer(), fs));
}

相关文章