fr.lirmm.boreal.util.evaluator.MultiEvaluator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of integraal-util Show documentation
Show all versions of integraal-util Show documentation
Util objects for integraal
The newest version!
package fr.lirmm.boreal.util.evaluator;
import java.util.Collection;
import java.util.function.BiFunction;
import java.util.function.Function;
import org.slf4j.Logger;
public abstract class MultiEvaluator {
protected static Logger LOG;
private final Collection input;
private final Function batchFunction;
private final Function lazyFunction;
private final Integer timeout;
private final BiFunction outputIfTimeout;
public MultiEvaluator(Collection input, Function function, Integer timeout,
BiFunction outputIfTimeout) {
this.input = input;
this.batchFunction = function;
this.lazyFunction = function;
this.outputIfTimeout = outputIfTimeout;
if (timeout == null) {
this.timeout = EvaluatorConstants.DEFAULT_TIMEOUT;
} else {
this.timeout = timeout;
}
}
public MultiEvaluator(Collection input, Function batchFunction,
Function lazyFunction, Integer timeout,
BiFunction outputIfTimeout) {
this.input = input;
this.batchFunction = batchFunction;
this.lazyFunction = lazyFunction;
this.timeout = timeout;
this.outputIfTimeout = outputIfTimeout;
}
/**
* Evaluates all queries in a batch and returns a list of QueryEvaluationOutput.
*
* @return A list of QueryEvaluationOutput, each containing a query and its
* corresponding iterator of substitutions.
*/
public final Iterable batchEvaluate() {
return new BatchProcessor<>(input, batchFunction, timeout, outputIfTimeout).processBatch();
}
/**
* Provides lazy evaluation for the queries, yielding QueryEvaluationOutput for
* each query.
*
* @return An iterable for lazy evaluation of query results, each as a
* QueryEvaluationOutput.
*/
public final Iterable lazyEvaluate() {
return new LazyIterator<>(input, lazyFunction);
}
}