diff options
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)
+
|