当前位置: 首页>>代码示例>>Java>>正文


Java AnnotationFS类代码示例

本文整理汇总了Java中org.apache.uima.cas.text.AnnotationFS的典型用法代码示例。如果您正苦于以下问题:Java AnnotationFS类的具体用法?Java AnnotationFS怎么用?Java AnnotationFS使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AnnotationFS类属于org.apache.uima.cas.text包,在下文中一共展示了AnnotationFS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: annotationToLabel

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
@Override
public DictionaryTerm annotationToLabel(AnnotationFS annotationFS) {
  FeatureStructure conceptsFeatureValue = annotationFS.getFeatureValue(conceptsFeature);
  if (!(conceptsFeatureValue instanceof ArrayFS)) {
    throw new IllegalStateException("Concepts feature structure is not array.");
  }

  ArrayFS conceptsArray = (ArrayFS) conceptsFeatureValue;

  int size = conceptsArray.size();

  List<DictionaryConcept> concepts = new ArrayList<>(size);

  for (int i = 0; i < size; i++) {
    AnnotationFS conceptFeatureStructure = (AnnotationFS) conceptsArray.get(i);
    concepts.add(dictionaryConceptLabelAdapter.annotationToLabel(conceptFeatureStructure));
  }
  return new DictionaryTerm(annotationFS.getBegin(), annotationFS.getEnd(), concepts);
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:20,代码来源:DictionaryTermLabelAdapter.java

示例2: fillAnnotation

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
@Override
protected void fillAnnotation(T label, AnnotationFS annotationFS) {
  List<Span> cueTerms = label.getCueTerms();
  ArrayFS fsArray = cas.createArrayFS(cueTerms.size());
  for (int i = 0; i < cueTerms.size(); i++) {
    Span cueTerm = cueTerms.get(i);

    AnnotationFS cueAnnotation = cas.createAnnotation(cueType, cueTerm.getStartIndex(),
        cueTerm.getEndIndex());

    cas.addFsToIndexes(cueAnnotation);
    fsArray.set(i, cueAnnotation);
  }
  cas.addFsToIndexes(fsArray);
  annotationFS.setFeatureValue(cues, fsArray);
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:17,代码来源:BiomedicusTsLabelsPlugin.java

示例3: annotationToLabel

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
@Override
public T annotationToLabel(AnnotationFS annotationFS) {
  FeatureStructure cuesValue = annotationFS.getFeatureValue(cues);
  if (!(cuesValue instanceof ArrayFS)) {
    throw new IllegalStateException("Cues is not ArrayFS");
  }
  ArrayFS cuesArray = (ArrayFS) cuesValue;

  int size = cuesArray.size();
  List<Span> cueTerms = new ArrayList<>(size);
  for (int i = 0; i < size; i++) {
    FeatureStructure cueFs = cuesArray.get(i);
    if (!(cueFs instanceof AnnotationFS)) {
      throw new IllegalStateException();
    }
    AnnotationFS cueAnnotation = (AnnotationFS) cueFs;
    Span span = new Span(cueAnnotation.getBegin(),
        cueAnnotation.getEnd());
    cueTerms.add(span);
  }

  return create(annotationFS.getBegin(), annotationFS.getEnd(), cueTerms);
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:24,代码来源:BiomedicusTsLabelsPlugin.java

示例4: process

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
@Override
public void process(CAS aCAS) throws AnalysisEngineProcessException {
  LOGGER.debug("Annotating rtf paragraphs.");
  CAS systemView = aCAS.getView(Views.SYSTEM_VIEW);

  Type newParagraphType = systemView.getTypeSystem()
      .getType("edu.umn.biomedicus.rtfuima.type.NewParagraph");

  Type paragraphType = systemView.getTypeSystem()
      .getType("edu.umn.biomedicus.type.ParagraphAnnotation");

  AnnotationIndex<AnnotationFS> newParagraphIndex = systemView
      .getAnnotationIndex(newParagraphType);
  int start = 0;

  for (AnnotationFS newParagraph : newParagraphIndex) {
    int end = newParagraph.getEnd();
    systemView.addFsToIndexes(
        systemView.createAnnotation(paragraphType, start, end));

    start = end;
  }
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:24,代码来源:ParagraphAnnotator.java

示例5: getAnnotation

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
@Nullable
AnnotationFS getAnnotation(CAS cas, int begin, int end, int value) {
  if (begin < 0) {
    throw new IllegalArgumentException("Begin: " + begin + "before 0.");
  }

  if (end < begin) {
    throw new IllegalArgumentException(
        annotationClassName + " - illegal annotation span at begin: " + begin
            + " end: " + end);
  }

  if (!zeroLengthEmitted && end == begin) {
    return null;
  }

  TypeSystem typeSystem = cas.getTypeSystem();
  Type type = typeSystem.getType(annotationClassName);
  AnnotationFS annotation = cas.createAnnotation(type, begin, end);
  if (valueIncluded) {
    Feature valueFeature = type.getFeatureByBaseName("value");
    annotation.setIntValue(valueFeature, value);
  }
  return annotation;
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:26,代码来源:PropertyCasMapping.java

示例6: controlWordEncountered

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
@Override
public void controlWordEncountered(KeywordAction keywordAction) {
  AnnotationFS annotation;
  int currentTextIndex = sofaBuilder.length();
  String controlWord = keywordAction.getControlWord();

  Type type;
  if (annotationTypeForControlWord.containsKey(controlWord)) {
    type = annotationTypeForControlWord.get(controlWord);
  } else {
    return;
  }
  annotation = destinationView.createAnnotation(type, currentTextIndex,
      currentTextIndex);
  Feature paramFeature = type.getFeatureByBaseName("param");
  if (keywordAction.hasParameter()) {
    annotation.setIntValue(paramFeature, keywordAction.getParameter());
  }
  Feature indexFeature = type.getFeatureByBaseName("index");
  annotation.setIntValue(indexFeature, keywordAction.getBegin());
  Feature knownFeature = type.getFeatureByBaseName("known");
  annotation.setBooleanValue(knownFeature, true);

  destinationView.addFsToIndexes(annotation);
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:26,代码来源:CasOutputDestination.java

示例7: addSpan

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
public int addSpan(JCas aJCas, int aBegin, int aEnd)
    throws MultipleSentenceCoveredException
{
    List<Token> tokens = WebAnnoCasUtil.selectOverlapping(aJCas, Token.class, aBegin, aEnd);

    if (!WebAnnoCasUtil.isSameSentence(aJCas, aBegin, aEnd)) {
        throw new MultipleSentenceCoveredException(
                "Annotation coveres multiple sentences, "
                        + "limit your annotation to single sentence!");
    }

    // update the begin and ends (no sub token selection)
    int begin = tokens.get(0).getBegin();
    int end = tokens.get(tokens.size() - 1).getEnd();

    // Add the link annotation on the span
    AnnotationFS newLink = newLink(aJCas, begin, end);

    // The added link is a new chain on its own - add the chain head FS
    newChain(aJCas, newLink);

    return WebAnnoCasUtil.getAddr(newLink);
}
 
开发者ID:webanno,项目名称:webanno,代码行数:24,代码来源:ChainAdapter.java

示例8: setAllRoleAnnosOnPosition

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
private static void setAllRoleAnnosOnPosition(Map<String, JCas> aJCases,
        Map<String, ArrayFS> slotAnnosPerUser, Set<String> aUsers, FeatureStructure aBaseAnno,
        Feature aFeature)
{
    Type t = aBaseAnno.getType();
    int begin = ((AnnotationFS) aBaseAnno).getBegin();
    int end = ((AnnotationFS) aBaseAnno).getEnd();

    for (String usr : aUsers) {
        for (FeatureStructure baseFS : CasUtil.selectCovered(aJCases.get(usr).getCas(), t,
                begin, end)) {
            // if non eqal stacked annotations with slot feature exists, get
            // the right one
            if (isSameAnno(aBaseAnno, baseFS)) {
                ArrayFS roleFs = (ArrayFS) WebAnnoCasUtil.getFeatureFS(baseFS,
                        aFeature.getShortName());
                slotAnnosPerUser.put(usr, roleFs);
                break;
            }
        }
    }
}
 
开发者ID:webanno,项目名称:webanno,代码行数:23,代码来源:MergeCas.java

示例9: getMultipleAnnotation

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
public Map<Integer, String> getMultipleAnnotation(Sentence sentence, AnnotationFeature aFeature)
    throws CASException
{
    Map<Integer, String> multAnno = new HashMap<>();
    Type type = getType(sentence.getCAS(), getAnnotationTypeName());
    for (AnnotationFS fs : selectCovered(type, sentence)) {
        boolean isBegin = true;
        Feature labelFeature = fs.getType().getFeatureByBaseName(aFeature.getName());
        for (Token token : selectCovered(Token.class, fs)) {
            if (multAnno.get(getAddr(token)) == null) {
                if (isBegin) {
                    multAnno.put(getAddr(token),
                            "B-" + fs.getFeatureValueAsString(labelFeature));
                    isBegin = false;
                }
                else {
                    multAnno.put(getAddr(token),
                            "I-" + fs.getFeatureValueAsString(labelFeature));
                }
            }
        }
    }
    return multAnno;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:25,代码来源:SpanAdapter.java

示例10: modifyRelationAnnotation

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
public static void modifyRelationAnnotation(AnnotationFS aOldFs, AnnotationFS aNewFs,
        JCas aJCas)
{
    Feature[] features = getAllFeatures(aOldFs);
    Type type = aOldFs.getType();
    Feature sourceFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE);
    Feature targetFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET);

    for (Feature f : features) {
        if (isLinkOrBasicFeatures(aOldFs, f)) {
            continue;
        }
        if (f.equals(sourceFeat)) {
            continue;
        }
        else if (f.equals(targetFeat)) {
            continue;
        }

        setFeatureValue(aNewFs, f, getFeatureValue(aOldFs, f));
    }
    aJCas.addFsToIndexes(aNewFs);
}
 
开发者ID:webanno,项目名称:webanno,代码行数:24,代码来源:MergeCas.java

示例11: generateSubPositions

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
@Override
public List<? extends Position> generateSubPositions(int aCasId, AnnotationFS aFs,
        LinkCompareBehavior aLinkCompareBehavior)
{
    List<Position> subPositions = new ArrayList<>();
    
    for (LinkFeatureDecl decl : linkFeatures) {
        Feature linkFeature = aFs.getType().getFeatureByBaseName(decl.name);
        ArrayFS array = (ArrayFS) aFs.getFeatureValue(linkFeature);
        if (array == null) {
            continue;
        }
        for (FeatureStructure linkFS : array.toArray()) {
            String role = linkFS.getStringValue(linkFS.getType().getFeatureByBaseName(
                    decl.roleFeature));
            AnnotationFS target = (AnnotationFS) linkFS.getFeatureValue(linkFS.getType()
                    .getFeatureByBaseName(decl.targetFeature));
            Position pos = getPosition(aCasId, aFs, decl.name, role, target.getBegin(),
                    target.getEnd(), aLinkCompareBehavior);
            subPositions.add(pos);
        }
    }
    
    return subPositions;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:26,代码来源:CasDiff2.java

示例12: setPrimitiveValue

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
private void setPrimitiveValue(TsvColumn aCol, AnnotationFS aAnnotation, String aValue)
{
    // Unescape value - this needs to be done after extracting the disambiguation ID and
    // after determining whether the values is a null value.
    if (!NULL_VALUE.equals(aValue)) {
        String value = Escaping.unescapeValue(aValue);
        Feature feat = aAnnotation.getType()
                .getFeatureByBaseName(aCol.uimaFeature.getShortName());
        
        if (feat == null) {
            throw new IllegalArgumentException(
                    "CAS type [" + aAnnotation.getType() + "] does not have a feature called ["
                            + aCol.uimaFeature.getShortName() + "]");
        }
        
        aAnnotation.setFeatureValueFromString(feat, value);
    }
}
 
开发者ID:webanno,项目名称:webanno,代码行数:19,代码来源:Tsv3XDeserializer.java

示例13: getChainForLink

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
/**
 * Find the chain head for the given link.
 *
 * @param aJCas the CAS.
 * @param aLink the link to search the chain for.
 * @return the chain.
 */
private FeatureStructure getChainForLink(JCas aJCas, AnnotationFS aLink)
{
    Type chainType = getAnnotationType(aJCas.getCas());

    for (FeatureStructure chainFs : selectFS(aJCas.getCas(), chainType)) {
        AnnotationFS linkFs = getFirstLink(chainFs);

        // Now we seek the link within the current chain
        while (linkFs != null) {
            if (WebAnnoCasUtil.isSame(linkFs, aLink)) {
                return chainFs;
            }
            linkFs = getNextLink(linkFs);
        }
    }

    // This should never happen unless the data in the CAS has been created erratically
    throw new IllegalArgumentException("Link not part of any chain");
}
 
开发者ID:webanno,项目名称:webanno,代码行数:27,代码来源:ChainAdapter.java

示例14: mapNote

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
private <BT extends BratType> void mapNote(BratUimaTypeMappingBase<BT> typeMapping,
                                           BratAnnotation<BT> bAnno, AnnotationFS uAnno) {
    BratNoteMapper noteMapper = typeMapping.noteMapper;
    if (noteMapper == null) {
        return;
    }
    Collection<BratNoteAnnotation> notes = bratContainer.getNotes(bAnno);
    for (BratNoteAnnotation note : notes) {
        try {
            noteMapper.parseNote(uAnno, note.getContent());
        } catch (Exception e) {
            throw new IllegalStateException(String.format(
                    "Can't parse note %s in document %s", note, currentDocName));
        }
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:17,代码来源:BratCollectionReader.java

示例15: getOrCreateRelationAnnotation

import org.apache.uima.cas.text.AnnotationFS; //导入依赖的package包/类
private AnnotationFS getOrCreateRelationAnnotation(TsvColumn aCol, TsvUnit aUnit,
        int aStackingIndex, String aDisambiguationInfo)
{
    // Check if we have seen the same annotation already in the current unit but in another
    // column.
    AnnotationFS annotation = aUnit.getUimaAnnotation(aCol.uimaType, aStackingIndex);

    // If not, then we have to create one
    if (annotation == null) {
        annotation = aUnit.getDocument().getJCas().getCas().createAnnotation(aCol.uimaType,
                aUnit.getBegin(), aUnit.getEnd());
        aUnit.addUimaAnnotation(annotation);
    }

    return annotation;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:17,代码来源:Tsv3XDeserializer.java


注:本文中的org.apache.uima.cas.text.AnnotationFS类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。