From d0373e987049e002bc9088805ca107deb9ae3729 Mon Sep 17 00:00:00 2001 From: Eric Joanis Date: Fri, 1 Sep 2023 14:21:30 -0400 Subject: [PATCH] test: MRE for #283 shows swallowed edge after 1->2+2->1 --- g2p/tests/test_mappings.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/g2p/tests/test_mappings.py b/g2p/tests/test_mappings.py index dc91f992..34b3bc44 100755 --- a/g2p/tests/test_mappings.py +++ b/g2p/tests/test_mappings.py @@ -395,6 +395,42 @@ def test_g2p_studio_csv(self): ) os.unlink(tf.name) + def test_vanishing_edge(self): + """1->2+2->1 should not eat the next edge""" + mapping = Mapping(rules=[{"in": "d{1}ef{2}", "out": "gh{1}i{2}"}]) + transducer = Transducer(mapping) + # the rule itself works, with the indices doing what they're supposed to do + tg = transducer("def") + self.assertEqual(tg.output_string, "ghi") + self.assertEqual(tg.alignments(), [(0, 0), (0, 1), (1, 2), (2, 2)]) + # but it swallows the next edge + tg = transducer("deft") + self.assertEqual(tg.output_string, "ghit") + # with vanishing edge bug, the following fails, getting only [(0, 0), (0, 1), (1, 2), (2, 2)] + self.assertEqual(tg.alignments(), [(0, 0), (0, 1), (1, 2), (2, 2), (3, 3)]) + + # make sure the fix works with "complex" cases too + tg = transducer("deftdefdef") + self.assertEqual(tg.output_string, "ghitghighi") + self.assertEqual( + tg.alignments(), + [ + (0, 0), + (0, 1), + (1, 2), + (2, 2), + (3, 3), + (4, 4), + (4, 5), + (5, 6), + (6, 6), + (7, 7), + (7, 8), + (8, 9), + (9, 9), + ], + ) + if __name__ == "__main__": main()