I have a finite ordered list of rewrite rules. These rules do not have any context, and each rewrite rule replaces a string with a string of less than or equal length.
I would like to do a left to right search and replace using these rules, allowing overlaps between outputs and inputs, using the following algorithm:
- Start with a cursor at the left side of the word to be processed.
- If the left hand side of one of my rewrite rules appears starting at the cursor, apply the corresponding rule. (If more than one left hand side appears, use the one that appears first in my list.)
- If the input and output of the rewrite rule have the same length, move the cursor one to the right. If the output is strictly smaller than the input, leave the cursor where it is.
- Repeat.
What is the easiest way to build the transducer that accomplishes this, using pynini?
If there is a clever way to do it, I’d be happy to learn this. Otherwise, I can build it manually… but actually I am new to pynini and I don’t yet know how to build tranducers manually in pynini by adding states and arrows, so if someone could point me to an examples or instructions on how to do this it would be helpful.
Alex Wright is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.