Search in sources :

Example 1 with CpeBuilder

use of org.apache.uima.fit.cpe.CpeBuilder 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)

Aggregations

UIMAFramework.newDefaultResourceManager (org.apache.uima.UIMAFramework.newDefaultResourceManager)1 AnalysisEngineDescription (org.apache.uima.analysis_engine.AnalysisEngineDescription)1 CollectionProcessingEngine (org.apache.uima.collection.CollectionProcessingEngine)1 CpeBuilder (org.apache.uima.fit.cpe.CpeBuilder)1 ResourceManager (org.apache.uima.resource.ResourceManager)1 ExecutionException (org.dkpro.lab.engine.ExecutionException)1 LifeCycleException (org.dkpro.lab.engine.LifeCycleException)1 TaskContext (org.dkpro.lab.engine.TaskContext)1 UimaTask (org.dkpro.lab.uima.task.UimaTask)1