-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
175 lines (146 loc) · 5.04 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package main
import (
"bufio"
"fmt"
dfalearningtoolkit "github.com/Cherrett/DFA-Learning-Toolkit/core"
"os"
"strconv"
"strings"
)
func main() {
var dfa dfalearningtoolkit.DFA
var dataset dfalearningtoolkit.Dataset = nil
reader := bufio.NewReader(os.Stdin)
exit := false
restart := false
for !exit {
restart = false
fmt.Println("\nSelect from the following options\n1. Generate DFA and Dataset\n2. Read DFA/APTA from file\n3. Read Dataset from file\n4. Exit")
choice := readIntInput("Choice: ", reader)
// First main choice.
switch choice {
case 1:
// Generate DFA and Dataset
valid := false
for !valid {
fmt.Println("\nSelect from the following options\n1. Generate DFA and Dataset using the Abbadingo Protocol\n2. Generate DFA and Dataset using the Stamina Protocol")
choice = readIntInput("Choice: ", reader)
switch choice {
case 1:
valid = true
targetDFASize := readIntInput("Input size of target DFA: ", reader)
numberOfTrainingExamples := readIntInput("Input number of training examples: ", reader)
_, dataset, _ = dfalearningtoolkit.AbbadingoInstanceExact(targetDFASize, true, numberOfTrainingExamples, 0)
case 2:
valid = true
alphabetSize := readIntInput("Input alphabet size: ", reader)
targetDFASize := readIntInput("Input size of target DFA: ", reader)
sparsityPercentage := readFloatInput("Input sparsity percentage of training set (in floating point form): ", reader)
_, dataset, _ = dfalearningtoolkit.DefaultStaminaInstance(alphabetSize, targetDFASize, sparsityPercentage)
default:
fmt.Println("Invalid choice. Please choose from options 1-2.")
}
}
case 2:
// Read DFA/APTA from file
valid := false
for !valid {
fmt.Println("\nSelect from the following options\n1. Read DFA/APTA from JSON\n2. Read DFA/APTA from Stamina file")
choice = readIntInput("Choice: ", reader)
switch choice {
case 1:
valid = true
filePath := readInput("Input file path of JSON DFA file: ", reader)
dfa, valid = dfalearningtoolkit.DFAFromJSON(filePath)
case 2:
filePath := readInput("Input file path of Stamina DFA file: ", reader)
dfa = dfalearningtoolkit.GetDFAFromStaminaFile(filePath)
valid = true
default:
fmt.Println("Invalid choice. Please choose from options 1-2.")
}
}
case 3:
// Read Dataset from file
valid := false
for !valid {
fmt.Println("\nSelect from the following options\n1. Read Dataset from JSON\n2. Read Dataset from Abbadingo file\n3. Read Dataset from Stamina file")
choice = readIntInput("Choice: ", reader)
switch choice {
case 1:
valid = true
filePath := readInput("Input file path of JSON Dataset file: ", reader)
dataset, valid = dfalearningtoolkit.DatasetFromJSON(filePath)
case 2:
filePath := readInput("Input file path of Abbadingo Dataset file: ", reader)
dataset = dfalearningtoolkit.GetDatasetFromAbbadingoFile(filePath)
valid = true
case 3:
filePath := readInput("Input file path of Stamina Dataset file: ", reader)
dataset = dfalearningtoolkit.GetDatasetFromStaminaFile(filePath)
valid = true
default:
fmt.Println("Invalid choice. Please choose from options 1-2.")
}
}
case 4:
fmt.Println("Exiting.")
exit = true
default:
fmt.Println("Invalid choice. Please choose from options 1-4.")
restart = true
}
for !exit && !restart {
// Second main choice.
fmt.Println("\nSelect from the following options\n1. Run EDSM on DFA/APTA or Dataset generated/read\n2. Run RPNI on DFA/APTA or Dataset generated/read\n3. Run AutomataTeams on DFA or Dataset generated/read\n4. Visualisation of DFA/APTA\n5. Exit")
choice = readIntInput("Choice: ", reader)
switch choice {
case 1:
case 2:
case 3:
case 4:
case 5:
fmt.Println("Exiting.")
exit = true
default:
fmt.Println("Invalid choice. Please choose from options 1-4.")
}
dfa.ToJSON("")
dataset.ToJSON("")
}
}
}
func readInput(prompt string, reader *bufio.Reader) string {
fmt.Print(prompt)
value, err := reader.ReadString('\n')
if err != nil {
fmt.Println("Invalid input.")
fmt.Print(prompt)
value, err = reader.ReadString('\n')
}
return strings.TrimRight(value, "\r\n")
}
func readIntInput(prompt string, reader *bufio.Reader) int {
fmt.Print(prompt)
value, err := reader.ReadString('\n')
intValue, err2 := strconv.Atoi(strings.TrimRight(value, "\r\n"))
if err != nil || err2 != nil {
fmt.Println("Invalid input.")
fmt.Print(prompt)
value, err = reader.ReadString('\n')
intValue, err2 = strconv.Atoi(strings.TrimRight(value, "\r\n"))
}
return intValue
}
func readFloatInput(prompt string, reader *bufio.Reader) float64 {
fmt.Print(prompt)
value, err := reader.ReadString('\n')
floatValue, err2 := strconv.ParseFloat(strings.TrimRight(value, "\r\n"), 64)
if err != nil || err2 != nil {
fmt.Println("Invalid input.")
fmt.Print(prompt)
value, err = reader.ReadString('\n')
floatValue, err2 = strconv.ParseFloat(strings.TrimRight(value, "\r\n"), 64)
}
return floatValue
}