8 | 8 |
|
9 | 9 |
# NOTE: these options are provisional and will change
|
10 | 10 |
|
|
11 |
# Input/output specifying parameters
|
|
12 |
|
11 | 13 |
argparser.add_argument(
|
12 | |
'grammar_filename', metavar='FILENAME', type=str,
|
13 | |
help='JSON file containing the grammar to use'
|
|
14 |
'grammar_filename', metavar='GRAMMARFILE', type=str,
|
|
15 |
help='name of JSON file containing the grammar to use'
|
14 | 16 |
)
|
|
17 |
argparser.add_argument(
|
|
18 |
'--output-filename', '-o', metavar='FILENAME', type=str, default='out.json',
|
|
19 |
help='name of file to write JSON-formatted output to'
|
|
20 |
)
|
|
21 |
|
|
22 |
# Options that affect the process
|
|
23 |
|
15 | 24 |
argparser.add_argument(
|
16 | 25 |
"--parse", action="store_true", default=False,
|
17 | 26 |
help="Process rules from right to left"
|
18 | |
)
|
19 | |
|
20 | |
argparser.add_argument(
|
21 | |
"--verbose", action="store_true", default=False,
|
22 | |
help="Display some vital statistics while processing"
|
23 | |
)
|
24 | |
argparser.add_argument(
|
25 | |
"--save-snapshots-every", metavar='COUNT', type=int, default=None,
|
26 | |
help="If given, each time this many generations have passed, "
|
27 | |
"save a copy of the working set of utterances to a JSON "
|
28 | |
"file"
|
29 | 27 |
)
|
30 | 28 |
|
31 | 29 |
argparser.add_argument(
|
|
67 | 65 |
"resulting derivations must be at least this long"
|
68 | 66 |
)
|
69 | 67 |
|
|
68 |
# Debugging-type options
|
|
69 |
|
|
70 |
argparser.add_argument(
|
|
71 |
"--verbose", action="store_true", default=False,
|
|
72 |
help="Display some vital statistics while processing"
|
|
73 |
)
|
|
74 |
argparser.add_argument(
|
|
75 |
"--save-snapshots-every", metavar='COUNT', type=int, default=None,
|
|
76 |
help="If given, each time this many generations have passed, "
|
|
77 |
"save a copy of the working set of utterances to a JSON "
|
|
78 |
"file"
|
|
79 |
)
|
|
80 |
|
70 | 81 |
options = argparser.parse_args(args)
|
71 | 82 |
|
72 | 83 |
with open(options.grammar_filename, 'r') as f:
|
|
103 | 114 |
beam_width=options.beam_width,
|
104 | 115 |
)
|
105 | 116 |
|
106 | |
with open('out.json', 'w') as f:
|
|
117 |
with open(options.output_filename, 'w') as f:
|
107 | 118 |
f.write(json.dumps(result, indent=4))
|
108 | 119 |
|
109 | 120 |
|