blob: 36f059bdc8af82ece1915eace5a7f3518d31a23f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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)
|