def main(): parser = argparse.ArgumentParser( 'Command line interface to the office TREC DD jig.', usage=usage, conflict_handler='resolve') parser.add_argument('command', help='must be "load", "init", "start", "step", or "stop"') parser.add_argument('args', help='input for given command', nargs=argparse.REMAINDER) modules = [yakonfig, kvlayer, Harness] args = yakonfig.parse_args(parser, modules) logging.basicConfig(level=logging.DEBUG) if args.command not in set(['load', 'init', 'start', 'step', 'stop']): sys.exit('The only valid commands are "load", "init", "start", "step", and "stop".') kvl = kvlayer.client() label_store = LabelStore(kvl) config = yakonfig.get_global_config('harness') harness = Harness(config, kvl, label_store) if args.command == 'load': if not config.get('truth_data_path'): sys.exit('Must provide --truth-data-path as an argument') if not os.path.exists(config['truth_data_path']): sys.exit('%r does not exist' % config['truth_data_path']) parse_truth_data(label_store, config['truth_data_path']) logger.info('Done! The truth data was loaded into this ' 'kvlayer backend:\n%s', json.dumps(yakonfig.get_global_config('kvlayer'), indent=4, sort_keys=True)) elif args.command == 'init': response = harness.init() print(json.dumps(response)) elif args.command == 'start': response = harness.start() print(json.dumps(response)) elif args.command == 'stop': response = harness.stop(args.args[0]) print(json.dumps(response)) elif args.command == 'step': parts = args.args topic_id = parts.pop(0) feedback = harness.step(topic_id, parts) print(json.dumps(feedback))
def main(): '''Run the random recommender system on a sequence of topics. ''' description = ( 'A baseline recommender system that uses the truth data to' ' create output that has perfect recall and would also have' ' perfect precision if you ignore subtopic diversity/novelty.' ' This generates output directly from the truth data and' ' randomly shuffles the truth data per topic, so that' ' the ordering of passages does not attempt to optimize any' ' particular quality metric.') parser = argparse.ArgumentParser(description=description) parser.add_argument('--overwrite', action='store_true') args = yakonfig.parse_args(parser, [yakonfig]) logging.basicConfig(level=logging.DEBUG) config = yakonfig.get_global_config('harness') batch_size = config.get('batch_size', 5) run_file_path = config['run_file_path'] if os.path.exists(run_file_path): if args.overwrite: os.remove(run_file_path) else: sys.exit('%r already exists' % run_file_path) kvl_config = { 'storage_type': 'local', 'namespace': 'test', 'app_name': 'test' } kvl = kvlayer.client(kvl_config) label_store = LabelStore(kvl) parse_truth_data(label_store, config['truth_data_path']) # Set up the system doc_store = make_doc_store(label_store) system = RandomSystem(doc_store) ambassador = HarnessAmbassadorCLI(system, args.config, batch_size) ambassador.run()