Beispiel #1
0
    def testPhraseExtraction(self):
        expected_phrases = ['MOCK']

        mock_module = Mock()
        mock_module.WORDS = ['MOCK']

        with patch.object(brain.Brain, 'get_modules',
                          classmethod(lambda cls: [mock_module])):
            extracted_phrases = vocabcompiler.get_all_phrases()
        self.assertEqual(expected_phrases, extracted_phrases)
Beispiel #2
0
    def testPhraseExtraction(self):
        expected_phrases = ['MOCK']

        mock_module = Mock()
        mock_module.WORDS = ['MOCK']

        with patch.object(brain.Brain, 'get_modules',
                          classmethod(lambda cls: [mock_module])):
            extracted_phrases = vocabcompiler.get_all_phrases()
        self.assertEqual(expected_phrases, extracted_phrases)
Beispiel #3
0
    def get_config(cls):
        # FIXME: Replace this as soon as we have a config module
        config = {}
        # HMM dir
        # Try to get hmm_dir from config
        profile_path = saschapath.config('profile.yml')

        name_default = 'default'
        path_default = saschapath.config('vocabularies')

        name_keyword = 'keyword'
        path_keyword = saschapath.config('vocabularies')

        if os.path.exists(profile_path):
            with open(profile_path, 'r') as f:
                profile = yaml.safe_load(f)
                if 'pocketsphinx' in profile:
                    if 'hmm_dir' in profile['pocketsphinx']:
                        config['hmm_dir'] = profile['pocketsphinx']['hmm_dir']

                    if 'vocabulary_default_name' in profile['pocketsphinx']:
                        name_default = \
                            profile['pocketsphinx']['vocabulary_default_name']

                    if 'vocabulary_default_path' in profile['pocketsphinx']:
                        path_default = \
                            profile['pocketsphinx']['vocabulary_default_path']

                    if 'vocabulary_keyword_name' in profile['pocketsphinx']:
                        name_keyword = \
                            profile['pocketsphinx']['vocabulary_keyword_name']

                    if 'vocabulary_keyword_path' in profile['pocketsphinx']:
                        path_keyword = \
                            profile['pocketsphinx']['vocabulary_keyword_path']

        config['vocabulary'] = vocabcompiler.PocketsphinxVocabulary(
            name_default, path=path_default)
        config['vocabulary_keyword'] = vocabcompiler.PocketsphinxVocabulary(
            name_keyword, path=path_keyword)

        config['vocabulary'].compile(vocabcompiler.get_all_phrases())
        config['vocabulary_keyword'].compile(
            vocabcompiler.get_keyword_phrases())

        return config
Beispiel #4
0
    def get_config(cls):
        # FIXME: Replace this as soon as we have a config module
        config = {}
        # HMM dir
        # Try to get hmm_dir from config
        profile_path = jasperpath.config('profile.yml')

        name_default = 'default'
        path_default = jasperpath.config('vocabularies')

        name_keyword = 'keyword'
        path_keyword = jasperpath.config('vocabularies')

        if os.path.exists(profile_path):
            with open(profile_path, 'r') as f:
                profile = yaml.safe_load(f)
                if 'pocketsphinx' in profile:
                    if 'hmm_dir' in profile['pocketsphinx']:
                        config['hmm_dir'] = profile['pocketsphinx']['hmm_dir']

                    if 'vocabulary_default_name' in profile['pocketsphinx']:
                        name_default = \
                            profile['pocketsphinx']['vocabulary_default_name']

                    if 'vocabulary_default_path' in profile['pocketsphinx']:
                        path_default = \
                            profile['pocketsphinx']['vocabulary_default_path']

                    if 'vocabulary_keyword_name' in profile['pocketsphinx']:
                        name_keyword = \
                            profile['pocketsphinx']['vocabulary_keyword_name']

                    if 'vocabulary_keyword_path' in profile['pocketsphinx']:
                        path_keyword = \
                            profile['pocketsphinx']['vocabulary_keyword_path']

        config['vocabulary'] = vocabcompiler.PocketsphinxVocabulary(
            name_default, path=path_default)
        config['vocabulary_keyword'] = vocabcompiler.PocketsphinxVocabulary(
            name_keyword, path=path_keyword)

        config['vocabulary'].compile(vocabcompiler.get_all_phrases())
        config['vocabulary_keyword'].compile(
            vocabcompiler.get_keyword_phrases())

        return config
Beispiel #5
0
 def get_active_instance(cls):
     phrases = vocabcompiler.get_all_phrases()
     return cls.get_instance('default', phrases)
Beispiel #6
0
 def get_active_instance(cls):
     phrases = vocabcompiler.get_all_phrases()
     return cls.get_instance('default', phrases)
Beispiel #7
0
 def get_music_instance(cls):
     phrases = vocabcompiler.get_all_phrases()
     return cls.get_instance('music', phrases)