I got in touch with tranducers and python, so i use default FST library. For example, I have a list ['a','b','c']
. I need to replace 'b'
if it is followed by 'c'
. I make following rules, but it works only if 'b'
is between 'a'
and 'c'
and only with this length of array.
from fst import fst
list = ['a','b','c']
t = fst.FST('example')
for i in range(0,len(list)):
t.add_state(str(i))
t.initial_state = '0'
t.add_arc('0','0',('a'),('a'))
t.add_arc('0','1',('b'),('d'))
t.add_arc('1','1',('c'),('c'))
t.set_final('1')
print t.transduce(list)
I got ['a','d','c']
I need to be able replace 'b'
with 'd'
wherever it is.
e.g. replace 'b'
when followed by 'l'
['m','r','b','l'] => ['m','r','o','l']
['m','b','l'] => ['m','o','l']
['b','l','o'] => ['o','l','o']
Please help me, thanks!
Consider this function...
You should add other pertinent validations, though.