Interface QueryEvaluator<Q extends Query, QD extends QueryableData>
- Type Parameters:
Q- The type ofQuerythat the evaluator can evaluateQD- The type ofQueryableDataevaluated by this evaluator
- All Known Subinterfaces:
FOQueryEvaluator<Formula,QD>
- All Known Implementing Classes:
AtomicFOQueryEvaluator, BacktrackEvaluator, DefaultGenericQueryEvaluator, FOQueryEvaluatorWithDBMSDelegation, GenericFOQueryEvaluator, InfAtomicFOQueryEvaluator, IntersectFOQueryConjunctionEvaluator, LegacyBacktrackEvaluator, NegationFOQueryEvaluator, UnfoldingAtomicFOQueryEvaluator, UnionFOQueryEvaluator
public interface QueryEvaluator<Q extends Query, QD extends QueryableData>
A Query evaluator is one possible algorithm to evaluate a
Evaluating a Query means retrieving all the
Query.
Evaluating a Query means retrieving all the
Substitution of the
answer variables from the query with respect to the atoms from the
QueryableData.-
Method Summary
Modifier and TypeMethodDescriptiondefault longcountAnswers(Q query, QD queryableData) Counts answers for the supplied query.default longcountHomomorphism(Q query, QD queryableData) Counts homomorphisms for the supplied query.default Stream<Substitution> Evaluates a query using its answer variables as the projection.default Stream<Substitution> evaluate(Q query, QD queryableData, Substitution preHomomorphism) Evaluates a query while extending a partial answer substitution.evaluate(Q query, QD queryableData, Collection<Variable> variablesThatMustBeMappedToGroundTerms, Substitution preHomomorphism) Evaluates a query against a data source.default booleanexistAnswer(Q query, QD queryableData) Tests whether the query has at least one answer in the data source.default booleanexistAnswer(Q query, QD queryableData, Substitution preHomomorphism) Tests whether the query has at least one answer extending the supplied substitution.default booleanexistHomomorphism(Q query, QD queryableData) Tests whether the query has at least one homomorphism in the data source.default booleanexistHomomorphism(Q query, QD queryableData, Substitution preHomomorphism) Tests whether the query has at least one homomorphism extending the supplied substitution.default Stream<Substitution> homomorphism(Q query, QD queryableData) Enumerates homomorphisms for a query without a pre-existing mapping.default Stream<Substitution> homomorphism(Q query, QD queryableData, Substitution preHomomorphism) Enumerates homomorphisms for a query while extending a partial substitution.default Stream<Substitution> postprocessResult(Stream<Substitution> unfilteredSubstitutions, Collection<Variable> variablesThatMustBeMappedToGroundTerms) Filters the result of a query by removing substitutions which map a variable to some other variable of the active domain.default Stream<Substitution> postprocessResult(Stream<Substitution> unfilteredSubstitutions, org.apache.commons.collections4.Predicate<Substitution> predicate) Filters the result of a query according to a predicate.default PreparedQuery<? extends Q, QD, Substitution, Substitution> prepareQuery(Q query, QD queryableData, boolean answerVariablesMustBeGround) Creates a prepared query bound to a data source.default PreparedQuery<? extends Q, QD, Substitution, Substitution> prepareQuery(Q query, QD queryableData, Collection<Variable> variablesThatMustBeMappedToGroundTerms) Creates a prepared query bound to a data source and ground-term policy.
-
Method Details
-
evaluate
Stream<Substitution> evaluate(Q query, QD queryableData, Collection<Variable> variablesThatMustBeMappedToGroundTerms, Substitution preHomomorphism) throws EvaluationException Evaluates a query against a data source.- Parameters:
query- query to evaluatequeryableData- queryable data source in which atoms are storedvariablesThatMustBeMappedToGroundTerms- the set of variables that must be mapped to constantspreHomomorphism- a partial homomorphism from var(query) to terms(queryable data source) to extend- Returns:
- an
StreamofSubstitutionover all the answers of the given query in the given queryable data source with respect to the query answer variables. - Throws:
EvaluationException- if the evaluation cannot be completed
-
homomorphism
Enumerates homomorphisms for a query without a pre-existing mapping.- Parameters:
query- query to evaluatequeryableData- queryable data source in which atoms are stored- Returns:
- an
StreamofSubstitutionover all the homomorphisms of the given query in the given queryable data source with respect to the query answer variables. - Throws:
EvaluationException- if the evaluation cannot be completed
-
homomorphism
default Stream<Substitution> homomorphism(Q query, QD queryableData, Substitution preHomomorphism) throws EvaluationException Enumerates homomorphisms for a query while extending a partial substitution.- Parameters:
query- query to evaluatequeryableData- queryable data source in which atoms are storedpreHomomorphism- a partial homomorphism to extend- Returns:
- an
StreamofSubstitutionover all the homomorphisms of the given query in the given queryable data source with respect to the query answer variables. - Throws:
EvaluationException- if the evaluation cannot be completed
-
evaluate
Evaluates a query using its answer variables as the projection.- Parameters:
query- query to evaluatequeryableData- queryable data source in which atoms are stored- Returns:
- an
StreamofSubstitutionover all the answers of the given query in the given queryable data source with respect to the query answer variables. - Throws:
EvaluationException- if the evaluation cannot be completed
-
evaluate
default Stream<Substitution> evaluate(Q query, QD queryableData, Substitution preHomomorphism) throws EvaluationException Evaluates a query while extending a partial answer substitution.- Parameters:
query- query to evaluatequeryableData- queryable data source in which atoms are storedpreHomomorphism- a partial answer to extend- Returns:
- an
StreamofSubstitutionover all the answers of the given query in the given queryable data source with respect to the query answer variables. - Throws:
EvaluationException- if the evaluation cannot be completed
-
existHomomorphism
Tests whether the query has at least one homomorphism in the data source.- Parameters:
query- query to evaluatequeryableData- queryable data source in which atoms are stored- Returns:
- true iff there exist a substitution s that is a homomorphism of the query on the queryable data source
- Throws:
EvaluationException- if the evaluation cannot be completed
-
existHomomorphism
default boolean existHomomorphism(Q query, QD queryableData, Substitution preHomomorphism) throws EvaluationException Tests whether the query has at least one homomorphism extending the supplied substitution.- Parameters:
query- query to evaluatequeryableData- queryable data source in which atoms are storedpreHomomorphism- a partial homomorphism to extend- Returns:
- true iff there exist a substitution s that is a homomorphism of the query on the queryable data source
- Throws:
EvaluationException- if the evaluation cannot be completed
-
existAnswer
Tests whether the query has at least one answer in the data source.- Parameters:
query- query to evaluatequeryableData- queryable data source in which atoms are stored- Returns:
- true iff there exist a substitution s that is an answer to the query on the queryable data source
- Throws:
EvaluationException- if the evaluation cannot be completed
-
existAnswer
default boolean existAnswer(Q query, QD queryableData, Substitution preHomomorphism) throws EvaluationException Tests whether the query has at least one answer extending the supplied substitution.- Parameters:
query- query to evaluatequeryableData- queryable data source in which atoms are storedpreHomomorphism- a partial answer to extend- Returns:
- true iff there exist a substitution s that is an answer to the query on the queryable data source
- Throws:
EvaluationException- if the evaluation cannot be completed
-
countAnswers
Counts answers for the supplied query.- Parameters:
query- query to evaluatequeryableData- queryable data source in which atoms are stored- Returns:
- the number of answers to the query
- Throws:
EvaluationException- if the evaluation cannot be completed
-
countHomomorphism
Counts homomorphisms for the supplied query.- Parameters:
query- query to evaluatequeryableData- queryable data source in which atoms are stored- Returns:
- the number of substitutions that are homomorphisms of the query on the queryable data source
- Throws:
EvaluationException- if the evaluation cannot be completed
-
postprocessResult
default Stream<Substitution> postprocessResult(Stream<Substitution> unfilteredSubstitutions, Collection<Variable> variablesThatMustBeMappedToGroundTerms) Filters the result of a query by removing substitutions which map a variable to some other variable of the active domain.- Parameters:
unfilteredSubstitutions- the unfiltered substitutionvariablesThatMustBeMappedToGroundTerms- the set of variables that must be mapped to constants- Returns:
- the post-processed query result where results have been possibly filtered by retaining only substitutions mapping to constants if required
-
postprocessResult
default Stream<Substitution> postprocessResult(Stream<Substitution> unfilteredSubstitutions, org.apache.commons.collections4.Predicate<Substitution> predicate) Filters the result of a query according to a predicate.- Parameters:
unfilteredSubstitutions- the unfiltered substitutionpredicate- the condition to be evaluated- Returns:
- the post-processed query result where results have been possibly filtered by retaining only substitutions mapping to constants if required
-
prepareQuery
default PreparedQuery<? extends Q, QD, Substitution, Substitution> prepareQuery(Q query, QD queryableData, Collection<Variable> variablesThatMustBeMappedToGroundTerms) Creates a prepared query bound to a data source and ground-term policy.- Parameters:
query- the query to preparequeryableData- the data source against which the query will runvariablesThatMustBeMappedToGroundTerms- variables constrained to ground answers- Returns:
- a prepared query wrapper
-
prepareQuery
default PreparedQuery<? extends Q, QD, Substitution, Substitution> prepareQuery(Q query, QD queryableData, boolean answerVariablesMustBeGround) Creates a prepared query bound to a data source.- Parameters:
query- the query to preparequeryableData- the data source against which the query will runanswerVariablesMustBeGround- whether answer variables must map to ground terms- Returns:
- a prepared query wrapper
-