kylebgorman / pynini

Read-only mirror of Pynini
http://pynini.opengrm.org
Apache License 2.0
118 stars 27 forks source link

Moving between states #33

Closed chuikova-e closed 3 years ago

chuikova-e commented 3 years ago

Hello, can I somehow implement moving between states in the following way?

My wfst:

image

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

kylebgorman commented 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.

chuikova-e commented 3 years ago

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.

kylebgorman commented 3 years ago

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.

chuikova-e commented 3 years ago

Thank you very much for your help!!