• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LearnLib / learnlib / 6660471831

26 Oct 2023 10:29PM UTC coverage: 93.327% (-0.001%) from 93.328%
6660471831

push

github

mtf90
cleanup statistics filters

32 of 32 new or added lines in 7 files covered. (100.0%)

11734 of 12573 relevant lines covered (93.33%)

1.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/api/src/main/java/de/learnlib/api/oracle/MembershipOracle.java
1
/* Copyright (C) 2013-2023 TU Dortmund
2
 * This file is part of LearnLib, http://www.learnlib.de/.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package de.learnlib.api.oracle;
17

18
import java.util.Collection;
19
import java.util.Collections;
20

21
import de.learnlib.api.oracle.parallelism.BatchProcessor;
22
import de.learnlib.api.query.DefaultQuery;
23
import de.learnlib.api.query.Query;
24
import net.automatalib.automaton.fsa.DFA;
25
import net.automatalib.automaton.transducer.MealyMachine;
26
import net.automatalib.automaton.transducer.MooreMachine;
27
import net.automatalib.word.Word;
28

29
/**
30
 * Membership oracle interface. A membership oracle provides an elementary abstraction to a System Under Learning (SUL),
31
 * by allowing to pose {@link Query queries}: A query is a sequence of input symbols (divided into a prefix and a suffix
32
 * part, cf. {@link Query#getPrefix()} and {@link Query#getSuffix()}) in reaction to which the SUL produces a specific
33
 * observable behavior (outputting a word, acceptance/rejection etc.).
34
 *
35
 * @see DefaultQuery
36
 */
37
public interface MembershipOracle<I, D> extends QueryAnswerer<I, D>, BatchProcessor<Query<I, D>> {
38

39
    @Override
40
    default D answerQuery(Word<I> input) {
41
        return answerQuery(Word.epsilon(), input);
1✔
42
    }
43

44
    @Override
45
    default D answerQuery(Word<I> prefix, Word<I> suffix) {
46
        DefaultQuery<I, D> query = new DefaultQuery<>(prefix, suffix);
1✔
47
        processQuery(query);
1✔
48
        return query.getOutput();
1✔
49
    }
50

51
    /**
52
     * Processes a single query. When this method returns, the {@link Query#answer(Object)} method of the supplied
53
     * object will have been called with an argument reflecting the SUL response to the respective query.
54
     * <p>
55
     * The default implementation of this method will simply wrap the provided {@link Query} in a singleton {@link
56
     * Collection} using {@link Collections#singleton(Object)}. Implementations in subclasses should override this
57
     * method to circumvent the Collection object creation, if possible.
58
     *
59
     * @param query
60
     *         the query to process
61
     */
62
    default void processQuery(Query<I, D> query) {
63
        processQueries(Collections.singleton(query));
1✔
64
    }
1✔
65

66
    /**
67
     * Processes the specified collection of queries. When this method returns, each of the contained queries {@link
68
     * Query#answer(Object)} method should have been called with an argument reflecting the SUL response to the
69
     * respective query.
70
     *
71
     * @param queries
72
     *         the queries to process
73
     *
74
     * @see Query#answer(Object)
75
     */
76
    void processQueries(Collection<? extends Query<I, D>> queries);
77

78
    @Override
79
    default MembershipOracle<I, D> asOracle() {
80
        return this;
×
81
    }
82

83
    @Override
84
    default void processBatch(Collection<? extends Query<I, D>> batch) {
85
        processQueries(batch);
1✔
86
    }
1✔
87

88
    /**
89
     * A specialization of the {@link MembershipOracle} that binds the output domain to {@link Boolean}s. Queries should
90
     * be answered according to the semantics of acceptors such as {@link DFA}s. This means an input sequence of length
91
     * {@code n} results in a single boolean output.
92
     *
93
     * @param <I>
94
     *         input symbol type
95
     */
96
    interface DFAMembershipOracle<I> extends MembershipOracle<I, Boolean> {}
97

98
    /**
99
     * A specialization of the {@link MembershipOracle} that binds the output domain to {@link Word}s of the specified
100
     * output type. Queries should be answered according to the semantics of transition-output systems such as
101
     * {@link MealyMachine}s. This means an input sequence of length {@code n} results in an output word of length
102
     * {@code n}.
103
     *
104
     * @param <I>
105
     *         input symbol type
106
     * @param <O>
107
     *         output symbol type
108
     */
109
    interface MealyMembershipOracle<I, O> extends MembershipOracle<I, Word<O>> {}
110

111
    /**
112
     * A specialization of the {@link MembershipOracle} that binds the output domain to {@link Word}s of the specified
113
     * output type. Queries should be answered according to the semantics of state-output systems such as
114
     * {@link MooreMachine}s. This means an input sequence of length {@code n} results in an output word of length
115
     * {@code n+1}.
116
     *
117
     * @param <I>
118
     *         input symbol type
119
     * @param <O>
120
     *         output symbol type
121
     */
122
    interface MooreMembershipOracle<I, O> extends MembershipOracle<I, Word<O>> {}
123

124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc