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

LearnLib / learnlib / 6673301747

27 Oct 2023 11:46PM UTC coverage: 91.986% (-1.3%) from 93.327%
6673301747

push

github

mtf90
merge the release and sign-artifacts profiles

10984 of 11941 relevant lines covered (91.99%)

1.72 hits per line

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

69.23
/api/src/main/java/de/learnlib/api/algorithm/PassiveLearningAlgorithm.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.algorithm;
17

18
import java.util.ArrayList;
19
import java.util.Arrays;
20
import java.util.Collection;
21
import java.util.Collections;
22
import java.util.List;
23

24
import de.learnlib.api.query.DefaultQuery;
25
import net.automatalib.automaton.fsa.DFA;
26
import net.automatalib.automaton.fsa.FiniteStateAcceptor;
27
import net.automatalib.automaton.fsa.NFA;
28
import net.automatalib.automaton.transducer.MealyMachine;
29
import net.automatalib.automaton.transducer.MooreMachine;
30
import net.automatalib.word.Word;
31

32
public interface PassiveLearningAlgorithm<M, I, D> {
33

34
    void addSamples(Collection<? extends DefaultQuery<I, D>> samples);
35

36
    @SuppressWarnings("unchecked")
37
    default void addSamples(DefaultQuery<I, D>... samples) {
38
        addSamples(Arrays.asList(samples));
×
39
    }
×
40

41
    @SuppressWarnings("unchecked")
42
    default void addSamples(D output, Word<I>... words) {
43
        addSamples(output, Arrays.asList(words));
1✔
44
    }
1✔
45

46
    default void addSamples(D output, Collection<? extends Word<I>> words) {
47
        List<DefaultQuery<I, D>> queries = new ArrayList<>(words.size());
1✔
48
        for (Word<I> word : words) {
1✔
49
            queries.add(new DefaultQuery<>(word, output));
1✔
50
        }
1✔
51

52
        addSamples(queries);
1✔
53
    }
1✔
54

55
    default void addSample(Word<I> input, D output) {
56
        addSample(new DefaultQuery<>(input, output));
1✔
57
    }
1✔
58

59
    default void addSample(DefaultQuery<I, D> sample) {
60
        addSamples(Collections.singleton(sample));
1✔
61
    }
1✔
62

63
    /**
64
     * Computes the model given the previously added samples.
65
     * <p>
66
     * <b>Implementation note:</b> It is up to the implementation if this operation is repeatable or not, An
67
     * implementation may throw an {@link IllegalStateException} if additional samples are added after the first model
68
     * construction.
69
     *
70
     * @return the computed model
71
     */
72
    M computeModel();
73

74
    /**
75
     * Basic interface for passive learning algorithms that infer {@link DFA}s.
76
     *
77
     * @param <I>
78
     *         input symbol type
79
     */
80
    interface PassiveDFALearner<I> extends PassiveAcceptorLearner<DFA<?, I>, I> {}
81

82
    /**
83
     * Basic interface for passive learning algorithms that infer {@link MealyMachine Mealy machines}.
84
     *
85
     * @param <I>
86
     *         input symbol type
87
     * @param <O>
88
     *         output symbol type
89
     */
90
    interface PassiveMealyLearner<I, O> extends PassiveLearningAlgorithm<MealyMachine<?, I, ?, O>, I, Word<O>> {}
91

92
    /**
93
     * Basic interface for passive learning algorithms that infer {@link MooreMachine Moore machines}.
94
     *
95
     * @param <I>
96
     *         input symbol type
97
     * @param <O>
98
     *         output symbol type
99
     */
100
    interface PassiveMooreLearner<I, O> extends PassiveLearningAlgorithm<MooreMachine<?, I, ?, O>, I, Word<O>> {}
101

102
    /**
103
     * Basic interface for passive learning algorithms that infer finite-state acceptors ({@link DFA}s or {@link
104
     * NFA}s).
105
     *
106
     * @param <M>
107
     *         model type
108
     * @param <I>
109
     *         input symbol type
110
     */
111
    interface PassiveAcceptorLearner<M extends FiniteStateAcceptor<?, I>, I>
112
            extends PassiveLearningAlgorithm<M, I, Boolean> {
113

114
        default void addPositiveSample(Word<I> word) {
115
            addSample(word, true);
1✔
116
        }
1✔
117

118
        default void addPositiveSamples(Collection<? extends Word<I>> words) {
119
            addSamples(true, words);
×
120
        }
×
121

122
        @SuppressWarnings("unchecked")
123
        default void addPositiveSamples(Word<I>... words) {
124
            addSamples(true, words);
1✔
125
        }
1✔
126

127
        default void addNegativeSample(Word<I> word) {
128
            addSample(word, false);
×
129
        }
×
130

131
        default void addNegativeSamples(Collection<? extends Word<I>> words) {
132
            addSamples(false, words);
×
133
        }
×
134

135
        @SuppressWarnings("unchecked")
136
        default void addNegativeSamples(Word<I>... words) {
137
            addSamples(false, words);
1✔
138
        }
1✔
139
    }
140

141
}
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