I am trying to set up a Finite State Transducer with Helsinki Finite State Technology (HFST) for Python.
I want if the first character of a word is an 'o' the output is "Positive" and if there are characters following in the same word, output empty for every character by using regex.
But I don't accept only "o".
e.g. "oa" = "positive" , empty
"aa" = 0
"o" = 0
What I got so far from the HFST tutorials:
t = hfst.HfstBasicTransducer()
t.add_state(1)
t.add_state(2)
tr = hfst.HfstBasicTransition(1,"o","positive",0.0)
tr2 = hfst.regex("?:0")
t.add_transition(0,1,tr)
t.add_transition(1,2, tr2)
The missing step is that
lookup()
will only return paths that end in a final state, which you can specify withtransducer.set_final_weight(state, weight)
.