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


Java CasUtil.getType方法代码示例

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


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

示例1: process

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
    TreeMatcher treeMatcher = new TreeMatcher(this.tree);
    Iterator<Token> iterator = JCasUtil.iterator(jcas, Token.class);
    Type type = CasUtil.getType(jcas.getCas(), this.annotationType);
    while (iterator.hasNext()) {
        Token token = iterator.next();
        String tokenText = token.getCoveredText();
        tokenText = this.textNormalizer.normalize(tokenText);
        treeMatcher.proceed(token.getBegin(), token.getEnd(), tokenText);
        List<TreeMatch> matches = treeMatcher.getMatches();

        for (TreeMatch match : matches) {
            for (EntryMetadata metadata : match.matchedEntries()) {
                annotate(jcas, type, match, metadata);
            }
        }
    }
}
 
开发者ID:tokenmill,项目名称:dictionary-annotator,代码行数:20,代码来源:DictionaryAnnotator.java

示例2: checkForTheSameBoundaries

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
public static void checkForTheSameBoundaries(CAS cas, Class<? extends AnnotationFS> typeClass) {
    Type type = CasUtil.getType(cas, typeClass);
    FSIterator<AnnotationFS> iter = cas.getAnnotationIndex(type).iterator();
    iter.moveToFirst();
    if (!iter.isValid()) {
        return;
    }
    AnnotationOffsetComparator<AnnotationFS> cmp =
            AnnotationOffsetComparator.instance(AnnotationFS.class);
    AnnotationFS lastAnno = iter.get();
    iter.moveToNext();
    while (iter.isValid()) {
        AnnotationFS anno = iter.get();
        if (cmp.compare(anno, lastAnno) == 0) {
            throw new IllegalStateException(String.format(
                    "Annotations %s and %s have the same boundaries",
                    lastAnno, anno));
        }
        iter.moveToNext();
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:22,代码来源:AnnotationOffsetComparator.java

示例3: test

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
@Test
public void test() throws UIMAException, SAXException,
        CpeDescriptorException, IOException {
    for (JCas jCas : new JCasIterable(readerDesc,
            tokenizerSentenceSplitterDesc, unitAnnotatorDesc)) {
        CAS aCas = jCas.getCas();
        Type unitSourceType = CasUtil.getType(aCas, unitTypes.iterator()
                .next());
        Type unitType = aCas.getTypeSystem().getType(
                UnitAnnotator.UNIT_TYPE_NAME);

        int sourceNumber = CasUtil.select(aCas, unitSourceType).size();
        int unitNumber = CasUtil.select(aCas, unitType).size();
        assertTrue(sourceNumber > 0);
        assertThat(unitNumber, equalTo(sourceNumber));
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:18,代码来源:UnitAnnotatorTest.java

示例4: delete

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
@Override
public void delete(AnnotatorState aState, 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, aState.getDocument(),
            aState.getUser().getUsername(), fs));
}
 
开发者ID:webanno,项目名称:webanno,代码行数:20,代码来源:SpanAdapter.java

示例5: getSpan

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
public Serializable getSpan(JCas aJCas, int aBegin, int aEnd, AnnotationFeature aFeature,
        String aLabelValue)
{
    List<Token> tokens = selectOverlapping(aJCas, Token.class, aBegin, aEnd);
    int begin = tokens.get(0).getBegin();
    int end = tokens.get(tokens.size() - 1).getEnd();
    String baseName = StringUtils.substringBeforeLast(getAnnotationTypeName(), CHAIN) + LINK;
    Type linkType = CasUtil.getType(aJCas.getCas(), baseName);
    
    for (AnnotationFS fs : CasUtil.selectCovered(aJCas.getCas(), linkType, begin, end)) {
        if (fs.getBegin() == aBegin && fs.getEnd() == aEnd) {
            return getFeatureValue(aFeature, fs);
        }
    }
    return null;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:17,代码来源:ChainAdapter.java

示例6: getAttachedSpans

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
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;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:19,代码来源:AnnotationDetailEditorPanel.java

示例7: createAnnotation

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
/**
 * A Helper method to add annotation to CAS
 */
private Integer createAnnotation(AnnotatorState aState, CAS aCas, int aBegin, int aEnd)
    throws AnnotationException
{
    // If stacking is not allowed and there already is an annotation, then return the address
    // of the existing annotation.
    Type type = CasUtil.getType(aCas, getAnnotationTypeName());
    for (AnnotationFS fs : CasUtil.selectCovered(aCas, type, aBegin, aEnd)) {
        if (fs.getBegin() == aBegin && fs.getEnd() == aEnd) {
            if (!allowStacking) {
                return getAddr(fs);
            }
        }
    }
    
    AnnotationFS newAnnotation = aCas.createAnnotation(type, aBegin, aEnd);
    
    // If if the layer attaches to a feature, then set the attach-feature to the newly
    // created annotation.
    if (getAttachFeatureName() != null) {
        Type theType = CasUtil.getType(aCas, getAttachTypeName());
        Feature attachFeature = theType.getFeatureByBaseName(getAttachFeatureName());
        if (CasUtil.selectCovered(aCas, theType, aBegin, aEnd).isEmpty()) {
            throw new AnnotationException("No annotation of type [" + getAttachTypeName()
                    + "] to attach to at location [" + aBegin + "-" + aEnd + "].");
        }
        CasUtil.selectCovered(aCas, theType, aBegin, aEnd).get(0)
                .setFeatureValue(attachFeature, newAnnotation);
    }
    
    aCas.addFsToIndexes(newAnnotation);
    
    publishEvent(new SpanCreatedEvent(this, aState.getDocument(),
            aState.getUser().getUsername(), newAnnotation));
    
    return getAddr(newAnnotation);
}
 
开发者ID:webanno,项目名称:webanno,代码行数:40,代码来源:SpanAdapter.java

示例8: 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

示例9: getLayerAndFeature

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
private int getLayerAndFeature(JCas aJcas, int columns, Map<Type, Set<Feature>> spanLayers,
        Map<Type, Type> relationayers, String line)
    throws IOException
{
    StringTokenizer headerTk = new StringTokenizer(line, "#");
    while (headerTk.hasMoreTokens()) {
        String layerNames = headerTk.nextToken().trim();
        StringTokenizer layerTk = new StringTokenizer(layerNames, "|");

        Set<Feature> features = new LinkedHashSet<>();
        String layerName = layerTk.nextToken().trim();

        Iterator<Type> types = aJcas.getTypeSystem().getTypeIterator();
        boolean layerExists = false;
        while (types.hasNext()) {

            if (types.next().getName().equals(layerName)) {
                layerExists = true;
                break;
            }
        }
        if (!layerExists) {
            throw new IOException(fileName + " This is not a valid TSV File. The layer "
                    + layerName + " is not created in the project.");
        }
        Type layer = CasUtil.getType(aJcas.getCas(), layerName);

        while (layerTk.hasMoreTokens()) {
            String ft = layerTk.nextToken().trim();
            if (ft.startsWith("AttachTo=")) {
                Type attachLayer = CasUtil.getType(aJcas.getCas(), ft.substring(9));
                relationayers.put(layer, attachLayer);
                columns++;
                continue;
            }
            Feature feature = layer.getFeatureByBaseName(ft);
            if (feature == null) {
                throw new IOException(fileName + " This is not a valid TSV File. The feature "
                        + ft + " is not created for the layer " + layerName);
            }
            features.add(feature);
            columns++;
        }
        spanLayers.put(layer, features);
    }
    return columns;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:48,代码来源:WebannoTsv2Reader.java

示例10: getAnnotationType

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
@Override
public Type getAnnotationType(CAS cas)
{
    return CasUtil.getType(cas, getAnnotationTypeName());
}
 
开发者ID:webanno,项目名称:webanno,代码行数:6,代码来源:SpanAdapter.java

示例11: getAnnotationType

import org.apache.uima.fit.util.CasUtil; //导入方法依赖的package包/类
@Override
public Type getAnnotationType(CAS cas)
{
    return CasUtil.getType(cas, annotationTypeName);
}
 
开发者ID:webanno,项目名称:webanno,代码行数:6,代码来源:ChainAdapter.java

示例12: 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.getType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。