Class Query<I,​D>

  • Type Parameters:
    I - input symbol type
    D - output domain type
    Direct Known Subclasses:
    AbstractQuery

    public abstract class Query<I,​D>
    extends Object
    A query is the basic form of interaction between a learner and a (membership) oracle, or teacher.

    In LearnLib, queries are performed in a callback-like fashion: an oracle does not return the responses to the queries, but rather invokes the answer(Object) method on the query objects it was provided with. This allows for implementing queries which directly react to an answered query (e.g., by modifying some internal data structure), without the need for buffering answers. It also allows for a more efficient parallel processing of queries, as there is no need for maintaining a common (synchronized) result data structure such as a map. However, this means that a learner cannot rely on the answer(Object) method of a query being called from the same thread which invoked MembershipOracle.processQueries(java.util.Collection). If this causes concurrency issues, a safe choice is to use queries of class DefaultQuery, which simply store the response and make it accessible via DefaultQuery.getOutput() for processing after the MembershipOracle.processQueries(java.util.Collection) call returns, guaranteeing thread-safety.

    Conceptually, a query is divided into a prefix and a getSuffix() suffix. The prefix part of a query identifies a state in the (unknown) target system, whereas the suffix is the "experiment" which is conducted on the system starting from the state to which it was transferred by the prefix. While the prefix influences the response of the target system to a query, the answer is the directly observable reaction to executing the suffix.

    Example 1: when learning Mealy machines, the prefix transfers the target system to a certain state. The outputs produced by the system while executing the prefix are not part of the answer, as the role of the prefix is limited to reaching a certain state. The reaction of the target system consists of the output word produced while executing the suffix. Therefore, in the setting of Mealy machine learning, a valid oracle will call the answer(Object) method with a word of the same length as the suffix.

    Example 2: when learning DFAs, the reaction of the target system is fully determined by the state reached by an input word. Since both prefix and suffix have the same effect on producing this output (by transferring the system to a certain state), the response will always be a single Boolean, and, furthermore, for every input word w, the response to a query will always be the same regardless of the subdivision of w = uv into prefix u and suffix v (including the corner cases u = ε and v = ε).

    • Constructor Detail

      • Query

        public Query()
    • Method Detail

      • answer

        public abstract void answer​(D output)
        Answers the query. This method should be called by a MembershipOracle, and only once per query to process. Calling this method more than once may result in undefined behavior, possibly (but not necessarily) throwing an exception.
        Parameters:
        output - the output, i.e., the directly observable response to the query's suffix (cf. main documentation)
      • getInput

        public Word<I> getInput()
        Retrieves the input word of this query. The input word corresponding to a query is the concatenation of its prefix and suffix.
        Returns:
        the input word of this query
      • getPrefix

        public abstract Word<I> getPrefix()
        Returns the prefix part of this query. The prefix of a query is responsible for transferring the system into a certain state, but (apart from that) does not directly influence the output.
        Returns:
        the prefix of this query
      • getSuffix

        public abstract Word<I> getSuffix()
        Returns the suffix part of this query. The suffix of a query is the experiment performed on the system when in the state it was transferred into by the prefix, and thus directly influences the output.
        Returns:
        the suffix of this query
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class Object
      • equals

        public final boolean equals​(@Nullable Object o)
        Overrides:
        equals in class Object
      • toString

        public String toString()
        Returns the string representation of this query.
        Overrides:
        toString in class Object
        Returns:
        A string of the form "Query[<prefix>|<suffix>]" for queries not containing an answer or "Query[<prefix>|<suffix> / <answer>]" if an answer may be specified.