summaryrefslogtreecommitdiff
path: root/realtime/rt
diff options
context:
space:
mode:
authorMichael Denkowski <mdenkows@cs.cmu.edu>2013-09-15 20:32:59 -0700
committerMichael Denkowski <mdenkows@cs.cmu.edu>2013-09-15 20:32:59 -0700
commit08be69abb923b74f7dc27712d6bef7f6e4a05377 (patch)
tree451919fb2311b22ab650ab6badd9dede6016c646 /realtime/rt
parent15084a749ee241b261458898640ac43a459acb59 (diff)
Move to using named commands
Diffstat (limited to 'realtime/rt')
-rw-r--r--realtime/rt/decoder.py2
-rw-r--r--realtime/rt/rt.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/realtime/rt/decoder.py b/realtime/rt/decoder.py
index 34b5d391..57739d93 100644
--- a/realtime/rt/decoder.py
+++ b/realtime/rt/decoder.py
@@ -34,6 +34,6 @@ class MIRADecoder(Decoder):
self.decoder = util.popen_io(mira_cmd)
def update(self, sentence, grammar, reference):
- input = '<seg grammar="{g}">{s}</seg> ||| {r}\n'.format(s=sentence, g=grammar, r=reference)
+ input = 'LEARN ||| <seg grammar="{g}">{s}</seg> ||| {r}\n'.format(s=sentence, g=grammar, r=reference)
self.decoder.stdin.write(input)
return self.decoder.stdout.readline().strip()
diff --git a/realtime/rt/rt.py b/realtime/rt/rt.py
index 1b8ac58c..0ce05a56 100644
--- a/realtime/rt/rt.py
+++ b/realtime/rt/rt.py
@@ -19,6 +19,8 @@ class RealtimeDecoder:
def __init__(self, configdir, tmpdir='/tmp', cache_size=5, norm=False):
+ self.commands = {'LEARN': self.learn}
+
cdec_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Temporary work dir
@@ -126,6 +128,12 @@ class RealtimeDecoder:
self.detokenizer.stdin.write('{}\n'.format(line))
return self.detokenizer.stdout.readline().strip()
+ def command(self, args):
+ try:
+ self.commands[args[0]](*args[1:])
+ except:
+ logging.info('Command error: {}'.format(' ||| '.join(args)))
+
def learn(self, source, target):
if '' in (source.strip(), target.strip()):
logging.info('Error empty source or target: {} ||| {}'.format(source, target))