diff options
author | Michael Denkowski <mdenkows@cs.cmu.edu> | 2013-09-18 11:01:41 -0700 |
---|---|---|
committer | Michael Denkowski <mdenkows@cs.cmu.edu> | 2013-09-18 11:01:41 -0700 |
commit | ae863e33391c61551299a5b5ebee684fe55d59e2 (patch) | |
tree | e7b0072cf814169c86289194c930914ae81fa247 /realtime | |
parent | 06500c2cd6218d364f7410996b2aacfae5982200 (diff) |
Support writing state to file
Diffstat (limited to 'realtime')
-rw-r--r-- | realtime/rt/rt.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/realtime/rt/rt.py b/realtime/rt/rt.py index fedc1fcf..b1cf19ef 100644 --- a/realtime/rt/rt.py +++ b/realtime/rt/rt.py @@ -179,12 +179,15 @@ class RealtimeDecoder: self.ref_fifo.write('{}\n'.format(target)) self.ref_fifo.flush() - def save_state(self): + def save_state(self, filename=None): + out = open(filename, 'w') if filename else sys.stdout logging.info('Saving state with {} sentences'.format(len(self.inc_data))) - sys.stdout.write('{}\n'.format(self.decoder.get_weights())) + out.write('{}\n'.format(self.decoder.get_weights())) for (source, target, alignment) in self.inc_data: - sys.stdout.write('{} ||| {} ||| {}\n'.format(source, target, alignment)) - sys.stdout.write('EOF\n') + out.write('{} ||| {} ||| {}\n'.format(source, target, alignment)) + out.write('EOF\n') + if filename: + out.close() def load_state(self, input=sys.stdin): # Non-initial load error |