Skip to content

Commit fa3f601

Browse files
committed
cleanup/refactor archetypes
- removed 'core' archetype - renamed 'typical' archetype to 'basic' archetype - added a small example class that demonstrates basic usage
1 parent bbf04c4 commit fa3f601

14 files changed

Lines changed: 232 additions & 184 deletions

File tree

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ limitations under the License.
2020
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2121
<modelVersion>4.0.0</modelVersion>
2222

23-
<artifactId>core</artifactId>
23+
<artifactId>basic</artifactId>
2424
<packaging>maven-archetype</packaging>
2525

26-
<name>LearnLib :: Archetypes :: Core</name>
27-
<description>Archetype providing dependencies for core functionalities of LearnLib</description>
26+
<name>LearnLib :: Archetypes :: Basic</name>
27+
<description>Archetype for a basic LearnLib setup, including the most commonly used dependencies</description>
2828

2929
<parent>
3030
<groupId>de.learnlib.archetypes</groupId>
@@ -43,5 +43,6 @@ limitations under the License.
4343
<scope>test</scope>
4444
</dependency>
4545
</dependencies>
46+
4647
</project>
4748

archetypes/core/src/main/resources-template/META-INF/maven/archetype-metadata.xml renamed to archetypes/basic/src/main/resources-template/META-INF/maven/archetype-metadata.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
-->
1818
<archetype-descriptor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1919
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
20-
name="LearnLib Core Project"
20+
name="LearnLib Basic Project"
2121
partial="true"
2222
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0">
2323
<requiredProperties>
@@ -27,13 +27,13 @@ limitations under the License.
2727
</requiredProperties>
2828

2929
<fileSets>
30-
<fileSet filtered="false" packaged="true" encoding="UTF-8">
30+
<fileSet filtered="true" packaged="true" encoding="UTF-8">
3131
<directory>src/main/java</directory>
3232
<includes>
3333
<include>**/*.java</include>
3434
</includes>
3535
</fileSet>
36-
<fileSet filtered="false" packaged="true" encoding="UTF-8">
36+
<fileSet filtered="true" packaged="true" encoding="UTF-8">
3737
<directory>src/test/java</directory>
3838
<includes>
3939
<include>**/*.java</include>

archetypes/typical/src/main/resources/archetype-resources/pom.xml renamed to archetypes/basic/src/main/resources/archetype-resources/pom.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ limitations under the License.
5252
<groupId>de.learnlib</groupId>
5353
<artifactId>learnlib-api</artifactId>
5454
</dependency>
55-
<dependency>
56-
<groupId>de.learnlib</groupId>
57-
<artifactId>learnlib-counterexamples</artifactId>
58-
</dependency>
5955
<dependency>
6056
<groupId>de.learnlib</groupId>
6157
<artifactId>learnlib-equivalence-oracles</artifactId>
@@ -66,11 +62,11 @@ limitations under the License.
6662
</dependency>
6763
<dependency>
6864
<groupId>de.learnlib</groupId>
69-
<artifactId>learnlib-cache</artifactId>
65+
<artifactId>learnlib-lstar</artifactId>
7066
</dependency>
7167
<dependency>
7268
<groupId>de.learnlib</groupId>
73-
<artifactId>learnlib-lstar</artifactId>
69+
<artifactId>learnlib-util</artifactId>
7470
</dependency>
7571

7672
<dependency>
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package ${package};
2+
3+
import de.learnlib.algorithms.lstar.dfa.ClassicLStarDFA;
4+
import de.learnlib.algorithms.lstar.dfa.ClassicLStarDFABuilder;
5+
import de.learnlib.api.oracle.MembershipOracle.DFAMembershipOracle;
6+
import de.learnlib.oracle.equivalence.WMethodEQOracle.DFAWMethodEQOracle;
7+
import de.learnlib.oracle.membership.SimulatorOracle.DFASimulatorOracle;
8+
import de.learnlib.util.Experiment.DFAExperiment;
9+
import de.learnlib.util.statistics.SimpleProfiler;
10+
import net.automatalib.automata.fsa.DFA;
11+
import net.automatalib.automata.fsa.impl.compact.CompactDFA;
12+
import net.automatalib.util.automata.builders.AutomatonBuilders;
13+
import net.automatalib.visualization.Visualization;
14+
import net.automatalib.words.Alphabet;
15+
import net.automatalib.words.impl.Alphabets;
16+
17+
/**
18+
* This example shows the usage of a learning algorithm and an equivalence test as part of an experiment in order to
19+
* learn a simulated SUL (system under learning).
20+
*/
21+
public final class Example {
22+
23+
public static void main(String[] args) {
24+
25+
// load DFA and alphabet
26+
CompactDFA<Character> target = constructSUL();
27+
Alphabet<Character> inputs = target.getInputAlphabet();
28+
29+
// construct a simulator membership query oracle
30+
// input - Character (determined by example)
31+
DFAMembershipOracle<Character> mqOracle = new DFASimulatorOracle<>(target);
32+
33+
// construct L* instance
34+
ClassicLStarDFA<Character> lstar =
35+
new ClassicLStarDFABuilder<Character>().withAlphabet(inputs) // input alphabet
36+
.withOracle(mqOracle) // membership oracle
37+
.create();
38+
39+
// construct a W-method conformance test
40+
// exploring the system up to depth 4 from
41+
// every state of a hypothesis
42+
DFAWMethodEQOracle<Character> wMethod = new DFAWMethodEQOracle<>(4, mqOracle);
43+
44+
// construct a learning experiment from
45+
// the learning algorithm and the conformance test.
46+
// The experiment will execute the main loop of
47+
// active learning
48+
DFAExperiment<Character> experiment = new DFAExperiment<>(lstar, wMethod, inputs);
49+
50+
// turn on time profiling
51+
experiment.setProfile(true);
52+
53+
// enable logging of models
54+
experiment.setLogModels(true);
55+
56+
// run experiment
57+
experiment.run();
58+
59+
// get learned model
60+
DFA<?, Character> result = experiment.getFinalHypothesis();
61+
62+
// report results
63+
System.out.println("-------------------------------------------------------");
64+
65+
// profiling
66+
System.out.println(SimpleProfiler.getResults());
67+
68+
// learning statistics
69+
System.out.println(experiment.getRounds().getSummary());
70+
71+
// model statistics
72+
System.out.println("States: " + result.size());
73+
System.out.println("Sigma: " + inputs.size());
74+
75+
// show model
76+
System.out.println();
77+
System.out.println("Model: ");
78+
79+
Visualization.visualizeAutomaton(result, inputs, true);
80+
}
81+
82+
/**
83+
* creates example from Angluin's seminal paper.
84+
*
85+
* @return example dfa
86+
*/
87+
private static CompactDFA<Character> constructSUL() {
88+
// input alphabet contains characters 'a'..'b'
89+
Alphabet<Character> sigma = Alphabets.characters('a', 'b');
90+
91+
// create automaton
92+
return AutomatonBuilders.newDFA(sigma)
93+
.withInitial("q0")
94+
.from("q0")
95+
.on('a').to("q1")
96+
.on('b').to("q2")
97+
.from("q1")
98+
.on('a').to("q0")
99+
.on('b').to("q3")
100+
.from("q2")
101+
.on('a').to("q3")
102+
.on('b').to("q0")
103+
.from("q3")
104+
.on('a').to("q2")
105+
.on('b').to("q1")
106+
.withAccepting("q0")
107+
.create();
108+
}
109+
}

archetypes/core/src/test/resources-template/projects/basic/archetype.properties renamed to archetypes/basic/src/test/resources-template/projects/basic/archetype.properties

File renamed without changes.

archetypes/core/src/test/resources-template/projects/basic/goal.txt renamed to archetypes/basic/src/test/resources-template/projects/basic/goal.txt

File renamed without changes.

archetypes/complete/src/main/resources-template/META-INF/maven/archetype-metadata.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
-->
1818
<archetype-descriptor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1919
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
20-
name="LearnLib Core Project"
20+
name="LearnLib Complete Project"
2121
partial="true"
2222
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0">
2323
<requiredProperties>
@@ -27,13 +27,13 @@ limitations under the License.
2727
</requiredProperties>
2828

2929
<fileSets>
30-
<fileSet filtered="false" packaged="true" encoding="UTF-8">
30+
<fileSet filtered="true" packaged="true" encoding="UTF-8">
3131
<directory>src/main/java</directory>
3232
<includes>
3333
<include>**/*.java</include>
3434
</includes>
3535
</fileSet>
36-
<fileSet filtered="false" packaged="true" encoding="UTF-8">
36+
<fileSet filtered="true" packaged="true" encoding="UTF-8">
3737
<directory>src/test/java</directory>
3838
<includes>
3939
<include>**/*.java</include>
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package ${package};
2+
3+
import de.learnlib.algorithms.lstar.dfa.ClassicLStarDFA;
4+
import de.learnlib.algorithms.lstar.dfa.ClassicLStarDFABuilder;
5+
import de.learnlib.api.oracle.MembershipOracle.DFAMembershipOracle;
6+
import de.learnlib.oracle.equivalence.WMethodEQOracle.DFAWMethodEQOracle;
7+
import de.learnlib.oracle.membership.SimulatorOracle.DFASimulatorOracle;
8+
import de.learnlib.util.Experiment.DFAExperiment;
9+
import de.learnlib.util.statistics.SimpleProfiler;
10+
import net.automatalib.automata.fsa.DFA;
11+
import net.automatalib.automata.fsa.impl.compact.CompactDFA;
12+
import net.automatalib.util.automata.builders.AutomatonBuilders;
13+
import net.automatalib.visualization.Visualization;
14+
import net.automatalib.words.Alphabet;
15+
import net.automatalib.words.impl.Alphabets;
16+
17+
/**
18+
* This example shows the usage of a learning algorithm and an equivalence test as part of an experiment in order to
19+
* learn a simulated SUL (system under learning).
20+
*/
21+
public final class Example {
22+
23+
public static void main(String[] args) {
24+
25+
// load DFA and alphabet
26+
CompactDFA<Character> target = constructSUL();
27+
Alphabet<Character> inputs = target.getInputAlphabet();
28+
29+
// construct a simulator membership query oracle
30+
// input - Character (determined by example)
31+
DFAMembershipOracle<Character> mqOracle = new DFASimulatorOracle<>(target);
32+
33+
// construct L* instance
34+
ClassicLStarDFA<Character> lstar =
35+
new ClassicLStarDFABuilder<Character>().withAlphabet(inputs) // input alphabet
36+
.withOracle(mqOracle) // membership oracle
37+
.create();
38+
39+
// construct a W-method conformance test
40+
// exploring the system up to depth 4 from
41+
// every state of a hypothesis
42+
DFAWMethodEQOracle<Character> wMethod = new DFAWMethodEQOracle<>(4, mqOracle);
43+
44+
// construct a learning experiment from
45+
// the learning algorithm and the conformance test.
46+
// The experiment will execute the main loop of
47+
// active learning
48+
DFAExperiment<Character> experiment = new DFAExperiment<>(lstar, wMethod, inputs);
49+
50+
// turn on time profiling
51+
experiment.setProfile(true);
52+
53+
// enable logging of models
54+
experiment.setLogModels(true);
55+
56+
// run experiment
57+
experiment.run();
58+
59+
// get learned model
60+
DFA<?, Character> result = experiment.getFinalHypothesis();
61+
62+
// report results
63+
System.out.println("-------------------------------------------------------");
64+
65+
// profiling
66+
System.out.println(SimpleProfiler.getResults());
67+
68+
// learning statistics
69+
System.out.println(experiment.getRounds().getSummary());
70+
71+
// model statistics
72+
System.out.println("States: " + result.size());
73+
System.out.println("Sigma: " + inputs.size());
74+
75+
// show model
76+
System.out.println();
77+
System.out.println("Model: ");
78+
79+
Visualization.visualizeAutomaton(result, inputs, true);
80+
}
81+
82+
/**
83+
* creates example from Angluin's seminal paper.
84+
*
85+
* @return example dfa
86+
*/
87+
private static CompactDFA<Character> constructSUL() {
88+
// input alphabet contains characters 'a'..'b'
89+
Alphabet<Character> sigma = Alphabets.characters('a', 'b');
90+
91+
// create automaton
92+
return AutomatonBuilders.newDFA(sigma)
93+
.withInitial("q0")
94+
.from("q0")
95+
.on('a').to("q1")
96+
.on('b').to("q2")
97+
.from("q1")
98+
.on('a').to("q0")
99+
.on('b').to("q3")
100+
.from("q2")
101+
.on('a').to("q3")
102+
.on('b').to("q0")
103+
.from("q3")
104+
.on('a').to("q2")
105+
.on('b').to("q1")
106+
.withAccepting("q0")
107+
.create();
108+
}
109+
110+
}

archetypes/core/src/main/resources/archetype-resources/pom.xml

Lines changed: 0 additions & 64 deletions
This file was deleted.

archetypes/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ limitations under the License.
3535
</parent>
3636

3737
<modules>
38-
<module>core</module>
39-
<module>typical</module>
38+
<module>basic</module>
4039
<module>complete</module>
4140
</modules>
4241

0 commit comments

Comments
 (0)