@@ -25,13 +25,13 @@ def get_state_name(state_data):
25
25
uses `str` for any unsupported python data types.
26
26
"""
27
27
if isinstance (state_data , str ):
28
- if state_data == "" :
29
- return "λ"
28
+ if state_data == '' :
29
+ return 'λ'
30
30
31
31
return state_data
32
32
33
33
if isinstance (state_data , (set , frozenset , list , tuple )):
34
- inner = ", " .join (FA .get_state_name (sub_data ) for sub_data in state_data )
34
+ inner = ', ' .join (FA .get_state_name (sub_data ) for sub_data in state_data )
35
35
if isinstance (state_data , (set , frozenset )):
36
36
return '{' + inner + '}'
37
37
@@ -62,7 +62,7 @@ def is_accepting(self, state):
62
62
def is_initial (self , state ):
63
63
"""Check if a state is an initial state."""
64
64
65
- def show (
65
+ def show_diagram (
66
66
self ,
67
67
input_str : str | None = None ,
68
68
save_path : str | os .PathLike | None = None ,
@@ -95,7 +95,7 @@ def show(
95
95
Digraph: The graph in dot format.
96
96
"""
97
97
# Converting to graphviz preferred input type,
98
- # keeping the conventional input styles; i.e fig_size(8,8)
98
+ # keeping the conventional input styles; i.e fig_size(8, 8)
99
99
# TODO why is (8, 8) the "conventional" size?
100
100
fig_size = ", " .join (map (str , fig_size ))
101
101
font_size = str (font_size )
@@ -109,12 +109,12 @@ def show(
109
109
ranksep = state_separation ,
110
110
)
111
111
if horizontal :
112
- graph .attr (rankdir = "LR" )
112
+ graph .attr (rankdir = 'LR' )
113
113
if reverse_orientation :
114
114
if horizontal :
115
- graph .attr (rankdir = "RL" )
115
+ graph .attr (rankdir = 'RL' )
116
116
else :
117
- graph .attr (rankdir = "BT" )
117
+ graph .attr (rankdir = 'BT' )
118
118
119
119
for state in self .iter_states ():
120
120
# every edge needs an origin node, so we add a null node for every
@@ -125,12 +125,12 @@ def show(
125
125
null_node = str (uuid .uuid4 ())
126
126
graph .node (
127
127
null_node ,
128
- label = "" ,
128
+ label = '' ,
129
129
shape = 'point' ,
130
130
fontsize = font_size ,
131
131
)
132
132
node = self .get_state_name (state )
133
- edge_label = "->" + node
133
+ edge_label = '->' + node
134
134
graph .edge (
135
135
null_node ,
136
136
node ,
@@ -147,13 +147,13 @@ def show(
147
147
edge_labels = defaultdict (list )
148
148
for from_state , to_state , symbol in self .iter_transitions ():
149
149
# TODO only do this for NFA
150
- label = "ε" if symbol == "" else str (symbol )
150
+ label = 'ε' if symbol == '' else str (symbol )
151
151
from_node = self .get_state_name (from_state )
152
152
to_node = self .get_state_name (to_state )
153
153
edge_labels [from_node , to_node ].append (label )
154
154
155
155
for (from_node , to_node ), labels in edge_labels .items ():
156
- label = "," .join (sorted (labels ))
156
+ label = ',' .join (sorted (labels ))
157
157
graph .edge (
158
158
from_node ,
159
159
to_node ,
@@ -164,7 +164,7 @@ def show(
164
164
else :
165
165
# TODO
166
166
raise NotImplementedError (
167
- " input_str is not yet supported yet"
167
+ ' input_str is not yet supported yet'
168
168
)
169
169
170
170
status , taken_transitions_pairs , taken_steps = self .input_check (
@@ -177,8 +177,8 @@ def show(
177
177
if x not in taken_transitions_pairs
178
178
]
179
179
180
- start_color = Color (" #FFFF00" )
181
- end_color = Color (" #00FF00" ) if status else Color (" #FF0000" )
180
+ start_color = Color (' #FFFF00' )
181
+ end_color = Color (' #00FF00' ) if status else Color (' #FF0000' )
182
182
183
183
number_of_colors = len (input_str )
184
184
interpolation = Color .interpolate ([start_color , end_color ], space = 'lch' )
@@ -196,18 +196,18 @@ def show(
196
196
graph .edge (
197
197
pair [0 ],
198
198
pair [1 ],
199
- label = " [{}]\n {} " .format (counter , pair [2 ]),
199
+ label = ' [{}]\n {} ' .format (counter , pair [2 ]),
200
200
arrowsize = arrow_size ,
201
201
fontsize = font_size ,
202
202
color = edge_color .to_string (hex = True ),
203
- penwidth = " 2.5" ,
203
+ penwidth = ' 2.5' ,
204
204
)
205
205
206
206
for pair in remaining_transitions_pairs :
207
207
graph .edge (
208
208
pair [0 ],
209
209
pair [1 ],
210
- label = " {} " .format (pair [2 ]),
210
+ label = ' {} ' .format (pair [2 ]),
211
211
arrowsize = arrow_size ,
212
212
fontsize = font_size ,
213
213
)
@@ -243,4 +243,4 @@ def _ipython_display_(self):
243
243
# IPython. So if IPython is not installed, this function will not be
244
244
# called, therefore no need to add ipython as dependency.
245
245
from IPython .display import display
246
- display (self .show ())
246
+ display (self .show_diagram ())
0 commit comments