summaryrefslogtreecommitdiff
path: root/client/vocabcompiler.py
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2015-01-15 16:05:35 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2015-01-15 16:05:35 +0100
commitf03860c66741a313bb0751726728c8a3cd4835d5 (patch)
tree3da5dec817ecf01ad1c248c24a0378eaf7792ab9 /client/vocabcompiler.py
parent7475cf0b7f0076d5e6b78ee3961697f70b630ef9 (diff)
downloadjasper-client-f03860c66741a313bb0751726728c8a3cd4835d5.tar.gz
jasper-client-f03860c66741a313bb0751726728c8a3cd4835d5.zip
Make archive_member_name configurable in Julius vocabcompiler
Diffstat (limited to 'client/vocabcompiler.py')
-rw-r--r--client/vocabcompiler.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/client/vocabcompiler.py b/client/vocabcompiler.py
index 665790f..0f8a648 100644
--- a/client/vocabcompiler.py
+++ b/client/vocabcompiler.py
@@ -333,13 +333,15 @@ class PocketsphinxVocabulary(AbstractVocabulary):
class JuliusVocabulary(AbstractVocabulary):
class VoxForgeLexicon(object):
- def __init__(self, fname):
+ def __init__(self, fname, membername=None):
self._dict = {}
- self.parse(fname)
+ self.parse(fname, membername)
@contextlib.contextmanager
- def open_dict(self, fname, membername='VoxForge/VoxForgeDict'):
+ def open_dict(self, fname, membername=None):
if tarfile.is_tarfile(fname):
+ if not membername:
+ raise ValueError('archive membername not set!')
tf = tarfile.open(fname)
f = tf.extractfile(membername)
yield f
@@ -349,9 +351,9 @@ class JuliusVocabulary(AbstractVocabulary):
with open(fname) as f:
yield f
- def parse(self, fname):
+ def parse(self, fname, membername=None):
pattern = re.compile(r'\[(.+)\]\W(.+)')
- with self.open_dict(fname) as f:
+ with self.open_dict(fname, membername=membername) as f:
for line in f:
matchobj = pattern.search(line)
if matchobj:
@@ -418,14 +420,20 @@ class JuliusVocabulary(AbstractVocabulary):
tmpdir = tempfile.mkdtemp()
lexicon_file = jasperpath.data('julius-stt', 'VoxForge.tgz')
+ lexicon_archive_member = 'VoxForge/VoxForgeDict'
profile_path = jasperpath.config('profile.yml')
if os.path.exists(profile_path):
with open(profile_path, 'r') as f:
profile = yaml.safe_load(f)
- if 'julius' in profile and 'lexicon' in profile['julius']:
- lexicon_file = profile['julius']['lexicon']
+ if 'julius' in profile:
+ if 'lexicon' in profile['julius']:
+ lexicon_file = profile['julius']['lexicon']
+ if 'lexicon_archive_member' in profile['julius']:
+ lexicon_archive_member = \
+ profile['julius']['lexicon_archive_member']
- lexicon = JuliusVocabulary.VoxForgeLexicon(lexicon_file)
+ lexicon = JuliusVocabulary.VoxForgeLexicon(lexicon_file,
+ lexicon_archive_member)
# Create grammar file
tmp_grammar_file = os.path.join(tmpdir,