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


Java CasUtil类代码示例

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


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

示例1: process

import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
  try{
    JCas deidView = CasUtil.getView(jCas.getCas(), DEID_VIEW_NAME, true).getJCas();

    String text = jCas.getDocumentText();

    String decoderOut = decoder.decodeString(text);

    while(true) {
      Matcher m = xmlPatt.matcher(decoderOut);
      if (!m.find()) {
        break;
      }
      String matchType = m.group(1);
      int matchStart = m.start();
      int matchEnd = m.end();
      decoderOut = decoderOut.substring(0, matchStart) + "[" + matchType + "]" + decoderOut.substring(matchEnd);
    }

    deidView.setDocumentText(decoderOut);
  }catch(Exception e){
    System.err.println("Error trying to run mist!");
    throw new AnalysisEngineProcessException(e);
  }
}
 
开发者ID:tmills,项目名称:ctakes-docker,代码行数:27,代码来源:MistAnalysisEngine.java

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

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

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

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

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

示例7: get

import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
/**
 * Get the {@link org.dkpro.argumentation.types.WebArgumentMetadata} from the JCas.
 *
 * @throws IllegalArgumentException if no {@link DocumentMetaData} exists in the jCas
 */
public static WebArgumentMetadata get(final JCas jCas)
{
    FSIterator<FeatureStructure> iterator = jCas.getCas().getIndexRepository().getAllIndexedFS(
            CasUtil.getType(jCas.getCas(), WebArgumentMetadata.class));

    if (!iterator.hasNext()) {
        throw new IllegalArgumentException(new Throwable("CAS does not contain any "
                + WebArgumentMetadata.class.getName()));
    }

    WebArgumentMetadata result = (WebArgumentMetadata) iterator.next();

    if (iterator.hasNext()) {
        throw new IllegalArgumentException(new Throwable("CAS contains more than one "
                + WebArgumentMetadata.class.getName()));
    }

    return result;
}
 
开发者ID:dkpro,项目名称:dkpro-argumentation,代码行数:25,代码来源:WebArgumentMetadataHelper.java

示例8: setAllRoleAnnosOnPosition

import org.apache.uima.fit.util.CasUtil; //导入依赖的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: simpleCopyToEmptyTest

import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Test
public void simpleCopyToEmptyTest()
    throws Exception
{
    AnnotatorState state = new AnnotatorStateImpl(Mode.CURATION);
    state.setUser(new User());
    
    JCas jcas = JCasFactory.createJCas();
    Type type = jcas.getTypeSystem().getType(POS.class.getTypeName());
    AnnotationFS clickedFs = createPOSAnno(jcas, type, "NN", 0, 0);

    JCas mergeCAs = JCasFactory.createJCas();
    createTokenAnno(mergeCAs, 0, 0);

    MergeCas.addSpanAnnotation(state, annotationSchemaService,
            posLayer, mergeCAs, clickedFs, false);

    assertEquals(1, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 0).size());
}
 
开发者ID:webanno,项目名称:webanno,代码行数:20,代码来源:CopyAnnotationTest.java

示例10: simpleCopyToDiffExistingAnnoWithNoStackingTest

import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Test
public void simpleCopyToDiffExistingAnnoWithNoStackingTest()
    throws Exception
{
    JCas jcas = JCasFactory.createJCas();
    Type type = jcas.getTypeSystem().getType(POS.class.getTypeName());
    AnnotationFS clickedFs = createPOSAnno(jcas, type, "NN", 0, 0);

    JCas mergeCAs = JCasFactory.createJCas();
    AnnotationFS existingFs = mergeCAs.getCas().createAnnotation(type, 0, 0);
    Feature posValue = type.getFeatureByBaseName("PosValue");
    existingFs.setStringValue(posValue, "NE");
    mergeCAs.addFsToIndexes(existingFs);

    MergeCas.addSpanAnnotation(new AnnotatorStateImpl(Mode.CURATION), annotationSchemaService,
            posLayer, mergeCAs, clickedFs, false);

    assertEquals(1, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 0).size());
}
 
开发者ID:webanno,项目名称:webanno,代码行数:20,代码来源:CopyAnnotationTest.java

示例11: simpleCopyToDiffExistingAnnoWithStackingTest

import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Test
public void simpleCopyToDiffExistingAnnoWithStackingTest()
    throws Exception
{
    AnnotatorState state = new AnnotatorStateImpl(Mode.CURATION);
    state.setUser(new User());
    
    posLayer.setAllowStacking(true);

    JCas jcas = JCasFactory.createJCas();
    Type type = jcas.getTypeSystem().getType(POS.class.getTypeName());
    AnnotationFS clickedFs = createPOSAnno(jcas, type, "NN", 0, 0);

    JCas mergeCAs = JCasFactory.createJCas();
    createTokenAnno(mergeCAs, 0, 0);
    AnnotationFS existingFs = mergeCAs.getCas().createAnnotation(type, 0, 0);
    Feature posValue = type.getFeatureByBaseName("PosValue");
    existingFs.setStringValue(posValue, "NE");
    mergeCAs.addFsToIndexes(existingFs);

    MergeCas.addSpanAnnotation(state, annotationSchemaService, posLayer, mergeCAs, clickedFs,
            true);

    assertEquals(2, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 0).size());
}
 
开发者ID:webanno,项目名称:webanno,代码行数:26,代码来源:CopyAnnotationTest.java

示例12: copySpanWithSlotNoStackingTest

import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Test
public void copySpanWithSlotNoStackingTest()
    throws Exception
{
    slotLayer.setAllowStacking(false);
    
    JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem("f1"));
    Type type = jcasA.getTypeSystem().getType(DiffUtils.HOST_TYPE);
    Feature feature = type.getFeatureByBaseName("f1");

    AnnotationFS clickedFs = DiffUtils.makeLinkHostMultiSPanFeatureFS(jcasA, 0, 0, feature, "A",
            DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));

    JCas mergeCAs = JCasFactory
            .createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem("f1"));

    DiffUtils.makeLinkHostMultiSPanFeatureFS(mergeCAs, 0, 0, feature, "C",
            DiffUtils.makeLinkFS(mergeCAs, "slot1", 0, 0));

    MergeCas.addSpanAnnotation(new AnnotatorStateImpl(Mode.CURATION), annotationSchemaService,
            slotLayer, mergeCAs, clickedFs, false);

    assertEquals(1, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 0).size());
}
 
开发者ID:webanno,项目名称:webanno,代码行数:25,代码来源:CopyAnnotationTest.java

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

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

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


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