Interface QueryEvaluator<Q extends Query, QD extends QueryableData>

Type Parameters:
Q - The type of Query that the evaluator can evaluate
QD - The type of QueryableData evaluated 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 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 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 evaluate
      queryableData - queryable data source in which atoms are stored
      variablesThatMustBeMappedToGroundTerms - the set of variables that must be mapped to constants
      preHomomorphism - a partial homomorphism from var(query) to terms(queryable data source) to extend
      Returns:
      an Stream of Substitution over 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

      default Stream<Substitution> homomorphism(Q query, QD queryableData) throws EvaluationException
      Enumerates homomorphisms for a query without a pre-existing mapping.
      Parameters:
      query - query to evaluate
      queryableData - queryable data source in which atoms are stored
      Returns:
      an Stream of Substitution over 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 evaluate
      queryableData - queryable data source in which atoms are stored
      preHomomorphism - a partial homomorphism to extend
      Returns:
      an Stream of Substitution over 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

      default Stream<Substitution> evaluate(Q query, QD queryableData) throws EvaluationException
      Evaluates a query using its answer variables as the projection.
      Parameters:
      query - query to evaluate
      queryableData - queryable data source in which atoms are stored
      Returns:
      an Stream of Substitution over 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 evaluate
      queryableData - queryable data source in which atoms are stored
      preHomomorphism - a partial answer to extend
      Returns:
      an Stream of Substitution over 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

      default boolean existHomomorphism(Q query, QD queryableData) throws EvaluationException
      Tests whether the query has at least one homomorphism in the data source.
      Parameters:
      query - query to evaluate
      queryableData - 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 evaluate
      queryableData - queryable data source in which atoms are stored
      preHomomorphism - 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

      default boolean existAnswer(Q query, QD queryableData) throws EvaluationException
      Tests whether the query has at least one answer in the data source.
      Parameters:
      query - query to evaluate
      queryableData - 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 evaluate
      queryableData - queryable data source in which atoms are stored
      preHomomorphism - 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

      default long countAnswers(Q query, QD queryableData) throws EvaluationException
      Counts answers for the supplied query.
      Parameters:
      query - query to evaluate
      queryableData - 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

      default long countHomomorphism(Q query, QD queryableData) throws EvaluationException
      Counts homomorphisms for the supplied query.
      Parameters:
      query - query to evaluate
      queryableData - 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 substitution
      variablesThatMustBeMappedToGroundTerms - 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 substitution
      predicate - 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 prepare
      queryableData - the data source against which the query will run
      variablesThatMustBeMappedToGroundTerms - 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 prepare
      queryableData - the data source against which the query will run
      answerVariablesMustBeGround - whether answer variables must map to ground terms
      Returns:
      a prepared query wrapper