Diff of /args/arg_parser.py [000000] .. [5e0db2]

Switch to unified view

a b/args/arg_parser.py
1
"""Define argument parser class."""
2
import argparse
3
from pathlib import Path
4
5
6
class ArgParser(object):
7
    """Argument parser for label.py"""
8
    def __init__(self):
9
        """Initialize argument parser."""
10
        parser = argparse.ArgumentParser()
11
12
        # Input report parameters.
13
        parser.add_argument('--reports_path',
14
                            required=True,
15
                            help='Path to file with radiology reports.')
16
        parser.add_argument('--sections_to_extract',
17
                            nargs='*',
18
                            default=[],
19
                            help='Titles of the sections to extract from ' +
20
                                 'each report.')
21
        parser.add_argument('--extract_strict',
22
                            action='store_true',
23
                            help='Instructs the labeler to only extract the ' +
24
                                 'sections given by sections_to_extract. ' +
25
                                 'If this argument is given and a report is ' +
26
                                 'encountered that does not contain any of ' +
27
                                 'the provided sections, instead of loading ' +
28
                                 'the original document, that report will be ' +
29
                                 'loaded as an empty document.')
30
31
        # Phrases
32
        parser.add_argument('--mention_phrases_dir',
33
                            default='phrases/mention',
34
                            help='Directory containing mention phrases for ' +
35
                                 'each observation.')
36
        parser.add_argument('--unmention_phrases_dir',
37
                            default='phrases/unmention',
38
                            help='Directory containing unmention phrases ' +
39
                                 'for each observation.')
40
41
        # Rules
42
        parser.add_argument('--pre_negation_uncertainty_path',
43
                            default='patterns/pre_negation_uncertainty.txt',
44
                            help='Path to pre-negation uncertainty rules.')
45
        parser.add_argument('--negation_path',
46
                            default='patterns/negation.txt',
47
                            help='Path to negation rules.')
48
        parser.add_argument('--post_negation_uncertainty_path',
49
                            default='patterns/post_negation_uncertainty.txt',
50
                            help='Path to post-negation uncertainty rules.')
51
52
        # Output parameters.
53
        parser.add_argument('--output_path',
54
                            default='labeled_reports.csv',
55
                            help='Output path to write labels to.')
56
57
        # Misc.
58
        parser.add_argument('-v', '--verbose',
59
                            action='store_true',
60
                            help='Print progress to stdout.')
61
62
        self.parser = parser
63
64
    def parse_args(self):
65
        """Parse and validate the supplied arguments."""
66
        args = self.parser.parse_args()
67
68
        args.reports_path = Path(args.reports_path)
69
        args.mention_phrases_dir = Path(args.mention_phrases_dir)
70
        args.unmention_phrases_dir = Path(args.unmention_phrases_dir)
71
        args.output_path = Path(args.output_path)
72
73
        return args