diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-05-26 14:20:10 -0700 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2014-05-26 14:20:10 -0700 |
| commit | 2edb48484aa0736e78cb96fdb87a0f39719eb7d6 (patch) | |
| tree | 7f9e3d58d0b1d99f491922c820cc88951f542bcb /boot/vocabcompiler.py | |
| parent | 64de5f735cf0dbdf1a17903b535a1da915d39a6f (diff) | |
| download | jasper-client-2edb48484aa0736e78cb96fdb87a0f39719eb7d6.tar.gz jasper-client-2edb48484aa0736e78cb96fdb87a0f39719eb7d6.zip | |
modularized lm compilation
Diffstat (limited to 'boot/vocabcompiler.py')
| -rw-r--r-- | boot/vocabcompiler.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/boot/vocabcompiler.py b/boot/vocabcompiler.py index 4daaa26..d9feba1 100644 --- a/boot/vocabcompiler.py +++ b/boot/vocabcompiler.py @@ -15,12 +15,29 @@ sys.path.append(mod_path) import g2p +def text2lm(in_filename, out_filename): + """Wrapper around the language model compilation tools""" + def text2idngram(in_filename, out_filename): + cmd = "text2idngram -vocab %s < %s -idngram temp.idngram" % (out_filename, + in_filename) + os.system(cmd) + + def idngram2lm(in_filename, out_filename): + cmd = "idngram2lm -idngram temp.idngram -vocab ../client/sentences.txt -arpa %s" % ( + in_filename, out_filename) + os.system(cmd) + + text2idngram(in_filename, in_filename) + idngram2lm(in_filename, out_filename) + + def compile(): """ Gets the words and creates the dictionary """ - m = [os.path.basename(f)[:-3] for f in glob.glob(os.path.dirname("../client/modules/")+"/*.py")] + m = [os.path.basename(f)[:-3] + for f in glob.glob(os.path.dirname("../client/modules/") + "/*.py")] words = [] for module_name in m: @@ -33,7 +50,7 @@ def compile(): words = list(set(words)) # for spotify module - words.extend(["MUSIC","SPOTIFY"]) + words.extend(["MUSIC", "SPOTIFY"]) # create the dictionary pronounced = g2p.translateWords(words) @@ -50,7 +67,4 @@ def compile(): f.close() # make language model - os.system( - "text2idngram -vocab ../client/sentences.txt < ../client/sentences.txt -idngram temp.idngram") - os.system( - "idngram2lm -idngram temp.idngram -vocab ../client/sentences.txt -arpa ../client/languagemodel.lm") + text2lm("../client/sentences.txt", "../client/languagemodel.lm") |
