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


Java CasCreationUtils类代码示例

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


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

示例1: indexDocument

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
void indexDocument(Path documentPath) throws NlpTabException {
    try (InputStream inputStream = Files.newInputStream(documentPath)) {
        CAS cas = CasCreationUtils.createCas(typeSystem, null, null, tuningProperties, resourceManager);

        if (systemIndexingSettings.useXCas()) {
            XCASDeserializer.deserialize(inputStream, cas);
        } else {
            XmiCasDeserializer.deserialize(inputStream, cas);
        }

        CasProcessorSettings casProcessorSettings = new CasProcessorSettings(systemIndexingSettings.getIndex(),
                typeSystemInfo, systemIndexFSProcessorDelegateProvider, systemIndexCasViewProcessorDelegate);

        casProcessorFactory.create(casProcessorSettings, cas).process();
    } catch (ResourceInitializationException | IOException | SAXException e) {
        throw new NlpTabException(e);
    }
}
 
开发者ID:nlpie,项目名称:nlptab,代码行数:19,代码来源:SystemIndexing.java

示例2: run

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
private void run() throws ResourceInitializationException, IOException, SAXException {
    Collection<File> inputFiles =
            FileUtils.listFiles(inputDir, FileFilterUtils.suffixFileFilter(".xml"), null);
    if (inputFiles.isEmpty()) {
        return;
    }
    TypeSystemDescription tsd = TypeSystemDescriptionFactory
            .createTypeSystemDescription(typeSystemDescName);
    CAS cas = CasCreationUtils.createCas(tsd, null, null);
    for (File inputFile : inputFiles) {
        AXMLReader.read(inputFile, cas);
        File outFile = getOutputFile(inputFile);
        OutputStream out = FileUtils.openOutputStream(outFile);
        try {
            XmiCasSerializer.serialize(cas, null, out, true, null);
        } finally {
            out.close();
            cas.reset();
        }
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:22,代码来源:AXML2XMI.java

示例3: testOverlap

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Test
public void testOverlap() throws ResourceInitializationException, CASException {
    JCas cas = CasCreationUtils.createCas(
            TypeSystemDescriptionFactory.createTypeSystemDescription(), null, null)
            .getJCas();
    Annotation firstAnno = new Annotation(cas);
    Annotation secondAnno = new Annotation(cas);
    for (Table.Cell<Offsets, Offsets, Integer> testCell : overlapTestTable.cellSet()) {
        firstAnno.setBegin(testCell.getRowKey().getBegin());
        firstAnno.setEnd(testCell.getRowKey().getEnd());
        //
        secondAnno.setBegin(testCell.getColumnKey().getBegin());
        secondAnno.setEnd(testCell.getColumnKey().getEnd());
        //
        if (testCell.getValue() > 0) {
            if (!AnnotationUtils.overlap(firstAnno, secondAnno)) {
                fail(format("Annotations %s and %s must overlap but they do not", firstAnno, secondAnno));
            }
        } else {
            if (AnnotationUtils.overlap(firstAnno, secondAnno)) {
                fail(format("Annotations %s and %s must not overlap but they do", firstAnno, secondAnno));
            }
        }
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:26,代码来源:AnnotationUtilsTest.java

示例4: testOverlapLength

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Test
public void testOverlapLength() throws ResourceInitializationException, CASException {
    JCas cas = CasCreationUtils.createCas(
            TypeSystemDescriptionFactory.createTypeSystemDescription(), null, null)
            .getJCas();
    Annotation firstAnno = new Annotation(cas);
    Annotation secondAnno = new Annotation(cas);
    for (Table.Cell<Offsets, Offsets, Integer> testCell : overlapTestTable.cellSet()) {
        firstAnno.setBegin(testCell.getRowKey().getBegin());
        firstAnno.setEnd(testCell.getRowKey().getEnd());
        //
        secondAnno.setBegin(testCell.getColumnKey().getBegin());
        secondAnno.setEnd(testCell.getColumnKey().getEnd());
        //
        assertEquals("overlapLength",
                AnnotationUtils.overlapLength(firstAnno, secondAnno),
                testCell.getValue().longValue());
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:20,代码来源:AnnotationUtilsTest.java

示例5: setUp

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    daoDesc = ExternalResourceFactory.createExternalResourceDescription(
            XmiFileTreeCorpusDAOResource.class, corpusPathString);
    tsd = CasCreationUtils
            .mergeTypeSystems(Sets.newHashSet(
                    XmiFileTreeCorpusDAO.getTypeSystem(corpusPathString),
                    TypeSystemDescriptionFactory
                            .createTypeSystemDescription(),
                    TokenizerAPI.getTypeSystemDescription(),
                    SentenceSplitterAPI.getTypeSystemDescription()));
    readerDesc = CollectionReaderFactory.createReaderDescription(
            CorpusDAOCollectionReader.class, tsd,
            CorpusDAOCollectionReader.CORPUS_DAO_KEY, daoDesc);
    CAS aCAS = CasCreationUtils.createCas(tsd, null, null, null);
    tokenizerSentenceSplitterDesc = AnalysisEngineFactory
            .createEngineDescription(Unitizer.createTokenizerSentenceSplitterAED());
    unitAnnotatorDesc = AnalysisEngineFactory.createEngineDescription(
            UnitAnnotator.class, UnitAnnotator.PARAM_UNIT_TYPE_NAMES,
            unitTypes);
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:22,代码来源:UnitAnnotatorTest.java

示例6: setUp

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    daoDesc = ExternalResourceFactory.createExternalResourceDescription(
            XmiFileTreeCorpusDAOResource.class, corpusPathString);
    tsd = CasCreationUtils
            .mergeTypeSystems(Sets.newHashSet(
                    XmiFileTreeCorpusDAO.getTypeSystem(corpusPathString),
                    TypeSystemDescriptionFactory
                            .createTypeSystemDescription(),
                    TokenizerAPI.getTypeSystemDescription(),
                    SentenceSplitterAPI.getTypeSystemDescription()));
    reader = CollectionReaderFactory.createReaderDescription(
            CorpusDAOCollectionReader.class, tsd,
            CorpusDAOCollectionReader.CORPUS_DAO_KEY, daoDesc);
    CAS aCAS = CasCreationUtils.createCas(tsd, null, null, null);
    tokenizerSentenceSplitter = Unitizer.createTokenizerSentenceSplitterAED();
    unitAnnotator = AnalysisEngineFactory.createEngineDescription(
            UnitAnnotator.class, UnitAnnotator.PARAM_UNIT_TYPE_NAMES,
            unitTypes);
    unitClassifier = AnalysisEngineFactory.createEngineDescription(
            UnitClassifier.class, UnitClassifier.PARAM_CLASS_TYPE_NAMES,
            classTypes);
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:24,代码来源:UnitClassifierTest.java

示例7: createTypeSystem

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
private TypeSystem createTypeSystem() throws IOException, UIMAException {
    TypeSystemDescription tsDesc = null;
    if (typeSystemDescPaths != null && typeSystemDescPaths.length > 0) {
        tsDesc = createTypeSystemDescriptionFromPath(typeSystemDescPaths);
    }
    if (typeSystemDescNames != null && typeSystemDescNames.length > 0) {
        TypeSystemDescription tsDescFromNames = createTypeSystemDescription(
                typeSystemDescNames);
        if (tsDesc != null) {
            tsDesc = mergeTypeSystems(asList(tsDesc, tsDescFromNames));
        } else {
            tsDesc = tsDescFromNames;
        }
    }
    if (tsDesc == null) {
        log.info("TypeSystemDescription will be created using the UIMAFit discovery");
        tsDesc = TypeSystemDescriptionFactory.createTypeSystemDescription();
    }
    CAS dumbCas = CasCreationUtils.createCas(tsDesc, null, null);
    TypeSystem typeSystem = dumbCas.getTypeSystem();
    // printAllTypes();
    return typeSystem;
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:24,代码来源:TypeSystemInitializer.java

示例8: test1

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Test
@DirtiesContext
public void test1() throws UIMAException {
    Type t1 = ts.getType("test.TestFirst");
    CAS cas = CasCreationUtils.createCas(ts, null, null, null);
    cas.setDocumentText(TXT);
    AnnotationFS s1 = cas.createAnnotation(t1, 0, 10);
    AnnotationFS g1 = cas.createAnnotation(t1, 0, 9);
    evaluator.onDocumentChange("1");
    evaluator.onPartialMatch(g1, s1);
    evaluator.onDocumentChange(null);
    RecognitionMeasures m = evaluator.getMeasures();
    assertEquals(1, m.getMatchedScore(), 0.001f);
    assertEquals(1f / 9, m.getSpuriousScore(), 0.001f);
    assertEquals(0f, m.getMissedScore(), 0.001f);
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:17,代码来源:BestMatchEvaluatorBaseTest.java

示例9: test2

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Test
@DirtiesContext
public void test2() throws UIMAException {
    Type t1 = ts.getType("test.TestFirst");
    CAS cas = CasCreationUtils.createCas(ts, null, null, null);
    cas.setDocumentText(TXT);
    AnnotationFS g1 = cas.createAnnotation(t1, 0, 9);
    AnnotationFS s1 = cas.createAnnotation(t1, 2, 3);
    AnnotationFS s2 = cas.createAnnotation(t1, 0, 18);
    AnnotationFS s3 = cas.createAnnotation(t1, 6, 12);
    evaluator.onDocumentChange("1");
    evaluator.onPartialMatch(g1, s1);
    evaluator.onPartialMatch(g1, s2);
    evaluator.onPartialMatch(g1, s3);
    evaluator.onMissing(g1);
    evaluator.onDocumentChange(null);
    RecognitionMeasures m = evaluator.getMeasures();
    assertEquals(1, m.getMatchedScore(), 0.001f);
    assertEquals(3, m.getSpuriousScore(), 0.001f);
    assertEquals(0, m.getMissedScore(), 0.001f);
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:22,代码来源:BestMatchEvaluatorBaseTest.java

示例10: test3

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Test
@DirtiesContext
public void test3() throws UIMAException {
    // the same as test2 but with exactMatch invoked
    Type t1 = ts.getType("test.TestFirst");
    CAS cas = CasCreationUtils.createCas(ts, null, null, null);
    cas.setDocumentText(TXT);
    AnnotationFS g1 = cas.createAnnotation(t1, 0, 9);
    AnnotationFS s1 = cas.createAnnotation(t1, 0, 9);
    AnnotationFS s2 = cas.createAnnotation(t1, 0, 18);
    AnnotationFS s3 = cas.createAnnotation(t1, 6, 12);
    evaluator.onDocumentChange("1");
    evaluator.onExactMatch(g1, s1);
    evaluator.onPartialMatch(g1, s2);
    evaluator.onPartialMatch(g1, s3);
    evaluator.onDocumentChange(null);
    RecognitionMeasures m = evaluator.getMeasures();
    assertEquals(1f, m.getMatchedScore(), 0.001f);
    assertEquals(2f, m.getSpuriousScore(), 0.001f);
    assertEquals(0f, m.getMissedScore(), 0.001f);
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:22,代码来源:BestMatchEvaluatorBaseTest.java

示例11: testTwoSentencesWithNoSpaceInBetween

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Test
public void testTwoSentencesWithNoSpaceInBetween() throws Exception
{
    TypeSystemDescription global = TypeSystemDescriptionFactory.createTypeSystemDescription();
    TypeSystemDescription local = TypeSystemDescriptionFactory
            .createTypeSystemDescriptionFromPath(
                    "src/test/resources/desc/type/webannoTestTypes.xml");
   
    TypeSystemDescription merged = CasCreationUtils.mergeTypeSystems(asList(global, local));
    
    JCas jcas = JCasFactory.createJCas(merged);
    
    DocumentMetaData.create(jcas).setDocumentId("doc");
    jcas.setDocumentText("onetwo");
    new Token(jcas, 0, 3).addToIndexes();
    new Sentence(jcas, 0, 3).addToIndexes();
    new Token(jcas, 3, 6).addToIndexes();
    new Sentence(jcas, 3, 6).addToIndexes();
    
    writeAndAssertEquals(jcas);
}
 
开发者ID:webanno,项目名称:webanno,代码行数:22,代码来源:WebAnnoTsv3WriterTestBase.java

示例12: makeJCasOneSentence

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
private JCas makeJCasOneSentence() throws UIMAException
{
    TypeSystemDescription global = TypeSystemDescriptionFactory.createTypeSystemDescription();
    TypeSystemDescription local = TypeSystemDescriptionFactory
            .createTypeSystemDescriptionFromPath(
                    "src/test/resources/desc/types/webannoTestTypes.xml");
   
    TypeSystemDescription merged = CasCreationUtils.mergeTypeSystems(asList(global, local));
    
    JCas jcas = JCasFactory.createJCas(merged);
    
    DocumentMetaData.create(jcas).setDocumentId("doc");
    
    TokenBuilder<Token, Sentence> tb = new TokenBuilder<>(Token.class,
            Sentence.class);
    tb.buildTokens(jcas, "This is a test .");
    
    return jcas;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:20,代码来源:ConstraintsGeneratorTest.java

示例13: readWebAnnoTSV

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
public static JCas readWebAnnoTSV(String aPath, TypeSystemDescription aType)
    throws UIMAException, IOException
{
    CollectionReader reader = createReader(WebannoTsv2Reader.class,
            WebannoTsv2Reader.PARAM_SOURCE_LOCATION, "src/test/resources/" + aPath);
    JCas jcas;
    if (aType != null) {
        TypeSystemDescription builtInTypes = TypeSystemDescriptionFactory
                .createTypeSystemDescription();
        List<TypeSystemDescription> allTypes = new ArrayList<>();
        allTypes.add(builtInTypes);
        allTypes.add(aType);
        jcas = JCasFactory.createJCas(CasCreationUtils.mergeTypeSystems(allTypes));
    }
    else {
        jcas = JCasFactory.createJCas();
    }

    reader.getNext(jcas.getCas());

    return jcas;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:23,代码来源:DiffUtils.java

示例14: readXMI

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
public static JCas readXMI(String aPath, TypeSystemDescription aType)
    throws UIMAException, IOException
{
    CollectionReader reader = createReader(XmiReader.class, XmiReader.PARAM_SOURCE_LOCATION,
            "src/test/resources/" + aPath);
    JCas jcas;
    if (aType != null) {
        TypeSystemDescription builtInTypes = TypeSystemDescriptionFactory
                .createTypeSystemDescription();
        List<TypeSystemDescription> allTypes = new ArrayList<>();
        allTypes.add(builtInTypes);
        allTypes.add(aType);
        jcas = JCasFactory.createJCas(CasCreationUtils.mergeTypeSystems(allTypes));
    }
    else {
        jcas = JCasFactory.createJCas();
    }

    reader.getNext(jcas.getCas());

    return jcas;
}
 
开发者ID:webanno,项目名称:webanno,代码行数:23,代码来源:DiffUtils.java

示例15: createMultiLinkWithRoleTestTypeSytem

import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSytem()
    throws Exception
{
    List<TypeSystemDescription> typeSystems = new ArrayList<>();

    TypeSystemDescription tsd = new TypeSystemDescription_impl();

    // Link type
    TypeDescription linkTD = tsd.addType(LINK_TYPE, "", CAS.TYPE_NAME_TOP);
    linkTD.addFeature("role", "", CAS.TYPE_NAME_STRING);
    linkTD.addFeature("target", "", Token.class.getName());

    // Link host
    TypeDescription hostTD = tsd.addType(HOST_TYPE, "", CAS.TYPE_NAME_ANNOTATION);
    hostTD.addFeature("links", "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false);

    typeSystems.add(tsd);
    typeSystems.add(TypeSystemDescriptionFactory.createTypeSystemDescription());

    return CasCreationUtils.mergeTypeSystems(typeSystems);
}
 
开发者ID:webanno,项目名称:webanno,代码行数:22,代码来源:DiffUtils.java


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