diff options
author | Michael Denkowski <mdenkows@cs.cmu.edu> | 2013-09-03 12:13:03 -0700 |
---|---|---|
committer | Michael Denkowski <mdenkows@cs.cmu.edu> | 2013-09-03 12:13:03 -0700 |
commit | eec45e082f4261871bb6547a14511d2c722e3f59 (patch) | |
tree | dd6fe95e46d59e7f1b8cd0fd2a467dd825bee7c1 /realtime/rt | |
parent | 7e8600d924f082c2d4b84e5d80993531e880c390 (diff) |
MIRA updates in realtime.py
Diffstat (limited to 'realtime/rt')
-rw-r--r-- | realtime/rt/aligner.py | 5 | ||||
-rw-r--r-- | realtime/rt/decoder.py | 7 | ||||
-rw-r--r-- | realtime/rt/util.py | 6 |
3 files changed, 16 insertions, 2 deletions
diff --git a/realtime/rt/aligner.py b/realtime/rt/aligner.py index d94dbda0..4a0ace48 100644 --- a/realtime/rt/aligner.py +++ b/realtime/rt/aligner.py @@ -23,7 +23,10 @@ class ForceAligner: self.rev_align = util.popen_io(rev_cmd) self.tools = util.popen_io(tools_cmd) - def align(self, line): + def align(self, source, target): + return self.align_formatted('{} ||| {}'.format(source, target)) + + def align_formatted(self, line): self.fwd_align.stdin.write('{}\n'.format(line)) self.rev_align.stdin.write('{}\n'.format(line)) # f words ||| e words ||| links ||| score diff --git a/realtime/rt/decoder.py b/realtime/rt/decoder.py index 786bc07a..6bbef6f2 100644 --- a/realtime/rt/decoder.py +++ b/realtime/rt/decoder.py @@ -9,7 +9,7 @@ class Decoder: self.decoder.stdin.close() def decode(self, sentence, grammar): - input = '<seg grammar="{g}">{s}</seg>\n'.format(i=id, s=sentence, g=grammar) + input = '<seg grammar="{g}">{s}</seg>\n'.format(s=sentence, g=grammar) self.decoder.stdin.write(input) return self.decoder.stdout.readline().strip() @@ -29,3 +29,8 @@ class MIRADecoder(Decoder): # optimizer=2 step=0.001 best=500, k=500, uniq, stream mira_cmd = [mira, '-c', config, '-w', weights, '-o', '2', '-C', '0.001', '-b', '500', '-k', '500', '-u', '-t'] 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) + self.decoder.stdin.write(input) + return self.decoder.stdout.readline().strip() diff --git a/realtime/rt/util.py b/realtime/rt/util.py index 7f877161..263e33fb 100644 --- a/realtime/rt/util.py +++ b/realtime/rt/util.py @@ -1,4 +1,5 @@ import subprocess +import sys import threading def popen_io(cmd): @@ -6,6 +7,11 @@ def popen_io(cmd): consume_stream(p.stderr) return p +def popen_io_v(cmd): + sys.stderr.write('{}\n'.format(' '.join(cmd))) + p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) + return p + def consume_stream(stream): def consume(s): for _ in s: |