Skip to content

Commit 9ef29ee

Browse files
committed
initial commit
1 parent a618ad6 commit 9ef29ee

File tree

4 files changed

+199
-0
lines changed

4 files changed

+199
-0
lines changed

.gitignore

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Python virtualenv
2+
venv/
3+
4+
# Maven output
5+
target/
6+
7+
# Eclipse output directory
8+
bin/
9+
10+
# Eclipse settings
11+
.settings/
12+
.classpath
13+
.project
14+
.factorypath
15+
16+
#Intellij settings
17+
*.iml
18+
.idea/

java/pom.xml

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
Copyright (C) 2013-2018 TU Dortmund
4+
This file is part of LearnLib, http://www.learnlib.de/.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
22+
<groupId>com.github.mtf90</groupId>
23+
<artifactId>learnlib-py4j-example</artifactId>
24+
<version>1.0-SNAPSHOT</version>
25+
<packaging>jar</packaging>
26+
27+
<properties>
28+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
29+
30+
<!-- AutomataLib requires Java 8 -->
31+
<maven.compiler.source>1.8</maven.compiler.source>
32+
<maven.compiler.target>1.8</maven.compiler.target>
33+
34+
<!-- Version of LearnLib to use -->
35+
<learnlib.version>0.13.1</learnlib.version>
36+
</properties>
37+
38+
<dependencyManagement>
39+
<dependencies>
40+
<dependency>
41+
<groupId>de.learnlib</groupId>
42+
<artifactId>learnlib-parent</artifactId>
43+
<version>${learnlib.version}</version>
44+
<type>pom</type>
45+
<scope>import</scope>
46+
</dependency>
47+
</dependencies>
48+
</dependencyManagement>
49+
50+
<dependencies>
51+
<dependency>
52+
<groupId>de.learnlib.distribution</groupId>
53+
<artifactId>learnlib-distribution</artifactId>
54+
<type>pom</type>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>net.sf.py4j</groupId>
59+
<artifactId>py4j</artifactId>
60+
<version>0.10.8.1</version>
61+
</dependency>
62+
63+
<!-- provide an SLF4J implementation -->
64+
<dependency>
65+
<groupId>ch.qos.logback</groupId>
66+
<artifactId>logback-classic</artifactId>
67+
<scope>runtime</scope>
68+
</dependency>
69+
</dependencies>
70+
71+
<build>
72+
<plugins>
73+
<plugin>
74+
<groupId>org.apache.maven.plugins</groupId>
75+
<artifactId>maven-shade-plugin</artifactId>
76+
<version>3.2.1</version>
77+
<executions>
78+
<execution>
79+
<phase>package</phase>
80+
<goals>
81+
<goal>shade</goal>
82+
</goals>
83+
<configuration>
84+
<createDependencyReducedPom>false</createDependencyReducedPom>
85+
<transformers>
86+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
87+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
88+
<mainClass>com.github.mtf90.Main</mainClass>
89+
</transformer>
90+
</transformers>
91+
</configuration>
92+
</execution>
93+
</executions>
94+
</plugin>
95+
</plugins>
96+
</build>
97+
</project>
98+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.github.mtf90;
2+
3+
import py4j.GatewayServer;
4+
5+
public class Main {
6+
7+
public static void main(String[] args) {
8+
GatewayServer server = new GatewayServer();
9+
server.start();
10+
}
11+
}

python/Main.py

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from py4j.java_gateway import JavaGateway, CallbackServerParameters
2+
3+
4+
class PySUL:
5+
6+
def __init__(self, gateway):
7+
self.alphabet = gateway.jvm.net.automatalib.words.impl.Alphabets.characters('a', 'b')
8+
self.state = 0
9+
10+
def pre(self):
11+
self.state = 0
12+
13+
def post(self): pass
14+
15+
def step(self, sulInput):
16+
if sulInput == 'b':
17+
self.state = (self.state + 1) % 2
18+
return 'b'
19+
20+
return '0' if self.state == 0 else '1'
21+
22+
def canFork(self):
23+
return False
24+
25+
def fork(self): pass
26+
27+
class Java:
28+
implements = ["de.learnlib.api.SUL"]
29+
30+
31+
def main():
32+
gateway = JavaGateway(callback_server_parameters=CallbackServerParameters())
33+
34+
sul = PySUL(gateway)
35+
alphabet = sul.alphabet
36+
37+
mq_oracle = gateway.jvm.de.learnlib.oracle.membership.SULOracle(sul)
38+
eq_oracle = gateway.jvm.de.learnlib.oracle.equivalence.WMethodEQOracle(mq_oracle, 3)
39+
40+
ttt = gateway.jvm.de.learnlib.algorithms.ttt.mealy.TTTLearnerMealyBuilder() \
41+
.withAlphabet(alphabet) \
42+
.withOracle(mq_oracle) \
43+
.create()
44+
45+
experiment = gateway.jvm.de.learnlib.util.Experiment(ttt, eq_oracle, alphabet)
46+
experiment.run()
47+
48+
hyp = experiment.getFinalHypothesis()
49+
50+
string_writer = gateway.jvm.java.io.StringWriter()
51+
52+
gateway.jvm.net.automatalib.serialization.dot.GraphDOT.write(hyp, alphabet, string_writer,
53+
# While varargs allow us to skip this parameter in Java, the method signature expects an array \
54+
gateway.new_array(
55+
gateway.jvm.net.automatalib.serialization.dot.DOTVisualizationHelper,
56+
0))
57+
58+
print("Learned model in DOT format:")
59+
print()
60+
print(string_writer.toString())
61+
62+
gateway.jvm.net.automatalib.visualization.Visualization.visualize(hyp, alphabet,
63+
# While varargs allow us to skip this parameter in Java, the method signature expects an array \
64+
gateway.new_array(
65+
gateway.jvm.net.automatalib.visualization.VisualizationHelper,
66+
0))
67+
68+
gateway.close()
69+
70+
71+
if __name__ == "__main__":
72+
main()

0 commit comments

Comments
 (0)