Esempio n. 1
0
    def test_multiple_sentences(self):
        """Test multiple intents."""
        intents = parse_ini("""
        [TestIntent1]
        this is a test

        [TestIntent2]
        this is another test
        """)

        graph = intents_to_graph(intents)
        fsts = graph_to_fsts(graph)
        self.assertEqual(
            fsts,
            GraphFsts(
                intent_fsts={
                    "TestIntent1":
                    "0 1 this this 0\n"
                    "1 2 is is 0\n"
                    "2 3 a a 0\n"
                    "3 4 test test 0\n"
                    "4 5 <eps> <eps> 0\n"
                    "5\n",
                    "TestIntent2":
                    "0 1 this this 0\n"
                    "1 2 is is 0\n"
                    "2 3 another another 0\n"
                    "3 4 test test 0\n"
                    "4 5 <eps> <eps> 0\n"
                    "5\n",
                },
                symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "test": 4,
                    "another": 5,
                },
                input_symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "test": 4,
                    "another": 5,
                },
                output_symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "test": 4,
                    "another": 5,
                },
            ),
        )
Esempio n. 2
0
    def test_intent_filter_multiple_fsts(self):
        """Test multiple intents, multiple FSTs with an intent filter."""
        intents = parse_ini("""
        [TestIntent1]
        this is a test

        [TestIntent2]
        this is another test
        """)

        graph = intents_to_graph(intents)
        fsts = graph_to_fsts(
            graph, intent_filter=lambda intent: intent == "TestIntent1")
        self.assertEqual(
            fsts,
            GraphFsts(
                intent_fsts={
                    "TestIntent1":
                    "0 1 this this 0\n"
                    "1 2 is is 0\n"
                    "2 3 a a 0\n"
                    "3 4 test test 0\n"
                    "4 5 <eps> <eps> 0\n"
                    "5\n"
                },
                symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "test": 4
                },
                input_symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "test": 4
                },
                output_symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "test": 4
                },
            ),
        )
Esempio n. 3
0
    def test_optional(self):
        """Test one intent, one sentence with an optional word."""
        intents = parse_ini("""
        [TestIntent]
        this is [a] test
        """)

        graph = intents_to_graph(intents)
        fsts = graph_to_fsts(graph)
        self.assertEqual(
            fsts,
            GraphFsts(
                intent_fsts={
                    "TestIntent":
                    "0 1 this this 0\n"
                    "1 2 is is 0\n"
                    "2 3 a a 0\n"
                    "2 4 <eps> <eps> 0\n"
                    "3 5 <eps> <eps> 0\n"
                    "4 5 <eps> <eps> 0\n"
                    "5 6 test test 0\n"
                    "6 7 <eps> <eps> 0\n"
                    "7\n"
                },
                symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "test": 4
                },
                input_symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "test": 4
                },
                output_symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "test": 4
                },
            ),
        )
Esempio n. 4
0
    def test_substitution(self):
        """Test one intent, one sentence with a substitution."""
        intents = parse_ini("""
        [TestIntent]
        this is a test:sub
        """)

        graph = intents_to_graph(intents)
        fsts = graph_to_fsts(graph)
        self.assertEqual(
            fsts,
            GraphFsts(
                intent_fsts={
                    "TestIntent":
                    "0 1 this this 0\n"
                    "1 2 is is 0\n"
                    "2 3 a a 0\n"
                    "3 4 test <eps> 0\n"
                    "4 5 <eps> sub 0\n"
                    "5 6 <eps> <eps> 0\n"
                    "6\n"
                },
                symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "test": 4,
                    "sub": 5
                },
                input_symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "test": 4
                },
                output_symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "sub": 5
                },
            ),
        )
Esempio n. 5
0
    def test_single_sentence(self):
        """Test one intent, one sentence."""
        intents = parse_ini("""
        [TestIntent]
        this is a test
        """)

        graph = intents_to_graph(intents)
        fsts = graph_to_fsts(graph)
        self.assertEqual(
            fsts,
            GraphFsts(
                intent_fsts={
                    "TestIntent":
                    "0 1 this this 0\n"
                    "1 2 is is 0\n"
                    "2 3 a a 0\n"
                    "3 4 test test 0\n"
                    "4 5 <eps> <eps> 0\n"
                    "5\n"
                },
                symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "test": 4
                },
                input_symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "test": 4
                },
                output_symbols={
                    "<eps>": 0,
                    "this": 1,
                    "is": 2,
                    "a": 3,
                    "test": 4
                },
            ),
        )