Class Query<I,D>
- java.lang.Object
-
- de.learnlib.query.Query<I,D>
-
- Type Parameters:
I
- input symbol typeD
- output domain type
- Direct Known Subclasses:
AbstractQuery
public abstract class Query<I,D> extends Object
A query is the basic form of interaction between alearner
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 theanswer(Object)
method of a query being called from the same thread which invokedMembershipOracle.processQueries(java.util.Collection)
. If this causes concurrency issues, a safe choice is to use queries of classDefaultQuery
, which simply store the response and make it accessible viaDefaultQuery.getOutput()
for processing after theMembershipOracle.processQueries(java.util.Collection)
call returns, guaranteeing thread-safety.Conceptually, a query is divided into a
prefix
and agetSuffix()
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 theanswer(Object)
method with a word of the same length as the suffix.Example 2: when learning
DFA
s, 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 singleBoolean
, and, furthermore, for every input wordw
, the response to a query will always be the same regardless of the subdivision ofw = uv
into prefixu
and suffixv
(including the corner casesu = ε
andv = ε
).
-
-
Constructor Summary
Constructors Constructor Description Query()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
answer(D output)
Answers the query.boolean
equals(@Nullable Object o)
Word<I>
getInput()
Retrieves the input word of this query.abstract Word<I>
getPrefix()
Returns the prefix part of this query.abstract Word<I>
getSuffix()
Returns the suffix part of this query.int
hashCode()
String
toString()
Returns the string representation of this query.
-
-
-
Method Detail
-
answer
public abstract void answer(D output)
Answers the query. This method should be called by aMembershipOracle
, 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
-
-