fr.boreal.backward_chaining.evaluators.DefaultRewritingFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of integraal-backward-chaining Show documentation
Show all versions of integraal-backward-chaining Show documentation
InteGraal has been designed in a modular way, in order to facilitate
software reuse and extension.
It should make it easy to test new scenarios and techniques, in
particular by combining algorithms.
The main features of Graal are currently the following:
(1) internal storage to store data by using a SQL or RDF representation
(Postgres, MySQL, HSQL, SQLite, Remote SPARQL endpoints, Local in-memory
triplestores) as well as a native in-memory representation
(2) data-integration capabilities for exploiting federated heterogeneous
data-sources through mappings able to target systems such as SQL, RDF,
and black-box (e.g. Web-APIs)
(3) algorithms for query-answering over heterogeneous and federated data
based on query rewriting and/or forward chaining (or chase)
package fr.boreal.backward_chaining.evaluators;
import java.util.Optional;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.boreal.backward_chaining.api.BackwardChainingAlgorithm;
import fr.boreal.backward_chaining.pure.PureRewriter;
import fr.boreal.model.query.api.FOQuery;
import fr.boreal.model.query.impl.UnionFOQuery;
/**
* 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 =
switch (rewritingInput.query()) {
case FOQuery> q -> algorithm.rewrite(q, rewritingInput.rules());
case UnionFOQuery q-> algorithm.rewrite(q, rewritingInput.rules());
default -> throw new IllegalArgumentException("Unsupported Query Type: " + rewritingInput.query());
}
;
return new RewritingOutput(rewritingInput.query(), rewritings, Optional.empty());
}
}