def main(filename, examplefile): try: examples = list(lfi.read_examples(examplefile)) program = PrologFile(filename) score, weights, names, iterations = lfi.run_lfi(program, examples) new_names = [] for n in names: new_names.append((str(n.with_probability()), ) + program.lineno(n.location)[1:]) return True, (score, weights, new_names, iterations) except Exception as err: return False, {"err": process_error(err)}
def main(argv, result_handler=None): parser = argparser() args = parser.parse_args(argv) if result_handler is None: if args.web: result_handler = print_result_json else: result_handler = print_result knowledge = get_evaluatable(args.koption) if args.output is None: outf = sys.stdout else: outf = open(args.output, 'w') create_logger('problog_lfi', args.verbose) create_logger('problog', args.verbose - 1) program = PrologFile(args.model) examples = list(read_examples(*args.examples)) if len(examples) == 0: logging.getLogger('problog_lfi').warn('no examples specified') else: logging.getLogger('problog_lfi').info('Number of examples: %s' % len(examples)) options = vars(args) del options['examples'] try: results = run_lfi(program, examples, knowledge=knowledge, **options) for n in results[2]: n.loc = program.lineno(n.location) retcode = result_handler((True, results), output=outf) except Exception as err: trace = traceback.format_exc() err.trace = trace retcode = result_handler((False, err), output=outf) if args.output is not None: outf.close() if retcode: sys.exit(retcode)