diff options
Diffstat (limited to 'realtime/rt/decoder.py')
-rw-r--r-- | realtime/rt/decoder.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/realtime/rt/decoder.py b/realtime/rt/decoder.py new file mode 100644 index 00000000..f4fea0e2 --- /dev/null +++ b/realtime/rt/decoder.py @@ -0,0 +1,23 @@ +import os +import subprocess + +import util + +class Decoder: + + def close(self): + self.decoder.stdin.close() + +class CdecDecoder(Decoder): + + def __init__(self, config, weights): + cdec_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + decoder = os.path.join(cdec_root, 'decoder', 'cdec') + decoder_cmd = [decoder, '-c', config, '-w', weights] + self.decoder = util.popen_io(decoder_cmd) + + def decode(self, sentence, grammar): + input = '<seg grammar="{g}">{s}</seg>\n'.format(i=id, s=sentence, g=grammar) + self.decoder.stdin.write(input) + return self.decoder.stdout.readline().strip() + |