git @ Cat's Eye Technologies relwrite / 2f88a02
Add `--output-file` option for specifying the output filename. Chris Pressey 8 months ago
2 changed file(s) with 25 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
6868
6969 ### TODO (immediate)
7070
71 * `--output-file` to specify output filename
7271 * `--goal` to assert that a particular final utterance appears
7372 * Turn `complete` into a strategy that must be explicitly selected.
7473
88
99 # NOTE: these options are provisional and will change
1010
11 # Input/output specifying parameters
12
1113 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'
1416 )
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
1524 argparser.add_argument(
1625 "--parse", action="store_true", default=False,
1726 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"
2927 )
3028
3129 argparser.add_argument(
6765 "resulting derivations must be at least this long"
6866 )
6967
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
7081 options = argparser.parse_args(args)
7182
7283 with open(options.grammar_filename, 'r') as f:
103114 beam_width=options.beam_width,
104115 )
105116
106 with open('out.json', 'w') as f:
117 with open(options.output_filename, 'w') as f:
107118 f.write(json.dumps(result, indent=4))
108119
109120