git @ Cat's Eye Technologies Samovar / e59e8fd
Beginnings of JSON output of events; needs to be structured. Chris Pressey 6 years ago
3 changed file(s) with 22 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
7575 a given action has been taken previously or not.
7676 * (+) Consider macros.
7777 * Output events to JSON.
78 * Output AST to JSON.
78 * Output scenarios to JSON.
7979 * Python 3 support.
8080 * Test (manually) that multiple source files can be given. (put in `eg/`)
8181 * Allow comments in source file. Probably `#` or `//`.
2626 argparser.add_argument('input_files', nargs='+', metavar='FILENAME', type=str,
2727 help='Source files containing the scenario descriptions'
2828 )
29 argparser.add_argument("--debug",
30 action="store_true",
31 help="Show state before and after each move")
29 argparser.add_argument("--debug", action="store_true",
30 help="Show state before and after each move"
31 )
3232 argparser.add_argument("--dump-ast",
3333 action="store_true",
3434 help="Just show the AST and stop")
3535 argparser.add_argument("--length",
3636 type=int, default=0,
3737 help="If given, generate this many events for each situation")
38 argparser.add_argument("--line-per-sentence",
39 action="store_true")
38 argparser.add_argument("--output-type",
39 choices=['naive-text', 'events-json', 'scenarios-json'],
40 default='naive-text',
41 help="Specify what to output and in what format")
4042 argparser.add_argument("--seed",
4143 type=int, default=None,
4244 help="Set random seed (to select moves deterministically)")
7476 sys.exit(0)
7577 if options.seed is not None:
7678 random.seed(options.seed)
79 event_buckets = []
7780 for scenario in ast.scenarios:
7881 if scenario.goal is None:
7982 continue
8285 events = g.generate_events(options.length)
8386 elif options.words > 0:
8487 events = g.generate_words(options.words)
85 for e in events:
86 if options.line_per_sentence:
88 event_buckets.append(events)
89
90 if options.output_type == 'naive-text':
91 for b in event_buckets:
92 for e in events:
8793 sys.stdout.write("%s\n" % e)
88 else:
89 sys.stdout.write("%s " % e)
90 sys.stdout.write("\n")
94 sys.stdout.write("\n")
95 elif options.output_type == 'events-json':
96 sys.stdout.write(json.dumps(event_buckets, indent=4, sort_keys=True))
97 elif options.output_type == 'scenarios-json':
98 raise NotImplementedError
99 else:
100 raise NotImplementedError
91101
92102
93103 if __name__ == '__main__':
99
1010 -> Functionality "Run Samovar Simulation" is implemented by
1111 -> shell command
12 -> "bin/samovar %(test-body-file) --words 20 --line-per-sentence --seed 0"
12 -> "bin/samovar %(test-body-file) --words 20 --seed 0"
1313
1414 Scenarios
1515 ---------