diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/functionalizer.py | 31 | ||||
-rw-r--r-- | src/moses.py | 38 | ||||
-rw-r--r-- | src/smt_semparse_config.py | 4 |
3 files changed, 68 insertions, 5 deletions
diff --git a/src/functionalizer.py b/src/functionalizer.py index 66325a0..782b4e5 100644 --- a/src/functionalizer.py +++ b/src/functionalizer.py @@ -37,6 +37,37 @@ class Functionalizer: break counter += 1 + def run_sentence(self, experiment_dir, temp_dir): + hyp_file = open('%s/nbest.tmp' % temp_dir, 'r') + + hypsets = [] + hypset = [] + last_eid = 0 + for line in hyp_file: + parts = line.split('|||') + eid = int(parts[0]) + if eid != last_eid: + hypsets.append(hypset) + hypset = [] + last_eid = eid + score = parts[2] + ' ||| ' + parts[3].strip() + hyp = parts[1].strip() + hypset.append((hyp,score)) + hypsets.append(hypset) + hyp_file.close() + + counter = 0 + for hypset in hypsets: + hypset = list(reversed(hypset)) + while hypset: + hyp, score = hypset.pop() + fun = self.functionalize(hyp) + if fun: + return fun + break + counter += 1 + return "" + #xc = 0 def functionalize(self, mrl): diff --git a/src/moses.py b/src/moses.py index 857ddbf..9a159c3 100644 --- a/src/moses.py +++ b/src/moses.py @@ -3,6 +3,8 @@ import os import subprocess import gzip +from subprocess import Popen, PIPE, STDOUT + class Moses: def __init__(self, config): @@ -17,7 +19,8 @@ class Moses: '--e', self.config.tgt, '--lm', '0:3:%s/%s.arpa' % (self.config.experiment_dir, self.config.tgt), #'-score-options', "'--OnlyDirect --NoPhraseCount'" - '--alignment', self.config.symm] + '--alignment', self.config.symm, + '-external-bin-dir', self.config.giza] if self.config.model == 'hier': args += ['-hierarchical', '-glue-grammar'] @@ -99,7 +102,7 @@ class Moses: else: args += [self.config.moses_decode_phrase] args += ['%s/model/moses.ini' % self.config.experiment_dir, - '--mertdir', '%s/dist/bin' % self.config.moses] + '--mertdir', '%s/bin' % self.config.moses] if self.config.model == 'hier': args += ['--filtercmd', '%s/scripts/training/filter-model-given-input.pl --Hierarchical'\ @@ -119,7 +122,7 @@ class Moses: else: assert False - if self.config.run == 'test': + if self.config.run == 'test' or self.config.run == 'all': args += ['-f', '%s/mert-work/moses.ini' % self.config.experiment_dir] else: args += ['-f', '%s/model/moses.ini' % self.config.experiment_dir] @@ -139,3 +142,32 @@ class Moses: infile.close() log.close() outfile.close() + + def decode_sentence(self, experiment_dir, sentence, temp_dir): + if self.config.model == 'phrase': + args = [self.config.moses_decode_phrase] + elif self.config.model == 'hier': + args = [self.config.moses_decode_hier] + else: + assert False + + if self.config.run == 'test' or self.config.run == 'all': + args += ['-f', '%s/mert-work/moses.ini' % experiment_dir] + else: + args += ['-f', '%s/model/moses.ini' % experiment_dir] + + args += ['-drop-unknown', + '-n-best-list', '%s/nbest.tmp' % temp_dir, + str(self.config.nbest), 'distinct', + '-threads', '1'] + + infile = open('%s/sent.tmp' % temp_dir, 'w') + print >>infile, sentence + infile.close + infile = open('%s/sent.tmp' % temp_dir, 'r') + nullfile = open(os.devnull, 'w') + p = subprocess.Popen(args, stdin=infile, stdout=nullfile, stderr=nullfile) + p.wait() + infile.close() + return + diff --git a/src/smt_semparse_config.py b/src/smt_semparse_config.py index 71eaf24..6bf50d7 100644 --- a/src/smt_semparse_config.py +++ b/src/smt_semparse_config.py @@ -17,8 +17,8 @@ class SMTSemparseConfig(Config): self.put('moses_train', '%s/scripts/training/train-model.perl' % self.moses) self.put('moses_tune', '%s/scripts/training/mert-moses.pl' % self.moses) - self.put('moses_decode_phrase', '%s/dist/bin/moses' % self.moses) - self.put('moses_decode_hier', '%s/dist/bin/moses_chart' % self.moses) + self.put('moses_decode_phrase', '%s/bin/moses' % self.moses) + self.put('moses_decode_hier', '%s/bin/moses_chart' % self.moses) self.put('bleu_eval', '%s/scripts/generic/multi-bleu.perl' % self.moses) self.put('wasp_eval', '%s/data/geo-funql/eval/eval.pl' % self.wasp) |