-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfsmutils.py
More file actions
51 lines (41 loc) · 1.21 KB
/
Copy pathfsmutils.py
File metadata and controls
51 lines (41 loc) · 1.21 KB
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
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
import string
from fst import FST
# This function returns fn o ... o f3 o f2 o f1 (input)
# where ALL transducers use characters as input symbols
def compose(input, *fsts):
output_list = [input]
for fst in fsts:
next_output_list = []
for o in output_list:
new_output = ''.join(o)
next_output_list.extend(fst.transduce(new_output))
output_list = next_output_list
return output_list
if __name__ == '__main__':
f1 = FST('test-generate')
# Indicate that '1' is the initial state
f1.add_state('start')
f1.add_state('next')
f1.initial_state = 'start'
# Set all the final states
f1.set_final('next')
# Add the rest of the arcs
for letter in ['A','B','C','D']:
f1.add_arc('start', 'next', letter, '1')
f1.add_arc('next', 'next', letter, '0')
f2 = FST('test-generate')
f2.add_state('start')
f2.add_state('next')
f2.initial_state = 'start'
f2.set_final('next')
f2.add_arc('start', 'next', '1', 'a')
f2.add_arc('start', 'next', '1', 'an')
f2.add_arc('next', 'next', '0', 'b')
output = compose(tuple('BAD'), f1, f2)
print(output)
for o in output:
print(compose(tuple(o), f2.inverted(), f1.inverted()))