/
ask
executable file
·61 lines (40 loc) · 1.29 KB
/
ask
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
import sys
import os.path
import subprocess
debug = '2>/dev/null'
def init():
global debug
args = sys.argv[1:]
valid_args = True
if len(args) < 2:
valid_args = False
print "Usage: ./answer <path/to/article> <number-of-questions>"
sys.exit(-1)
if not os.path.isfile(args[0]):
valid_args = False
print args[0], "is not a valid file"
try:
nquestions = int(args[1])
if nquestions <= 0:
valid_args = False
print args[1], "is not a valid positive integer"
except ValueError:
valid_args = False
print args[1], "is not a valid positive integer"
if valid_args:
if len(args) == 3 and args[2] == '--debug':
debug = ''
return args[0], int(args[1])
else:
sys.exit(1)
article_path, nquestions = init()
cmd = './scripts/run.sh question-asker --debug %s < %s' % (debug, article_path)
output = subprocess.check_output(cmd, shell=True)
questions = []
for line in output.split('\n'):
if line.strip() == '':
continue
question, sentence, answer, score = line.strip().split('\t')
questions.append(question)
print '\n'.join(questions[0:min(len(questions), nquestions)])