1

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)
Community
  • 1
  • 1
  • 1
    It would be nice if you could specify what mapping between input and output you observe in contrast to the mapping you expected (which you've already shown). – Captain Trojan Jul 13 '21 at 12:32
  • I don't know what you mean by mapping, sorry. Basically what I want to observe are morphemes. My output should contain morphological information, I don't know how I will present that, that's why I just use any output for the moment. Don't know if that answers your question. – Evangelos F. Jul 13 '21 at 12:40
  • Your expected mapping: `"oa" -> "positive" + empty; "aa" -> "0"; "o" -> "0"; etc`. Thats what you've shown in your first code fragment. I am curious about what you actually observe when you use your code. – Captain Trojan Jul 13 '21 at 12:54
  • Okay, so this is just one of many rules I need. You have a word starting with "o" then you output the morphological information for the "o", lets say `"NUM = Singular, PERSON = 1"` . The following characters of the word do not interest us, that's why I assumed that I just output "empty" for any given character following the "o". Solely the "o" have to occure in combination with other characters and must be in first place. – Evangelos F. Jul 13 '21 at 13:07

1 Answers1

0

The missing step is that lookup() will only return paths that end in a final state, which you can specify with transducer.set_final_weight(state, weight).

>>> import hfst
>>> t = hfst.HfstBasicTransducer()
>>> t.add_state(1)
1
>>> tr = hfst.HfstBasicTransition(1,'o', 'positive',0.0)
>>> t.add_transition(0,tr)
>>> t.set_final_weight(1,0.0)
>>> t.lookup('o')
{'o': [('positive', 0.0)]}
popcorndude
  • 123
  • 7