kylebgorman / pynini

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

Determining if a state is accepting #45

Closed kalvinchang closed 3 years ago

kalvinchang commented 3 years ago

Currently, I am determining if a state is an accepting state with the following: fsa.final(state) == pynini.Weight.one('tropical')

However, this approach is flawed if we set the weight of a state to 1. Is there a better way of figuring out if a state is accepting or not?

kylebgorman commented 3 years ago

Why not just:

def accepting(fst: pynini.Fst, state: int) -> bool:
    return fst.final(state) != pynini.Weight.zero(fst.arc_type())

?

kalvinchang commented 3 years ago

oh that works too. Thanks!!