def test_multiple_weights(self): """Multiple intents should have balanced weights.""" intents = parse_ini(""" [TestIntent1] this is a test [TestIntent2] this is a test """) graph = intents_to_graph(intents) fst = graph_to_fst(graph) print(fst) self.assertEqual( fst, GraphFst( intent_fst="0 1 <eps> __label__TestIntent1 0.5\n" "1 2 this this 0\n" "2 3 is is 0\n" "3 4 a a 0\n" "4 5 test test 0\n" "5 6 <eps> <eps> 0\n" "0 7 <eps> __label__TestIntent2 0.5\n" "7 8 this this 0\n" "8 9 is is 0\n" "9 10 a a 0\n" "10 11 test test 0\n" "11 6 <eps> <eps> 0\n" "6\n", symbols={ "<eps>": 0, "__label__TestIntent1": 1, "this": 2, "is": 3, "a": 4, "test": 5, "__label__TestIntent2": 6, }, input_symbols={ "<eps>": 0, "this": 2, "is": 3, "a": 4, "test": 5 }, output_symbols={ "<eps>": 0, "__label__TestIntent1": 1, "this": 2, "is": 3, "a": 4, "test": 5, "__label__TestIntent2": 6, }, ), )
def test_multiple_weights(self): """Multiple intents should have balanced weights.""" intents = parse_ini(""" [TestIntent1] this is a test [TestIntent2] this is a test """) graph = intents_to_graph(intents) fst = graph_to_fst(graph) self.assertEqual( fst, GraphFst( intent_fst="0 1 <eps> __label__TestIntent1 0.5\n" "0 2 <eps> __label__TestIntent2 0.5\n" "1 3 this this 0\n" "2 4 this this 0\n" "3 5 is is 0\n" "4 6 is is 0\n" "5 7 a a 0\n" "6 8 a a 0\n" "7 9 test test 0\n" "8 10 test test 0\n" "9 11 <eps> <eps> 0\n" "10 11 <eps> <eps> 0\n" "11\n", symbols={ "<eps>": 0, "__label__TestIntent1": 1, "__label__TestIntent2": 2, "this": 3, "is": 4, "a": 5, "test": 6, }, input_symbols={ "<eps>": 0, "this": 3, "is": 4, "a": 5, "test": 6 }, output_symbols={ "<eps>": 0, "__label__TestIntent1": 1, "__label__TestIntent2": 2, "this": 3, "is": 4, "a": 5, "test": 6, }, ), )
def test_intent_filter_single_fst(self): """Test multiple intents, single FST with an intent filter.""" intents = parse_ini(""" [TestIntent1] this is a test [TestIntent2] this is another test """) graph = intents_to_graph(intents) fst = graph_to_fst( graph, intent_filter=lambda intent: intent == "TestIntent1") print(fst) self.assertEqual( fst, GraphFst( intent_fst="0 1 <eps> __label__TestIntent1 0.5\n" "1 2 this this 0\n" "2 3 is is 0\n" "3 4 a a 0\n" "4 5 test test 0\n" "5 6 <eps> <eps> 0\n" "6\n", symbols={ "<eps>": 0, "__label__TestIntent1": 1, "this": 2, "is": 3, "a": 4, "test": 5, }, input_symbols={ "<eps>": 0, "this": 2, "is": 3, "a": 4, "test": 5 }, output_symbols={ "<eps>": 0, "__label__TestIntent1": 1, "this": 2, "is": 3, "a": 4, "test": 5, }, ), )
def test_one_weight(self): """Single intent should have an edge weight of 0.""" intents = parse_ini(""" [TestIntent] this is a test """) graph = intents_to_graph(intents) fst = graph_to_fst(graph) self.assertEqual( fst, GraphFst( intent_fst="0 1 <eps> __label__TestIntent 0\n" "1 2 this this 0\n" "2 3 is is 0\n" "3 4 a a 0\n" "4 5 test test 0\n" "5 6 <eps> <eps> 0\n" "6\n", symbols={ "<eps>": 0, "__label__TestIntent": 1, "this": 2, "is": 3, "a": 4, "test": 5, }, input_symbols={ "<eps>": 0, "this": 2, "is": 3, "a": 4, "test": 5 }, output_symbols={ "<eps>": 0, "__label__TestIntent": 1, "this": 2, "is": 3, "a": 4, "test": 5, }, ), )