Пример #1
0
 def test_tag_word(self):
     """Tag a word."""
     s = Sentence.parse("this{is} a{test}")
     self.assertEqual(
         s.items,
         [Word("this", tag=Tag(tag_text="is")), Word("a", tag=Tag(tag_text="test"))],
     )
Пример #2
0
 def test_sequence_substition_in_alternative(self):
     """Test sequence substitution inside an alternative."""
     s = Sentence.parse(
         "((light one):light_1 | (light two):light_2) {name} :domain{light}"
     )
     self.assertEqual(
         s.items,
         [
             Sequence(
                 text="(light one):light_1 | (light two):light_2",
                 type=SequenceType.ALTERNATIVE,
                 tag=Tag(tag_text="name"),
                 items=[
                     Sequence(
                         text="light one",
                         substitution="light_1",
                         type=SequenceType.GROUP,
                         items=[Word("light"), Word("one")],
                     ),
                     Sequence(
                         text="light two",
                         substitution="light_2",
                         type=SequenceType.GROUP,
                         items=[Word("light"), Word("two")],
                     ),
                 ],
             ),
             Word(text="", substitution="domain", tag=Tag(tag_text="light")),
         ],
     )
Пример #3
0
 def test_den_overhead(self):
     """Sequence of optionals/alternatives plus tag substitution."""
     s = Sentence.parse(
         "toggle [the] (den | playroom) [light] {light_name:den_overhead}")
     self.assertEqual(
         s.items,
         [
             Word("toggle"),
             Sequence(
                 text="the",
                 type=SequenceType.ALTERNATIVE,
                 items=[Word("the"), Word("")],
             ),
             Sequence(
                 text="den | playroom",
                 type=SequenceType.GROUP,
                 items=[
                     Sequence(
                         text="den | playroom",
                         type=SequenceType.ALTERNATIVE,
                         items=[Word("den"), Word("playroom")],
                     )
                 ],
             ),
             Sequence(
                 text="light",
                 type=SequenceType.ALTERNATIVE,
                 items=[Word("light"), Word("")],
                 tag=Tag(tag_text="light_name",
                         substitution="den_overhead"),
             ),
         ],
     )
Пример #4
0
 def test_tagged_group_in_optional(self):
     """Tagged group inside an optional."""
     s = Sentence.parse("this is a [($test){tag}]")
     self.assertEqual(
         s.items,
         [
             Word("this"),
             Word("is"),
             Word("a"),
             Sequence(
                 text="($test){tag}",
                 type=SequenceType.ALTERNATIVE,
                 items=[
                     Sequence(
                         text="$test",
                         type=SequenceType.GROUP,
                         tag=Tag(tag_text="tag"),
                         items=[
                             SlotReference(slot_name="test", text="$test")
                         ],
                     ),
                     Word(""),
                 ],
             ),
         ],
     )
Пример #5
0
 def test_entity_converters(self):
     """Test multiple converters on a tag/entity"""
     s = Sentence.parse("this is a{test!c1!c2}")
     self.assertEqual(
         s.items,
         [
             Word("this"),
             Word("is"),
             Word("a", tag=Tag(tag_text="test", converters=["c1", "c2"])),
         ],
     )
Пример #6
0
 def test_tag_alternative(self):
     """Tag an alternative."""
     s = Sentence.parse("[this is a]{test}")
     self.assertEqual(s.tag, Tag(tag_text="test"))
     self.assertEqual(
         s.items,
         [
             Sequence(
                 text="this is a",
                 type=SequenceType.GROUP,
                 items=[Word("this"), Word("is"), Word("a")],
             ),
             Word(""),
         ],
     )
Пример #7
0
    def test_final_optional_entity(self):
        """Ensure final optional entity has tag."""

        ini_text = """
        [ChangeDisplay]
        display [(page | layer){layout}]
        """

        intents = parse_ini(ini_text)
        self.assertEqual(
            intents,
            {
                "ChangeDisplay": [
                    Sentence(
                        text="display [(page | layer){layout}]",
                        items=[
                            Word("display"),
                            Sequence(
                                text="(page | layer){layout}",
                                type=SequenceType.ALTERNATIVE,
                                items=[
                                    Sequence(
                                        text="page | layer",
                                        type=SequenceType.GROUP,
                                        tag=Tag(tag_text="layout"),
                                        items=[
                                            Sequence(
                                                text="page | layer",
                                                type=SequenceType.ALTERNATIVE,
                                                items=[
                                                    Word("page"),
                                                    Word("layer")
                                                ],
                                            )
                                        ],
                                    ),
                                    Word(""),
                                ],
                            ),
                        ],
                    )
                ]
            },
        )
Пример #8
0
 def test_tag_and_word_substitution(self):
     """Tag and word substitutions."""
     s = Sentence.parse("(this:is){a:test}")
     group = s.items[0]
     self.assertEqual(group.tag, Tag(tag_text="a", substitution="test"))
     self.assertEqual(group.items, [Word("this", substitution="is")])
Пример #9
0
 def test_tag_group(self):
     """Tag a group."""
     s = Sentence.parse("(this is a){test}")
     group = s.items[0]
     self.assertEqual(group.tag, Tag(tag_text="test"))
     self.assertEqual(group.items, [Word("this"), Word("is"), Word("a")])
Пример #10
0
 def test_tag_substitution(self):
     """Tag substitution."""
     s = Sentence.parse("(this is){a:test}")
     self.assertEqual(s.tag, Tag(tag_text="a", substitution="test"))
     self.assertEqual(s.items, [Word("this"), Word("is")])