use of org.dkpro.lab.engine.TaskContext in project dkpro-lab by dkpro.
the class ReportingEngine method run.
@Override
public String run(Task aConfiguration) throws ExecutionException, LifeCycleException {
if (!(aConfiguration instanceof ReportingTask)) {
throw new ExecutionException("This engine can only execute [" + ReportingTask.class.getName() + "]");
}
// Create persistence service for injection into analysis components
TaskContext ctx = null;
try {
ctx = contextFactory.createContext(aConfiguration);
// Now the setup is complete
ctx.getLifeCycleManager().initialize(ctx, aConfiguration);
// Start recording
ctx.getLifeCycleManager().begin(ctx, aConfiguration);
// End recording (here the reports will nbe done)
ctx.getLifeCycleManager().complete(ctx, aConfiguration);
return ctx.getId();
} finally {
if (ctx != null) {
ctx.getLifeCycleManager().destroy(ctx, aConfiguration);
}
}
}
use of org.dkpro.lab.engine.TaskContext in project dkpro-lab by dkpro.
the class BatchTaskEngine method run.
@Override
public String run(Task aConfiguration) throws ExecutionException, LifeCycleException {
if (!(aConfiguration instanceof BatchTask)) {
throw new ExecutionException("This engine can only execute [" + BatchTask.class.getName() + "]");
}
// Create persistence service for injection into analysis components
TaskContext ctx = null;
try {
ctx = contextFactory.createContext(aConfiguration);
// Now the setup is complete
ctx.getLifeCycleManager().initialize(ctx, aConfiguration);
// Start recording
ctx.getLifeCycleManager().begin(ctx, aConfiguration);
try {
BatchTask cfg = (BatchTask) aConfiguration;
ParameterSpace parameterSpace = cfg.getParameterSpace();
// Try to calculate the parameter space size.
int estimatedSize = 1;
for (Dimension<?> d : parameterSpace.getDimensions()) {
if (d instanceof FixedSizeDimension) {
FixedSizeDimension fsd = (FixedSizeDimension) d;
if (fsd.size() > 0) {
estimatedSize *= fsd.size();
}
}
}
// A subtask execution may apply to multiple parameter space coordinates!
Set<String> executedSubtasks = new LinkedHashSet<String>();
ProgressMeter progress = new ProgressMeter(estimatedSize);
for (Map<String, Object> config : parameterSpace) {
if (cfg.getConfiguration() != null) {
for (Entry<String, Object> e : cfg.getConfiguration().entrySet()) {
if (!config.containsKey(e.getKey())) {
config.put(e.getKey(), e.getValue());
}
}
}
log.info("== Running new configuration [" + ctx.getId() + "] ==");
List<String> keys = new ArrayList<String>(config.keySet());
for (String key : keys) {
log.info("[" + key + "]: [" + StringUtils.abbreviateMiddle(Util.toString(config.get(key)), "…", 150) + "]");
}
executeConfiguration(cfg, ctx, config, executedSubtasks);
progress.next();
log.info("Completed configuration " + progress);
}
// Set the subtask property and persist again, so the property is available to
// reports
cfg.setAttribute(SUBTASKS_KEY, executedSubtasks.toString());
cfg.persist(ctx);
} catch (LifeCycleException e) {
ctx.getLifeCycleManager().fail(ctx, aConfiguration, e);
throw e;
} catch (UnresolvedImportException e) {
// HACK - pass unresolved import exceptions up to the outer batch task
ctx.getLifeCycleManager().fail(ctx, aConfiguration, e);
throw e;
} catch (Throwable e) {
ctx.getLifeCycleManager().fail(ctx, aConfiguration, e);
throw new ExecutionException(e);
}
// End recording (here the reports will nbe done)
ctx.getLifeCycleManager().complete(ctx, aConfiguration);
return ctx.getId();
} finally {
if (ctx != null) {
ctx.getLifeCycleManager().destroy(ctx, aConfiguration);
}
}
}
Aggregations