diff options
author | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2014-04-25 18:40:18 +0200 |
---|---|---|
committer | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2014-04-25 18:40:18 +0200 |
commit | 7120911494711094c6dcd9dc0da741d686207aab (patch) | |
tree | 9eb85690b3550d810796ebed2328631001f4405b /decode_sentence.py | |
parent | 145368964385a6e8d475d10e2b726bf18a33d2f1 (diff) |
Diffstat (limited to 'decode_sentence.py')
-rw-r--r-- | decode_sentence.py | 37 |
1 files changed, 37 insertions, 0 deletions
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)
+
|