git @ Cat's Eye Technologies Samovar / 8d3a8ad
ArgumentParser Chris Pressey 6 years ago
2 changed file(s) with 26 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
6868
6969 ### TODO
7070
71 * (+) Allow sentence trees to be given for actions.
7271 * (+) Allow scenarios to define a termination condition, so that the implementation
7372 can generate a scene where the condition is met (by whatever method).
7473 * (+) Allow scenarios to specify a minimum number of events to generate.
7877 * Output events to JSON.
7978 * Output AST to JSON.
8079 * Python 3 support.
81 * ArgParser, not OptionParser.
8280 * Test (manually) that multiple source files can be given. (put in `eg/`)
8381 * Allow comments in source file. Probably `#` or `//`.
8482 * Say that Greek letter variables are exactly equivalent to `?rho`, etc.
8785 * Consider allowing `∨`.
8886 * Take AST code from SixtyPical or ALPACA (or try to do better, perhaps with
8987 named tuples, but this is probably madness and not at all worth doing)
88
89 #### Probably we don't do
90
91 * (+) Allow sentence trees to be given for actions.
1111
1212 sys.path.insert(0, join(dirname(realpath(sys.argv[0])), '..', 'src'))
1313
14 from argparse import ArgumentParser
1415 import codecs
15 from optparse import OptionParser
16 import json
1617 import random
1718
1819 from samovar.parser import Parser
1920 from samovar.generator import Generator
2021
2122
22 if __name__ == '__main__':
23 optparser = OptionParser(__doc__)
24 optparser.add_option("--debug",
23 def main(args):
24 argparser = ArgumentParser()
25
26 argparser.add_argument('input_files', nargs='+', metavar='FILENAME', type=str,
27 help='Source files containing the scenario descriptions'
28 )
29 argparser.add_argument("--debug",
2530 action="store_true",
2631 help="Show state before and after each move")
27 optparser.add_option("--dump-ast",
32 argparser.add_argument("--dump-ast",
2833 action="store_true",
2934 help="Just show the AST and stop")
30 optparser.add_option("--length",
35 argparser.add_argument("--length",
3136 type=int, default=0,
3237 help="If given, generate this many events for each situation")
33 optparser.add_option("--line-per-sentence",
38 argparser.add_argument("--line-per-sentence",
3439 action="store_true")
35 optparser.add_option("--seed",
40 argparser.add_argument("--seed",
3641 type=int, default=None,
3742 help="Set random seed (to select moves deterministically)")
38 optparser.add_option("--profile",
43 argparser.add_argument("--profile",
3944 action="store_true",
4045 help="Run cProfile on standard 'heavy load' case and exit")
41 optparser.add_option("--words",
46 argparser.add_argument("--words",
4247 type=int, default=0,
4348 help="If given, generate each scenario til this many words")
44 (options, args) = optparser.parse_args(sys.argv[1:])
49
50 options = argparser.parse_args(args)
4551
4652 if options.profile:
4753 import cProfile
5763 sys.exit(0)
5864
5965 text = ''
60 for arg in args:
66 for arg in options.input_files:
6167 with codecs.open(arg, 'r', encoding='UTF-8') as f:
6268 text += f.read()
6369
8288 else:
8389 sys.stdout.write("%s " % e)
8490 sys.stdout.write("\n")
91
92
93 if __name__ == '__main__':
94 main(sys.argv[1:])