fr.boreal.backward_chaining.evaluators.DefaultRewritingFunction Maven / Gradle / Ivy
package fr.boreal.backward_chaining.evaluators;
import fr.boreal.backward_chaining.api.BackwardChainingAlgorithm;
import fr.boreal.backward_chaining.pure.PureRewriter;
import fr.boreal.model.query.impl.UnionFOQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Optional;
import java.util.function.Function;
/**
* A class to encapsulate the function of rewriting a query against a ruleset
* and via a certain algorithm and producing a RewritingResult.
*/
public class DefaultRewritingFunction implements Function {
static final Logger LOG = LoggerFactory.getLogger(DefaultRewritingFunction.class);
@Override
public RewritingOutput apply(RewritingInput rewritingInput) {
LOG.debug("rewriting : {}", rewritingInput);
BackwardChainingAlgorithm algorithm = new PureRewriter(rewritingInput.compilation());
UnionFOQuery rewritings = algorithm.rewrite(rewritingInput.query(), rewritingInput.rules());
return new RewritingOutput(rewritingInput.query(), rewritings, Optional.empty());
}
}