Closed chuikova-e closed 3 years ago
You want to do the composition state by state, manually? I'm not sure why you'd want this, but it's not that hard to do. If your WFST is f
then you can use f.states()
to get an iterator over the states (in numeric order) and a f.arcs(stateid)
to get an iterator over the arcs leaving a state.
Can it be implemented depending on the input word?
for example, If WFST in 0 state receives "fat" it moves to 1 state, but if it receives "dog", it moves to 2 state.
Yes, but you'll have to implement it yourself! That's just the definition of composition. So if you're in state 0 you have to iterate over the arcs using something like:
curr_state = f.start()
while ...:
label_to_match = syms.find("fat")
for arc in f.arcs(curr_state):
if arc.ilabel == label_to_match:
curr_state = arc.nextstate
Also, it'll be really slow. If you actually want to compose a string with an FST use pynini.compose
or the overloaded @
operator: "[fat foot cat]" @ f
might work.
Thank you very much for your help!!
Hello, can I somehow implement moving between states in the following way?
My wfst:
Step 0. WFST at zero state Step 1. Word "fat" received, WFST moves to state 1 Step 2. Word "foot" received, WFST moves to state 3 Step 2. Word "cat" received, WFST moves to state 2
Words are sequentially fed to the WFST