@SuppressWarnings("PMD.AvoidCatchingThrowable")
public T perform() throws TaskExecutionException {
Preconditions.checkState(algorithm != null, "no algorithm specified");
Preconditions.checkState(inputData != null, "no input data specified");
Preconditions.checkState(action != null, "no action specified");
LogContext context = new LogContext();
try {
context.put("lenskit.eval.command.class", getName());
context.put("lenskit.eval.command.name", getName());
context.put("lenskit.eval.algorithm.name", algorithm.getName());
// TODO Support serializing the recommender
LenskitRecommender rec;
StopWatch timer = new StopWatch();
timer.start();
try {
logger.info("{}: building recommender {}", getName(), algorithm.getName());
LenskitConfiguration config = new LenskitConfiguration();
inputData.configure(config);
rec = algorithm.buildRecommender(config);
} catch (RecommenderBuildException e) {
throw new TaskExecutionException(getName() + ": error building recommender", e);
}
timer.stop();
logger.info("{}: trained in {}", getName(), timer);
return action.apply(rec);
} finally {
context.finish();
}
}