-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
72 lines (67 loc) · 2.58 KB
/
main.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
from models.classifier import train_classifier, use_classifier, generate_and_save_train_valid_test
from models.extractor import train_extractor, use_extractor, get_and_save_positives, write_IOB2_format
from models.normalizer import train_normalizer, use_normalizer, get_train_valid_and_test, use_normalizer_similarity
from utils.evaluation import evaluate
from utils.data import Statistics
import argparse
import sys
import logging
def main():
parser = argparse.ArgumentParser()
parser.add_argument('op', type=str, choices=['classify', 'extract', 'normalize', 'similarity'],
help='operation to perform')
parser.add_argument('mode', type=str, choices=['dataset', 'train', 'use', 'evaluate', 'analysis'],
help='generate dataset, training mode, use the trained model, evaluation mode or making a '
'data analysis.')
# Parse arguments
try:
args = parser.parse_args()
logging.info("Input Arguments : %s", args)
except:
parser.print_help()
sys.exit(0)
if args.op == "classify":
if args.mode == 'dataset':
generate_and_save_train_valid_test()
if args.mode == 'train':
train_classifier()
if args.mode == 'use':
use_classifier()
if args.mode == 'evaluate':
evaluate('classifier')
if args.mode == 'analysis':
Statistics('classifier').analysis()
elif args.op == 'extract':
if args.mode == 'dataset':
get_and_save_positives()
write_IOB2_format()
if args.mode == 'train':
train_extractor()
if args.mode == 'use':
use_extractor()
if args.mode == 'evaluate':
evaluate('extractor')
if args.mode == 'analysis':
Statistics('extractor').analysis()
elif args.op == 'normalize':
if args.mode == 'dataset':
get_train_valid_and_test()
if args.mode == 'train':
train_normalizer()
if args.mode == 'evaluate':
evaluate('normalizer')
if args.mode == 'use':
use_normalizer()
if args.mode == 'analysis':
Statistics('normalizer').analysis()
elif args.op == 'normalize':
if args.mode == 'dataset':
get_train_valid_and_test()
if args.mode == 'evaluate':
evaluate('normalizer')
if args.mode == 'use':
use_normalizer_similarity()
if args.mode == 'analysis':
Statistics('similarity').analysis()
if __name__ == '__main__':
main()