Ejemplo n.º 1
0
 def test_utterance_patterns_with_range_and_non_range(self) -> None:
     artists = ('the beatles', 'kanye', 'nico', 'tom waits')
     dynamic_token_patterns_map = {'ARTIST': artists}
     pattern_def = _load_pattern_def(
         self._base_dir / 'utterance_patterns_with_range_and_non_range.yml')
     _, generator = expand(
         pattern_def, dynamic_token_patterns_map=dynamic_token_patterns_map)
     actual_utterance_combo, actual_tokens, actual_groups = zip(*generator)
     expected_utterance_combo = (
         (('she wants', ), ),
         (('she wants', ), ('to play', ), artists),
         (('she wants', ), ('to play', ), artists, ('to play', ), artists),
         (('she wants', ), ('to play', ), artists, ('to play', ), artists,
          ('to play', ), artists),
     )
     expected_tokens = (
         ('START', ),
         ('START', 'PLAY', 'ARTIST'),
         ('START', 'PLAY', 'ARTIST', 'PLAY', 'ARTIST'),
         ('START', 'PLAY', 'ARTIST', 'PLAY', 'ARTIST', 'PLAY', 'ARTIST'),
     )
     expected_groups = (
         (('None', 1), ),
         (('None', 1), ('PLAY_ARTIST', 2)),
         (('None', 1), ('PLAY_ARTIST', 2), ('PLAY_ARTIST', 2)),
         (('None', 1), ('PLAY_ARTIST', 2), ('PLAY_ARTIST', 2),
          ('PLAY_ARTIST', 2)),
     )
     pairs = [(actual_utterance_combo, expected_utterance_combo),
              (actual_tokens, expected_tokens),
              (actual_groups, expected_groups)]
     compare_all_pairs(self, pairs)
Ejemplo n.º 2
0
 def test_static_and_base_tokens(self) -> None:
     pattern_def = _load_pattern_def(self._base_dir /
                                     'static_and_base_tokens.yml')
     _, generator = expand(pattern_def)
     actual_utterance_combo, actual_tokens, actual_groups = zip(*generator)
     expected_utterance_combo = ((('he will want', 'she will want'),
                                  ('to play', 'to listen')), )
     expected_tokens = (('START', 'PLAY'), )
     expected_groups = ((('None', 1), ('None', 1)), )
     pairs = [(actual_utterance_combo, expected_utterance_combo),
              (actual_tokens, expected_tokens),
              (actual_groups, expected_groups)]
     compare_all_pairs(self, pairs)
Ejemplo n.º 3
0
 def test_dynamic_token_patterns_only(self) -> None:
     dynamic_token_patterns_map = {'ARTIST': ('the beatles', 'kanye')}
     pattern_def = _load_pattern_def(self._base_dir /
                                     'dynamic_token_patterns_only.yml')
     expected_utterance_combo = ((('the beatles', 'kanye'), ), )
     expected_tokens = (('ARTIST', ), )
     expected_groups = (((('None', 1)), ), )
     _, generator = expand(
         pattern_def, dynamic_token_patterns_map=dynamic_token_patterns_map)
     actual_utterance_combo, actual_tokens, actual_groups = zip(*generator)
     pairs = [(actual_utterance_combo, expected_utterance_combo),
              (actual_tokens, expected_tokens),
              (actual_groups, expected_groups)]
     compare_all_pairs(self, pairs)
Ejemplo n.º 4
0
 def test_token_and_default_token_handler(self) -> None:
     # pylint: disable=too-many-locals
     _start_token_handler = lambda token, tokenized_phrase: '[{}]'.format(
         token)
     _default_token_handler = lambda token, tokenized_phrase: '[{}(default)]'.format(
         token)
     utterance_combo = (('he will want', 'she will want'), ('to play',
                                                            'to listen'))
     tokens = ('START', 'PLAY')
     groups = (('None', 1), ('None', 1))
     token_handler_map = {
         'START': _start_token_handler,
         'DEFAULT': _default_token_handler
     }
     _, generator = combine(utterance_combo,
                            tokens,
                            groups,
                            token_handler_map=token_handler_map)
     actual_utterances, actual_handled_tokens, actual_handled_groups = zip(
         *generator)
     expected_utterances = ('he will want to play',
                            'he will want to listen',
                            'she will want to play',
                            'she will want to listen')
     expected_handled_tokens = ((
         '[START]',
         '[PLAY(default)]',
     ), (
         '[START]',
         '[PLAY(default)]',
     ), (
         '[START]',
         '[PLAY(default)]',
     ), (
         '[START]',
         '[PLAY(default)]',
     ))
     expected_handled_groups = (('{None([START])}',
                                 '{None([PLAY(default)])}'),
                                ('{None([START])}',
                                 '{None([PLAY(default)])}'),
                                ('{None([START])}',
                                 '{None([PLAY(default)])}'),
                                ('{None([START])}',
                                 '{None([PLAY(default)])}'))
     pairs = [(actual_utterances, expected_utterances),
              (actual_handled_tokens, expected_handled_tokens),
              (actual_handled_groups, expected_handled_groups)]
     compare_all_pairs(self, pairs)
Ejemplo n.º 5
0
 def test_dynamic_and_static_token_patterns(self) -> None:
     dynamic_token_patterns_map = {'ARTIST': ('the beatles', 'kanye')}
     pattern_def = _load_pattern_def(
         self._base_dir / 'dynamic_and_static_token_patterns.yml')
     _, generator = expand(
         pattern_def, dynamic_token_patterns_map=dynamic_token_patterns_map)
     actual_utterance_combo, actual_tokens, actual_groups = zip(*generator)
     expected_utterance_combo = ((('he will want', 'she will want'),
                                  ('to play', 'to listen'), ('the beatles',
                                                             'kanye')), )
     expected_tokens = (('START', 'PLAY', 'ARTIST'), )
     expected_groups = ((('None', 1), ('None', 1), ('None', 1)), )
     pairs = [(actual_utterance_combo, expected_utterance_combo),
              (actual_tokens, expected_tokens),
              (actual_groups, expected_groups)]
     compare_all_pairs(self, pairs)
Ejemplo n.º 6
0
 def test_one_token(self) -> None:
     utterance_combo = (('the beatles', 'kanye'), )
     tokens = ('ARTIST', )
     groups = (('None', 1), )
     _, generator = combine(utterance_combo, tokens, groups)
     actual_utterances, actual_handled_tokens, actual_handled_groups = zip(
         *generator)
     expected_utterances = ('the beatles', 'kanye')
     expected_handled_tokens = (('[ARTIST(the beatles)]', ),
                                ('[ARTIST(kanye)]', ))
     expected_handled_groups = (('{None([ARTIST(the beatles)])}', ),
                                ('{None([ARTIST(kanye)])}', ))
     pairs = [(actual_utterances, expected_utterances),
              (actual_handled_tokens, expected_handled_tokens),
              (actual_handled_groups, expected_handled_groups)]
     compare_all_pairs(self, pairs)
Ejemplo n.º 7
0
 def test_multiple_optional_utternace_pattern(self) -> None:
     pattern_def = _load_pattern_def(
         self._base_dir / 'multiple_optional_utternace_pattern.yml')
     _, generator = expand(pattern_def)
     actual_utterance_combo, actual_tokens, actual_groups = zip(*generator)
     expected_utterance_combo = ((('hi', ), ('she will want', ),
                                  ('to play', ), ('nico', )),
                                 (('hi', ), ('she will want', ),
                                  ('to play', ), ('tom waits', )))
     expected_tokens = (('WAKE', 'START', 'PLAY', 'ARTIST_1'),
                        ('WAKE', 'START', 'PLAY', 'ARTIST_2'))
     expected_groups = ((('None', 1), ('PLAY_PHRASE', 2), ('None', 1)),
                        (('None', 1), ('PLAY_PHRASE', 2), ('None', 1)))
     pairs = [(actual_utterance_combo, expected_utterance_combo),
              (actual_tokens, expected_tokens),
              (actual_groups, expected_groups)]
     compare_all_pairs(self, pairs)
Ejemplo n.º 8
0
 def test_nested_group_tokens(self) -> None:
     pattern_def = _load_pattern_def(self._base_dir /
                                     'nested_group_tokens.yml')
     _, generator = expand(pattern_def)
     actual_utterance_combo, actual_tokens, actual_groups = zip(*generator)
     expected_utterance_combo = ((('hi', ), ('she wants', ), ('to play',
                                                              'to listen'),
                                  ('to play', 'to listen')), )
     expected_tokens = (('WAKE', 'START', 'PLAY', 'PLAY'), )
     expected_groups = ((
         ('None', 1),
         ('PLAY_PHRASE', 3),
     ), )
     pairs = [(actual_utterance_combo, expected_utterance_combo),
              (actual_tokens, expected_tokens),
              (actual_groups, expected_groups)]
     compare_all_pairs(self, pairs)
Ejemplo n.º 9
0
 def test_combo_options_with_replacement(self) -> None:
     utterance_combo = (('he will want', 'she will want'), ('to play',
                                                            'to listen'))
     tokens = ('START', 'PLAY')
     groups = (('None', 1), ('None', 1))
     combo_options = ComboOptions(max_sample_size=6, with_replacement=True)
     _, generator = combine(utterance_combo,
                            tokens,
                            groups,
                            combo_options=combo_options)
     actual_utterances, actual_handled_tokens, actual_handled_groups = zip(
         *generator)
     expected_utterances = ('she will want to listen',
                            'she will want to listen',
                            'he will want to play', 'she will want to play',
                            'she will want to listen',
                            'she will want to listen')
     expected_handled_tokens = (('[START(she will want)]',
                                 '[PLAY(to listen)]'),
                                ('[START(she will want)]',
                                 '[PLAY(to listen)]'),
                                ('[START(he will want)]',
                                 '[PLAY(to play)]'),
                                ('[START(she will want)]',
                                 '[PLAY(to play)]'),
                                ('[START(she will want)]',
                                 '[PLAY(to listen)]'),
                                ('[START(she will want)]',
                                 '[PLAY(to listen)]'))
     expected_handled_groups = (('{None([START(she will want)])}',
                                 '{None([PLAY(to listen)])}'),
                                ('{None([START(she will want)])}',
                                 '{None([PLAY(to listen)])}'),
                                ('{None([START(he will want)])}',
                                 '{None([PLAY(to play)])}'),
                                ('{None([START(she will want)])}',
                                 '{None([PLAY(to play)])}'),
                                ('{None([START(she will want)])}',
                                 '{None([PLAY(to listen)])}'),
                                ('{None([START(she will want)])}',
                                 '{None([PLAY(to listen)])}'))
     pairs = [(actual_utterances, expected_utterances),
              (actual_handled_tokens, expected_handled_tokens),
              (actual_handled_groups, expected_handled_groups)]
     compare_all_pairs(self, pairs)
Ejemplo n.º 10
0
 def test_intents_and_entities(self) -> None:
     pattern_def = _load_pattern_def(self._base_dir /
                                     'intents_and_entities.yml')
     _, generator = expand(pattern_def)
     actual_utterance_combo, actual_tokens, actual_groups = zip(*generator)
     expected_utterance_combo = ((('he will want', 'she will want'),
                                  ('to play', 'to listen'),
                                  ('nico', 'kanye', 'tom waits')),
                                 (('he will want', 'she will want'),
                                  ('to play', 'to listen'),
                                  ('sunday morning', 'all falls down',
                                   'table top joe')))
     expected_tokens = (('START', 'PLAY', 'ARTIST'), ('START', 'PLAY',
                                                      'SONG'))
     expected_groups = ((('None', 1), ('None', 1), ('None', 1)),
                        (('None', 1), ('None', 1), ('None', 1)))
     pairs = [(actual_utterance_combo, expected_utterance_combo),
              (actual_tokens, expected_tokens),
              (actual_groups, expected_groups)]
     compare_all_pairs(self, pairs)
Ejemplo n.º 11
0
 def test_multiple_tokens(self) -> None:
     utterance_combo = (('he will want', 'she will want'), ('to play',
                                                            'to listen'))
     tokens = ('START', 'PLAY')
     groups = (('None', 1), ('None', 1))
     _, generator = combine(utterance_combo, tokens, groups)
     actual_utterances, actual_handled_tokens, actual_handled_groups = zip(
         *generator)
     expected_utterances = ('he will want to play',
                            'he will want to listen',
                            'she will want to play',
                            'she will want to listen')
     expected_handled_tokens = ((
         '[START(he will want)]',
         '[PLAY(to play)]',
     ), (
         '[START(he will want)]',
         '[PLAY(to listen)]',
     ), (
         '[START(she will want)]',
         '[PLAY(to play)]',
     ), (
         '[START(she will want)]',
         '[PLAY(to listen)]',
     ))
     expected_handled_groups = (('{None([START(he will want)])}',
                                 '{None([PLAY(to play)])}'),
                                ('{None([START(he will want)])}',
                                 '{None([PLAY(to listen)])}'),
                                ('{None([START(she will want)])}',
                                 '{None([PLAY(to play)])}'),
                                ('{None([START(she will want)])}',
                                 '{None([PLAY(to listen)])}'))
     pairs = [(actual_utterances, expected_utterances),
              (actual_handled_tokens, expected_handled_tokens),
              (actual_handled_groups, expected_handled_groups)]
     compare_all_pairs(self, pairs)