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


Java CasUtil.select方法代码示例

本文整理汇总了Java中org.apache.uima.fit.util.CasUtil.select方法的典型用法代码示例。如果您正苦于以下问题:Java CasUtil.select方法的具体用法?Java CasUtil.select怎么用?Java CasUtil.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.uima.fit.util.CasUtil的用法示例。


在下文中一共展示了CasUtil.select方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
@Override
public void process(CAS cas) throws AnalysisEngineProcessException {
    String docUriStr = DocumentUtils.getDocumentUri(cas);
    if (docUriStr == null) {
        throw new IllegalStateException("Can't extract document URI");
    }
    Path docUriPath = IoUtils.extractPathFromURI(docUriStr);
    if (docUriPath.isAbsolute()) {
        docUriPath = Paths.get("/").relativize(docUriPath);
    }
    Path outputPath = outputDir.resolve(docUriPath);
    outputPath = IoUtils.addExtension(outputPath, outputFileSuffix);
    try (PrintWriter out = IoUtils.openPrintWriter(outputPath.toFile())) {
        for (AnnotationFS anno : CasUtil.select(cas, targetType)) {
            String text = anno.getCoveredText();
            text = StringUtils.replaceChars(text, "\r\n", "  ");
            out.println(text);
        }
    } catch (IOException e) {
        throw new AnalysisEngineProcessException(e);
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:23,代码来源:AnnotationPerLineWriter.java

示例2: test

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
@Test
public void test() throws UIMAException, IOException {
    SetMultimap<String, String> unitsByClass = HashMultimap.create();
    for (JCas jCas : new JCasIterable(reader, tokenizerSentenceSplitter,
            unitAnnotator, unitClassifier)) {
        CAS aCas = jCas.getCas();
        Type unitType = aCas.getTypeSystem().getType(
                UnitAnnotator.UNIT_TYPE_NAME);
        Feature classFeature = unitType
                .getFeatureByBaseName(UnitClassifier.CLASS_FEAT_NAME);
        for (AnnotationFS unitAnnotation : CasUtil.select(aCas, unitType)) {
            if (unitAnnotation.getStringValue(classFeature) != null) {
                unitsByClass.put(
                        unitAnnotation.getStringValue(classFeature),
                        unitAnnotation.getCoveredText());
            }
        }
    }
    assertEquals(
            Sets.newHashSet("Вагнер", "двое", "боевиков", "пособница"),
            unitsByClass.get("ru.kfu.itis.issst.evex.Person"));
    assertEquals(Sets.newHashSet("ЦСКА"),
            unitsByClass.get("ru.kfu.itis.issst.evex.Organization"));
    assertEquals(Sets.newHashSet("штурма", "квартиры"),
            unitsByClass.get("ru.kfu.itis.issst.evex.Weapon"));
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:27,代码来源:UnitClassifierTest.java

示例3: process

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
@Override
public void process(CAS cas) throws AnalysisEngineProcessException {
    List<AnnotationFS> anno2DeleteList = Lists.newLinkedList();
    for (AnnotationFS coveringAnno : CasUtil.select(cas, coveringAnnoType)) {
        anno2DeleteList.addAll(CasUtil.selectCovered(cas, annoToDeleteType, coveringAnno));
    }
    for (AnnotationFS anno : anno2DeleteList) {
        cas.removeFsFromIndexes(anno);
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:11,代码来源:DeleteCoveredAnnotations.java

示例4: process

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
@Override
public void process(CAS aCAS) throws AnalysisEngineProcessException {
    for (AnnotationFS unit : CasUtil.select(aCAS, unitType)) {
        for (Type classType : classTypes) {
            for (AnnotationFS classAnnotation : CasUtil.select(aCAS,
                    classType)) {
                if (isIntersect(unit, classAnnotation)) {
                    unit.setStringValue(classFeature, classType.getName());
                }
            }
        }
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:14,代码来源:UnitClassifier.java

示例5: process

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
@Override
public void process(CAS aCAS) throws AnalysisEngineProcessException {
    for (Type unitSourceType : unitTypes) {
        for (AnnotationFS unitSource : CasUtil.select(aCAS, unitSourceType)) {
            AnnotationFS unit = aCAS.createAnnotation(unitType,
                    unitSource.getBegin(), unitSource.getEnd());
            aCAS.addFsToIndexes(unit);
        }
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:11,代码来源:UnitAnnotator.java

示例6: process

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
@Override
public void process(CAS cas) throws AnalysisEngineProcessException {
    try {
        normFunction = new NormFunction(FSUtils.stringFeaturePathFunc(cas, inputTokenType, normFeaturePathStr));
    } catch (CASException e) {
        throw new AnalysisEngineProcessException(e);
    }
    for (AnnotationFS span : CasUtil.select(cas, boundaryAnnoType)) {
        processSpan(cas, span);
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:12,代码来源:DictionaryAnnotator.java

示例7: setAmbiguity

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
private void setAmbiguity(JCas aJCas)
{
    List<String> spanAndTokenLayers = spanLayers;
    spanAndTokenLayers.add(Token.class.getName());
    for (String l : spanAndTokenLayers) {
        Type type = getType(aJCas.getCas(), l);
        ambigUnits.putIfAbsent(type.getName(), new HashMap<>());
        for (AnnotationFS fs : CasUtil.select(aJCas.getCas(), type)) {
            AnnotationUnit unit = getFirstUnit(fs);
            // multiple token anno
            if (isMultipleTokenAnnotation(fs.getBegin(), fs.getEnd())) {
                SubTokenAnno sta = new SubTokenAnno();
                sta.setBegin(fs.getBegin());
                sta.setEnd(fs.getEnd());
                sta.setText(fs.getCoveredText());
                Set<AnnotationUnit> sus = new LinkedHashSet<>();
                for (AnnotationUnit newUnit : getSubUnits(sta, sus)) {
                    ambigUnits.get(type.getName()).put(newUnit, true);
                }
            }
            // stacked anno
            else if (ambigUnits.get(type.getName()).get(unit) != null) {
                ambigUnits.get(type.getName()).put(unit, true);
            }
            // single or first occurrence of stacked anno
            else {
                ambigUnits.get(type.getName()).put(unit, false);
            }
        }

    }
}
 
开发者ID:webanno,项目名称:webanno,代码行数:33,代码来源:WebannoTsv3Writer.java

示例8: multiLinkWithRoleLabelDifferenceTest

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
@Test
public void multiLinkWithRoleLabelDifferenceTest()
    throws Exception
{
    JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
    DiffUtils.makeLinkHostFS(jcasA, 0, 0, DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));

    JCas jcasB = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
    DiffUtils.makeLinkHostFS(jcasB, 0, 0, DiffUtils.makeLinkFS(jcasB, "slot2", 0, 0));

    Map<String, List<JCas>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(jcasA));
    casByUser.put("user2", asList(jcasB));
    casByUser.put(CURATION_USER, asList(jcasA));

    List<String> entryTypes = asList(DiffUtils.HOST_TYPE);

    SpanDiffAdapter adapter = new SpanDiffAdapter(DiffUtils.HOST_TYPE);
    adapter.addLinkFeature("links", "role", "target");
    List<? extends DiffAdapter> diffAdapters = asList(adapter);

    DiffResult result = CasDiff2.doDiff(entryTypes, diffAdapters,
            LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);

    result.print(System.out);

    JCas mergeCas = MergeCas.reMergeCas(result, getSingleCasByUser(casByUser));

    Type hostType = mergeCas.getTypeSystem().getType(DiffUtils.HOST_TYPE);
    int numHost = CasUtil.select(mergeCas.getCas(), hostType).size();

    assertEquals(1, numHost);
    for (FeatureStructure host : CasUtil.select(mergeCas.getCas(), hostType)) {
        ArrayFS linkFss = (ArrayFS) WebAnnoCasUtil.getFeatureFS(host, "links");
        assertEquals(0, linkFss.toArray().length);
    }

}
 
开发者ID:webanno,项目名称:webanno,代码行数:39,代码来源:MergeCasTest.java

示例9: multiLinkWithRoleTargetDifferenceTest

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
@Test
public void multiLinkWithRoleTargetDifferenceTest()
    throws Exception
{
    JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
    DiffUtils.makeLinkHostFS(jcasA, 0, 0, DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));

    JCas jcasB = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
    DiffUtils.makeLinkHostFS(jcasB, 0, 0, DiffUtils.makeLinkFS(jcasB, "slot1", 10, 10));

    Map<String, List<JCas>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(jcasA));
    casByUser.put("user2", asList(jcasB));

    casByUser.put(CURATION_USER, asList(jcasA));

    List<String> entryTypes = asList(DiffUtils.HOST_TYPE);

    SpanDiffAdapter adapter = new SpanDiffAdapter(DiffUtils.HOST_TYPE);
    adapter.addLinkFeature("links", "role", "target");
    List<? extends DiffAdapter> diffAdapters = asList(adapter);

    DiffResult result = CasDiff2.doDiff(entryTypes, diffAdapters,
            LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);

    result.print(System.out);

    JCas mergeCas = MergeCas.reMergeCas(result, getSingleCasByUser(casByUser));

    Type hostType = mergeCas.getTypeSystem().getType(DiffUtils.HOST_TYPE);
    int numHost = CasUtil.select(mergeCas.getCas(), hostType).size();

    assertEquals(1, numHost);
    for (FeatureStructure host : CasUtil.select(mergeCas.getCas(), hostType)) {
        ArrayFS linkFss = (ArrayFS) WebAnnoCasUtil.getFeatureFS(host, "links");
        assertEquals(0, linkFss.toArray().length);
    }
}
 
开发者ID:webanno,项目名称:webanno,代码行数:39,代码来源:MergeCasTest.java

示例10: getAttachedLinks

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
private Set<AnnotationFS> getAttachedLinks(AnnotationFS aFs, AnnotationLayer aLayer)
{
    CAS cas = aFs.getCAS();
    Set<AnnotationFS> attachedLinks = new HashSet<>();
    TypeAdapter adapter = annotationService.getAdapter(aLayer);
    if (adapter instanceof SpanAdapter) {
        for (AnnotationFeature linkFeature : annotationService
                .listAttachedLinkFeatures(aLayer)) {
            if (MultiValueMode.ARRAY.equals(linkFeature.getMultiValueMode())
                    && LinkMode.WITH_ROLE.equals(linkFeature.getLinkMode())) {
                // Fetch slot hosts that could link to the current FS and check if any of
                // them actually links to the current FS
                Type linkType = CasUtil.getType(cas, linkFeature.getLayer().getName());
                for (AnnotationFS linkFS : CasUtil.select(cas, linkType)) {
                    List<LinkWithRoleModel> links = adapter.getFeatureValue(linkFeature,
                            linkFS);
                    for (int li = 0; li < links.size(); li++) {
                        LinkWithRoleModel link = links.get(li);
                        AnnotationFS linkTarget = selectByAddr(cas, AnnotationFS.class,
                                link.targetAddr);
                        // If the current annotation fills a slot, then add the slot host to
                        // our list of attached links.
                        if (isSame(linkTarget, aFs)) {
                            attachedLinks.add(linkFS);
                        }
                    }
                }
            }
        }
    }
    return attachedLinks;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:33,代码来源:AnnotationDetailEditorPanel.java

示例11: setTokenAnnos

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
private void setTokenAnnos(CAS aCas, Map<Integer, String> aTokenAnnoMap, Type aType,
        Feature aFeature)
{
    LowLevelCAS llCas = aCas.getLowLevelCAS();
    for (AnnotationFS annoFs : CasUtil.select(aCas, aType)) {
        boolean first = true;
        boolean previous = false; // exists previous annotation, place-holed O-_ should be kept
        for (Token token : selectCovered(Token.class, annoFs)) {
            if (annoFs.getBegin() <= token.getBegin() && annoFs.getEnd() >= token.getEnd()) {
                String annotation = annoFs.getFeatureValueAsString(aFeature);
                if (annotation == null) {
                    annotation = aType.getName() + "_";
                }
                if (aTokenAnnoMap.get(llCas.ll_getFSRef(token)) == null) {
                    if (previous) {
                        if (!multipleSpans.contains(aType.getName())) {
                            aTokenAnnoMap.put(llCas.ll_getFSRef(token), annotation);
                        }
                        else {
                            aTokenAnnoMap.put(llCas.ll_getFSRef(token), "O-_|"
                                    + (first ? "B-" : "I-") + annotation);
                            first = false;
                        }
                    }
                    else {
                        if (!multipleSpans.contains(aType.getName())) {
                            aTokenAnnoMap.put(llCas.ll_getFSRef(token), annotation);
                        }
                        else {
                            aTokenAnnoMap.put(llCas.ll_getFSRef(token), (first ? "B-" : "I-")
                                    + annotation);
                            first = false;
                        }
                    }
                }
                else {
                    if (!multipleSpans.contains(aType.getName())) {
                        aTokenAnnoMap.put(llCas.ll_getFSRef(token),
                                aTokenAnnoMap.get(llCas.ll_getFSRef(token)) + "|"
                                        + annotation);
                        previous = true;
                    }
                    else {
                        aTokenAnnoMap.put(llCas.ll_getFSRef(token),
                                aTokenAnnoMap.get(llCas.ll_getFSRef(token)) + "|"
                                        + (first ? "B-" : "I-") + annotation);
                        first = false;
                        previous = true;
                    }
                }

            }
        }
    }
}
 
开发者ID:webanno,项目名称:webanno,代码行数:56,代码来源:WebannoTsv2Writer.java

示例12: setRelationAnnotation

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
private void setRelationAnnotation(JCas aJCas)
{
    for (String l : relationLayers) {
        if (l.equals(Token.class.getName())) {
            continue;
        }
        Map<AnnotationUnit, List<List<String>>> annotationsPertype;
        if (annotationsPerPostion.get(l) == null) {
            annotationsPertype = new HashMap<>();

        }
        else {
            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)) {

                // check if the dependent is
                dependentFeature = feature;
            }
            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();

            AnnotationUnit govUnit = getFirstUnit(
                    getUnit(govFs.getBegin(), govFs.getEnd(), govFs.getCoveredText()));
            if (ambigUnits.get(govType.getName()).get(govUnit) == null) {
                govUnit = getUnit(govFs.getBegin(), govFs.getEnd(), govFs.getCoveredText());
            }

            AnnotationUnit depUnit = getFirstUnit(
                    getUnit(depFs.getBegin(), depFs.getEnd(), depFs.getCoveredText()));
            if (ambigUnits.get(govType.getName()).get(depUnit) == null) {
                depUnit = getUnit(depFs.getBegin(), depFs.getEnd(), depFs.getCoveredText());
            }
            // Since de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency is over
            // Over POS anno which itself attached to Token, we need the POS type here

            if (type.getName().equals(Dependency.class.getName())) {
                govType = aJCas.getCas().getTypeSystem().getType(POS.class.getName());
            }

            int govRef = 0;
            int depRef = 0;

            // For that unit test case only, where annotations are on Tokens.
            // The WebAnno world do not ever process Token as an annotation
            if (!govType.getName().equals(Token.class.getName())
                    && ambigUnits.get(govType.getName()).get(govUnit).equals(true)) {
                govRef = annotaionRefPerType.get(govType).get(govFs);
            }

            if (!govType.getName().equals(Token.class.getName())
                    && ambigUnits.get(govType.getName()).get(depUnit).equals(true)) {
                depRef = annotaionRefPerType.get(govType).get(depFs);
            }

            setRelationAnnoPerFeature(annotationsPertype, type, fs, depUnit, govUnit, govRef,
                    depRef, govType);

        }
        if (annotationsPertype.keySet().size() > 0) {
            annotationsPerPostion.put(l, annotationsPertype);
        }
    }
}
 
开发者ID:webanno,项目名称:webanno,代码行数:77,代码来源:WebannoTsv3Writer.java

示例13: getAttachedRels

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
public Set<AnnotationFS> getAttachedRels(AnnotationFS aFs, AnnotationLayer aLayer)
{
    CAS cas = aFs.getCAS();
    Set<AnnotationFS> toBeDeleted = new HashSet<>();
    for (AnnotationLayer relationLayer : annotationService
        .listAttachedRelationLayers(aLayer)) {
        ArcAdapter relationAdapter = (ArcAdapter) annotationService.getAdapter(relationLayer);
        Type relationType = CasUtil.getType(cas, relationLayer.getName());
        Feature sourceFeature = relationType.getFeatureByBaseName(relationAdapter
            .getSourceFeatureName());
        Feature targetFeature = relationType.getFeatureByBaseName(relationAdapter
            .getTargetFeatureName());

        // This code is already prepared for the day that relations can go between
        // different layers and may have different attach features for the source and
        // target layers.
        Feature relationSourceAttachFeature = null;
        Feature relationTargetAttachFeature = null;
        if (relationAdapter.getAttachFeatureName() != null) {
            relationSourceAttachFeature = sourceFeature.getRange().getFeatureByBaseName(
                relationAdapter.getAttachFeatureName());
            relationTargetAttachFeature = targetFeature.getRange().getFeatureByBaseName(
                relationAdapter.getAttachFeatureName());
        }

        for (AnnotationFS relationFS : CasUtil.select(cas, relationType)) {
            // Here we get the annotations that the relation is pointing to in the UI
            FeatureStructure sourceFS;
            if (relationSourceAttachFeature != null) {
                sourceFS = relationFS.getFeatureValue(sourceFeature).getFeatureValue(
                    relationSourceAttachFeature);
            }
            else {
                sourceFS = relationFS.getFeatureValue(sourceFeature);
            }

            FeatureStructure targetFS;
            if (relationTargetAttachFeature != null) {
                targetFS = relationFS.getFeatureValue(targetFeature).getFeatureValue(
                    relationTargetAttachFeature);
            }
            else {
                targetFS = relationFS.getFeatureValue(targetFeature);
            }

            if (isSame(sourceFS, aFs) || isSame(targetFS, aFs)) {
                toBeDeleted.add(relationFS);
                LOG.debug("Deleted relation [" + getAddr(relationFS) + "] from layer ["
                    + relationLayer.getName() + "]");
            }
        }
    }

    return toBeDeleted;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:56,代码来源:AnnotationDetailEditorPanel.java


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