From 7120911494711094c6dcd9dc0da741d686207aab Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Fri, 25 Apr 2014 18:40:18 +0200 Subject: modifications --- decode_sentence.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 decode_sentence.py (limited to 'decode_sentence.py') diff --git a/decode_sentence.py b/decode_sentence.py new file mode 100644 index 0000000..36f059b --- /dev/null +++ b/decode_sentence.py @@ -0,0 +1,37 @@ +import sys +import os +import tempfile, shutil +from src.extractor import Extractor +from src.smt_semparse_config import SMTSemparseConfig +from src.moses import Moses +from src.functionalizer import Functionalizer + +#input: English sentence +if __name__ == '__main__': + sentence = '' + if len(sys.argv) == 3: + experiment_dir = sys.argv[1] + sentence = sys.argv[2] + else: + assert False + + # load config + _dir = os.path.dirname(os.path.abspath(__file__)) + config = SMTSemparseConfig(_dir+'/settings.yaml', _dir+'/dependencies.yaml') + + #stem + sentence = Extractor(config).preprocess_nl(sentence) + + # we need a temp dir! + temp_dir = tempfile.mkdtemp() + + #decode + moses = Moses(config) + moses.decode_sentence(experiment_dir, sentence, temp_dir) + + #convert to bracket structure + print Functionalizer(config).run_sentence(experiment_dir, temp_dir) + + #delete tmp files + shutil.rmtree(temp_dir) + -- cgit v1.2.3