Ejemplo n.º 1
0
    def testKeywordPhraseExtraction(self):
        expected_phrases = ['MOCK']

        with tempfile.TemporaryFile() as f:
            # We can't use mock_open here, because it doesn't seem to work
            # with the 'for line in f' syntax
            f.write("MOCK\n")
            f.seek(0)
            with patch('%s.open' % vocabcompiler.__name__,
                       return_value=f, create=True):
                extracted_phrases = vocabcompiler.get_keyword_phrases()
        self.assertEqual(expected_phrases, extracted_phrases)
Ejemplo n.º 2
0
    def testKeywordPhraseExtraction(self):
        expected_phrases = ['MOCK']

        with tempfile.TemporaryFile() as f:
            # We can't use mock_open here, because it doesn't seem to work
            # with the 'for line in f' syntax
            f.write("MOCK\n")
            f.seek(0)
            with patch('%s.open' % vocabcompiler.__name__,
                       return_value=f,
                       create=True):
                extracted_phrases = vocabcompiler.get_keyword_phrases()
        self.assertEqual(expected_phrases, extracted_phrases)
Ejemplo n.º 3
0
Archivo: stt.py Proyecto: tdmike/SASCHA
    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
Ejemplo n.º 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
Ejemplo n.º 5
0
 def get_passive_instance(cls):
     phrases = vocabcompiler.get_keyword_phrases()
     return cls.get_instance('keyword', phrases)
Ejemplo n.º 6
0
 def get_passive_instance(cls):
     phrases = vocabcompiler.get_keyword_phrases()
     return cls.get_instance('keyword', phrases)