Search in sources :

Example 1 with TaskExecutionEngine

use of org.dkpro.lab.engine.TaskExecutionEngine in project dkpro-lab by dkpro.

the class DefaultTaskExecutionService method createEngine.

@Override
public TaskExecutionEngine createEngine(Task aConfiguration) {
    try {
        for (Class<? extends Task> taskClass : map.keySet()) {
            if (taskClass.isAssignableFrom(aConfiguration.getClass())) {
                TaskExecutionEngine engine = map.get(taskClass).newInstance();
                engine.setContextFactory(contextFactory);
                beanFactory.autowireBean(engine);
                return engine;
            }
        }
    } catch (InstantiationException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    throw new IllegalArgumentException("No engine registered for type [" + aConfiguration.getClass().getName() + "]");
}
Also used : TaskExecutionEngine(org.dkpro.lab.engine.TaskExecutionEngine)

Example 2 with TaskExecutionEngine

use of org.dkpro.lab.engine.TaskExecutionEngine 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 TaskExecutionEngine

use of org.dkpro.lab.engine.TaskExecutionEngine in project dkpro-lab by dkpro.

the class UimaAsExecutionEngineTest method testInit.

@Test
public void testInit() throws Exception {
    File repo = new File("target/repository");
    FileUtils.deleteQuietly(repo);
    ((FileSystemStorageService) storageService).setStorageRoot(repo);
    assertNotNull(executionService);
    assertNotNull(contextFactory);
    AnalysisEngineDescription desc = createEngineDescription(DummyAE.class);
    DefaultUimaTask cfg = new DefaultUimaTask();
    cfg.setReaderDescription(createReaderDescription(TestReader.class));
    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 : 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 4 with TaskExecutionEngine

use of org.dkpro.lab.engine.TaskExecutionEngine in project dkpro-lab by dkpro.

the class BatchTaskEngine method runNewExecution.

/**
 * Execute the given task with the given task configuration.
 *
 * @param aContext
 *            the context of the current batch task.
 * @param aTask
 *            the the task whose task to be executed.
 * @param aConfig
 *            the current parameter configuration.
 * @return the context meta data.
 */
protected TaskContextMetadata runNewExecution(TaskContext aContext, Task aTask, Map<String, Object> aConfig, Set<String> aScope) throws ExecutionException, LifeCycleException {
    TaskExecutionService execService = aContext.getExecutionService();
    TaskExecutionEngine engine = execService.createEngine(aTask);
    engine.setContextFactory(new ScopedTaskContextFactory(contextFactory, aConfig, aScope));
    String uuid = engine.run(aTask);
    return aContext.getStorageService().getContext(uuid);
}
Also used : TaskExecutionService(org.dkpro.lab.engine.TaskExecutionService) TaskExecutionEngine(org.dkpro.lab.engine.TaskExecutionEngine)

Aggregations

TaskExecutionEngine (org.dkpro.lab.engine.TaskExecutionEngine)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 AnalysisEngineDescription (org.apache.uima.analysis_engine.AnalysisEngineDescription)2 StreamReader (org.dkpro.lab.storage.StreamReader)2 FileSystemStorageService (org.dkpro.lab.storage.filesystem.FileSystemStorageService)2 TaskContextMetadata (org.dkpro.lab.task.TaskContextMetadata)2 DefaultUimaTask (org.dkpro.lab.uima.task.impl.DefaultUimaTask)2 Test (org.junit.Test)2 TypeSystemDescriptionFactory.createTypeSystemDescription (org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription)1 TypeSystemDescription (org.apache.uima.resource.metadata.TypeSystemDescription)1 TaskExecutionService (org.dkpro.lab.engine.TaskExecutionService)1