summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Denkowski <mdenkows@cs.cmu.edu>2013-09-18 11:01:41 -0700
committerMichael Denkowski <mdenkows@cs.cmu.edu>2013-09-18 11:01:41 -0700
commitf650759280f7ceb71e36be3ac834f3046112d037 (patch)
tree5533cbbd940919cd40c3bbe92b3bef20f9622757
parentafdd521ba4cbcec44b548288918d1517f30260f1 (diff)
Support writing state to file
-rw-r--r--realtime/rt/rt.py11
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