-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
76 lines (70 loc) · 2.11 KB
/
run.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from flask import Flask, render_template, request
from dataset import Dataset
import argparse
from collections import defaultdict
app = Flask(__name__)
dataset = Dataset() # will be loaded at beggining of the program
# 最初はこっちが呼ばれるはず
@app.route('/')
def index():
global dataset
types1, types2 = dataset.load_types(id='errant')
visible_types = []
for t1 in types1:
for t2 in types2:
visible_types.append(t1 + ':' + t2)
return render_template(
'content.html',
title='gec analyzer',
dataset=dataset,
visible_types1=types1,
visible_types2=types2,
visible_types=visible_types,
type1=types1,
type2=types2
)
# チェックボックス適用したらこっちが呼ばれるはず
@app.route('/', methods=['POST'])
def post():
global dataset
types1, types2 = dataset.load_types(id='errant')
visible_types1 = request.form.getlist('type1')
if types2 == {''}:
visible_types2 = types2
else:
visible_types2 = request.form.getlist('type2')
visible_types = []
for t1 in visible_types1:
for t2 in visible_types2:
visible_types.append(t1 + ':' + t2)
return render_template(
'content.html',
title='gec analyzer',
dataset=dataset,
visible_types1=visible_types1,
visible_types2=visible_types2,
visible_types=visible_types,
type1=types1,
type2=types2
)
def load_dataset(args):
global dataset
dataset.load(
original_file=args.orig,
referece_files=args.refs,
hypothesis_files=args.hyps
)
def get_parser():
parser = argparse.ArgumentParser()
parser.add_argument('--orig')
parser.add_argument('--hyps', nargs='+')
parser.add_argument('--refs', nargs='+')
parser.add_argument('--m2')
parser.add_argument('--ref_id', type=int, default=0)
parser.add_argument('--port', type=int, default=5000)
args = parser.parse_args()
return args
if __name__ == '__main__':
args = get_parser()
load_dataset(args)
app.run(debug=False, port=args.port)