Search in sources :

Example 1 with AnalysisEngineDescription

use of org.apache.uima.analysis_engine.AnalysisEngineDescription in project dkpro-lab by dkpro.

the class CpeExecutionEngine method run.

@Override
public String run(Task aConfiguration) throws ExecutionException, LifeCycleException {
    if (!(aConfiguration instanceof UimaTask)) {
        throw new ExecutionException("This engine can only execute [" + UimaTask.class.getName() + "]");
    }
    UimaTask configuration = (UimaTask) aConfiguration;
    // Create persistence service for injection into analysis components
    TaskContext ctx = contextFactory.createContext(aConfiguration);
    try {
        ResourceManager resMgr = newDefaultResourceManager();
        // Make sure the descriptor is fully resolved. It will be modified and
        // thus should not be modified again afterwards by UIMA.
        AnalysisEngineDescription analysisDesc = configuration.getAnalysisEngineDescription(ctx);
        analysisDesc.resolveImports(resMgr);
        // Scan components that accept the service and bind it to them
        bindResource(analysisDesc, TaskContext.class, TaskContextProvider.class, TaskContextProvider.PARAM_FACTORY_NAME, contextFactory.getId(), TaskContextProvider.PARAM_CONTEXT_ID, ctx.getId());
        CpeBuilder mgr = new CpeBuilder();
        ctx.message("CPE will be using " + Runtime.getRuntime().availableProcessors() + " parallel threads to optimally utilize your cpu cores");
        mgr.setMaxProcessingUnitThreadCount(Runtime.getRuntime().availableProcessors());
        mgr.setReader(configuration.getCollectionReaderDescription(ctx));
        mgr.setAnalysisEngine(analysisDesc);
        StatusCallbackListenerImpl status = new StatusCallbackListenerImpl(ctx);
        CollectionProcessingEngine engine = mgr.createCpe(status);
        // Now the setup is complete
        ctx.getLifeCycleManager().initialize(ctx, aConfiguration);
        // Start recording
        ctx.getLifeCycleManager().begin(ctx, aConfiguration);
        // Run the experiment
        engine.process();
        try {
            synchronized (status) {
                while (status.isProcessing) {
                    status.wait();
                }
            }
        } catch (InterruptedException e) {
            ctx.message("CPE interrupted.");
        }
        if (status.exceptions.size() > 0) {
            throw status.exceptions.get(0);
        }
        // End recording
        ctx.getLifeCycleManager().complete(ctx, aConfiguration);
        return ctx.getId();
    } catch (LifeCycleException e) {
        ctx.getLifeCycleManager().fail(ctx, aConfiguration, e);
        throw e;
    } catch (Throwable e) {
        ctx.getLifeCycleManager().fail(ctx, aConfiguration, e);
        throw new ExecutionException(e);
    } finally {
        if (ctx != null) {
            ctx.getLifeCycleManager().destroy(ctx, aConfiguration);
        }
    }
}
Also used : TaskContext(org.dkpro.lab.engine.TaskContext) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) ResourceManager(org.apache.uima.resource.ResourceManager) UIMAFramework.newDefaultResourceManager(org.apache.uima.UIMAFramework.newDefaultResourceManager) CollectionProcessingEngine(org.apache.uima.collection.CollectionProcessingEngine) LifeCycleException(org.dkpro.lab.engine.LifeCycleException) UimaTask(org.dkpro.lab.uima.task.UimaTask) ExecutionException(org.dkpro.lab.engine.ExecutionException) CpeBuilder(org.apache.uima.fit.cpe.CpeBuilder)

Example 2 with AnalysisEngineDescription

use of org.apache.uima.analysis_engine.AnalysisEngineDescription in project dkpro-lab by dkpro.

the class SimpleExecutionEngineTest method testInit.

@Test
public void testInit() throws Exception {
    File repo = new File("target/repository");
    FileUtils.deleteDirectory(repo);
    ((FileSystemStorageService) storageService).setStorageRoot(repo);
    assertNotNull(executionService);
    assertNotNull(contextFactory);
    TypeSystemDescription tsd = createTypeSystemDescription(new String[0]);
    AnalysisEngineDescription desc = createEngineDescription(DummyAE.class, tsd);
    DefaultUimaTask cfg = new DefaultUimaTask();
    cfg.setReaderDescription(createReaderDescription(TestReader.class, tsd));
    cfg.setAnalysisEngineDescription(desc);
    TaskExecutionEngine runner = executionService.createEngine(cfg);
    String uuid = runner.run(cfg);
    System.out.println("=== Experiments in repository ===");
    List<TaskContextMetadata> experiments = storageService.getContexts();
    for (TaskContextMetadata e : experiments) {
        System.out.println(e);
    }
    final StringBuilder sb = new StringBuilder();
    storageService.retrieveBinary(uuid, "test", new StreamReader() {

        @Override
        public void read(InputStream aInputStream) throws IOException {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            Util.shoveAndClose(aInputStream, bos);
            sb.append(new String(bos.toByteArray(), "UTF-8"));
        }
    });
    assertEquals("works", sb.toString());
}
Also used : TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) TypeSystemDescriptionFactory.createTypeSystemDescription(org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TaskExecutionEngine(org.dkpro.lab.engine.TaskExecutionEngine) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultUimaTask(org.dkpro.lab.uima.task.impl.DefaultUimaTask) TaskContextMetadata(org.dkpro.lab.task.TaskContextMetadata) StreamReader(org.dkpro.lab.storage.StreamReader) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) File(java.io.File) FileSystemStorageService(org.dkpro.lab.storage.filesystem.FileSystemStorageService) Test(org.junit.Test)

Example 3 with AnalysisEngineDescription

use of org.apache.uima.analysis_engine.AnalysisEngineDescription in project webanno by webanno.

the class Conll2009ReaderWriterTest method test.

@Test
public void test() throws Exception {
    CollectionReaderDescription reader = createReaderDescription(Conll2009Reader.class, Conll2009Reader.PARAM_SOURCE_LOCATION, "src/test/resources/conll/2009", Conll2009Reader.PARAM_PATTERNS, "en-orig.conll");
    AnalysisEngineDescription writer = createEngineDescription(Conll2009Writer.class, Conll2009Writer.PARAM_TARGET_LOCATION, "target/test-output/Conll2009ReaderWriterTest-test", Conll2009Writer.PARAM_FILENAME_EXTENSION, ".conll", Conll2009Writer.PARAM_STRIP_EXTENSION, true);
    runPipeline(reader, writer);
    String reference = FileUtils.readFileToString(new File("src/test/resources/conll/2009/en-ref.conll"), "UTF-8").trim();
    String actual = FileUtils.readFileToString(new File("target/test-output/Conll2009ReaderWriterTest-test/en-orig.conll"), "UTF-8").trim();
    assertTrue(IOUtils.contentEqualsIgnoreEOL(new StringReader(reference), new StringReader(actual)));
}
Also used : CollectionReaderDescription(org.apache.uima.collection.CollectionReaderDescription) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) StringReader(java.io.StringReader) File(java.io.File) Test(org.junit.Test)

Example 4 with AnalysisEngineDescription

use of org.apache.uima.analysis_engine.AnalysisEngineDescription in project webanno by webanno.

the class ConllUReaderWriterTest method roundTrip.

@Test
public void roundTrip() throws Exception {
    CollectionReaderDescription reader = createReaderDescription(ConllUReader.class, ConllUReader.PARAM_SOURCE_LOCATION, "src/test/resources/conll/u", ConllUReader.PARAM_PATTERNS, "conllu-en-orig.conll");
    AnalysisEngineDescription writer = createEngineDescription(ConllUWriter.class, ConllUWriter.PARAM_TARGET_LOCATION, "target/test-output/ConllUReaderWriterTest-roundTrip", ConllUWriter.PARAM_FILENAME_SUFFIX, ".conll", ConllUWriter.PARAM_STRIP_EXTENSION, true);
    runPipeline(reader, writer);
    String reference = FileUtils.readFileToString(new File("src/test/resources/conll/u/conllu-en-ref.conll"), "UTF-8").trim();
    String actual = FileUtils.readFileToString(new File("target/test-output/ConllUReaderWriterTest-roundTrip/conllu-en-orig.conll"), "UTF-8").trim();
    assertTrue(IOUtils.contentEqualsIgnoreEOL(new StringReader(reference), new StringReader(actual)));
}
Also used : CollectionReaderDescription(org.apache.uima.collection.CollectionReaderDescription) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) StringReader(java.io.StringReader) File(java.io.File) Test(org.junit.Test)

Example 5 with AnalysisEngineDescription

use of org.apache.uima.analysis_engine.AnalysisEngineDescription in project webanno by webanno.

the class TcfReaderWriterTest method testRoundtrip.

@Test
public void testRoundtrip() throws Exception {
    CollectionReaderDescription reader = createReaderDescription(TcfReader.class, TcfReader.PARAM_SOURCE_LOCATION, "src/test/resources/", TcfReader.PARAM_PATTERNS, "wlfxb.xml");
    AnalysisEngineDescription writer = createEngineDescription(TcfWriter.class, TcfWriter.PARAM_TARGET_LOCATION, "target/test-output/roundtrip", TcfWriter.PARAM_FILENAME_SUFFIX, ".xml", TcfWriter.PARAM_STRIP_EXTENSION, true);
    runPipeline(reader, writer);
    String expected = contentOf(new File("src/test/resources/wlfxb.xml"), UTF_8);
    String actual = contentOf(new File("target/test-output/roundtrip/wlfxb.xml"), UTF_8);
    assertThat(expected).isXmlEqualTo(actual);
}
Also used : CollectionReaderDescription(org.apache.uima.collection.CollectionReaderDescription) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) File(java.io.File) Test(org.junit.Test)

Aggregations

AnalysisEngineDescription (org.apache.uima.analysis_engine.AnalysisEngineDescription)62 Test (org.junit.Test)32 File (java.io.File)27 CollectionReaderDescription (org.apache.uima.collection.CollectionReaderDescription)25 ArrayList (java.util.ArrayList)22 AnalysisEngine (org.apache.uima.analysis_engine.AnalysisEngine)18 JCas (org.apache.uima.jcas.JCas)16 Feature (org.dkpro.tc.api.features.Feature)13 FeatureTestUtil.assertFeature (org.dkpro.tc.testing.FeatureTestUtil.assertFeature)11 ExternalResourceDescription (org.apache.uima.resource.ExternalResourceDescription)10 AggregateBuilder (org.apache.uima.fit.factory.AggregateBuilder)8 ResourceInitializationException (org.apache.uima.resource.ResourceInitializationException)8 JsonDataWriter (org.dkpro.tc.core.io.JsonDataWriter)8 TextClassificationTarget (org.dkpro.tc.api.type.TextClassificationTarget)7 Gson (com.google.gson.Gson)6 IOException (java.io.IOException)6 Instance (org.dkpro.tc.api.features.Instance)6 OpenNlpPosTagger (de.tudarmstadt.ukp.dkpro.core.opennlp.OpenNlpPosTagger)4 BreakIteratorSegmenter (de.tudarmstadt.ukp.dkpro.core.tokit.BreakIteratorSegmenter)4 CAS (org.apache.uima.cas.CAS)4