コード例 #1
0
def score1q(q, kb, depth, n):
    nbest = etcetera.nbest(q.given(), kb, depth, n)
    elist = entailedlist(q.given(), nbest, kb)
    altaIndex, altaPercent = highestPercent(elist, q.alta())
    altbIndex, altbPercent = highestPercent(elist, q.altb())
    score = 0
    if q.answer() == 'a':
        if altaPercent > altbPercent:
            score = 1
        elif altaIndex < altbIndex:
            score = 1
        elif altaIndex == altbIndex and altaPercent == altbPercent and altaPercent == 1.0 and len(
                q.alta()) > len(q.altb()):
            score = 1
    elif q.answer() == 'b':
        if altbPercent > altaPercent:
            score = 1
        elif altbIndex < altaIndex:
            score = 1
        elif altaIndex == altbIndex and altaPercent == altbPercent and altaPercent == 1.0 and len(
                q.altb()) > len(q.alta()):
            score = 1
    else:
        print("big problem")
    print(q.number(), q.answer(), altaIndex, altaPercent, altbIndex,
          altbPercent, score)
    return score
コード例 #2
0
ファイル: tricopa.py プロジェクト: asgordon/EtcAbductionPy
def score1q(q, kb, depth, n):
    nbest = etcetera.nbest(q.given(), kb, depth, n)
    elist = entailedlist(q.given(), nbest, kb)
    altaIndex, altaPercent = highestPercent(elist, q.alta())
    altbIndex, altbPercent = highestPercent(elist, q.altb())
    score = 0
    if q.answer() == 'a':
        if altaPercent > altbPercent:
            score = 1
        elif altaIndex < altbIndex:
            score = 1
        elif altaIndex == altbIndex and altaPercent == altbPercent and altaPercent == 1.0 and len(q.alta()) > len(q.altb()):
            score = 1
    elif q.answer() == 'b':
        if altbPercent > altaPercent:
            score = 1
        elif altbIndex < altaIndex:
            score = 1
        elif altaIndex == altbIndex and altaPercent == altbPercent and altaPercent == 1.0 and len(q.altb()) > len(q.alta()):
            score = 1
    else:
        print("big problem")
    print(q.number(), q.answer(), altaIndex, altaPercent, altbIndex, altbPercent, score)
    return score
コード例 #3
0
if args.all:
    solutions = etcetera.etcAbduction(obs, kb, args.depth, skolemize=skolemize)
else:
    if args.incremental:
        solutions = incremental.incremental(obs,
                                            kb,
                                            args.depth,
                                            args.nbest,
                                            args.window,
                                            args.beam,
                                            skolemize=skolemize)
    else:
        solutions = etcetera.nbest(obs,
                                   kb,
                                   args.depth,
                                   args.nbest,
                                   skolemize=skolemize)

if args.graph:
    solution = solutions[args.solution - 1]
    print(forward.graph(solution, forward.forward(solution, kb), targets=obs),
          file=args.outfile)
elif args.evalfile:
    solution = solutions[args.solution - 1]
    precision, recall, f1 = evaluate.evaluate(solution, goldliterals)
    print("Precision", precision, "Recall", recall, "F1", f1, sep="\t")
else:
    for solution in solutions:
        print(parse.display(solution), file=args.outfile)
    print(str(len(solutions)) + " solutions.")
コード例 #4
0
if args.all:
    solutions = etcetera.etcAbduction(obs, kb, indexed_kb, args.depth)
else:
    if args.ilp:
        import etcetera_ilp

        # import may take a while.
        time_start = time.time()
        solutions = etcetera_ilp.nbest_ilp(obs, indexed_kb, args.depth,
                                           args.nbest, args.ilp_verbose,
                                           args.ilp_use_cnf,
                                           not args.ilp_no_relreason,
                                           args.ilp_show_nonetc)

    else:
        solutions = etcetera.nbest(obs, kb, indexed_kb, args.depth, args.nbest)

logging.info(str(len(solutions)) + " solutions.")
logging.info("It took %.2f sec to find the solutions." %
             (time.time() - time_start))

if args.graph:
    solution = solutions[args.solution - 1]
    print(forward.graph(solution, forward.forward(solution, kb), targets=obs),
          file=args.outfile)
else:
    for solution in solutions:
        print("; prob=%s\n%s" %
              (etcetera.jointProbability(solution), parse.display(solution)),
              file=args.outfile)
コード例 #5
0
ファイル: __main__.py プロジェクト: asgordon/EtcAbductionPy
# Handle forward

if args.forward:
    entailed = forward.forward(obs, kb)
    if args.graph:
        print(forward.graph(obs, entailed), file=args.outfile)
    else:
        for e in entailed:
            print(parse.display(e[0]), file=args.outfile)
    sys.exit()

# Handle abduction

if args.all:
    solutions = etcetera.etcAbduction(obs, kb, args.depth)
else:
    solutions = etcetera.nbest(obs, kb, args.depth, args.nbest)

if args.graph:
    solution = solutions[args.solution - 1]
    print(forward.graph(solution, forward.forward(solution, kb), targets=obs),
          file=args.outfile)
else:
    for solution in solutions:
        print(parse.display(solution), file=args.outfile)
    print(str(len(solutions)) + " solutions.")


# To do: enable skolemize as an option
コード例 #6
0
ファイル: tricopa.py プロジェクト: asgordon/EtcAbductionPy
def xbestproof(q, kb, depth, x):
    xbest = etcetera.nbest(q.given(), kb, depth, x + 1)[x]
    return(forward.graph(xbest, forward.forward(xbest, kb), targets=q.given()))
コード例 #7
0
ファイル: tricopa.py プロジェクト: asgordon/EtcAbductionPy
def workflow(q, kb, depth):
    best = etcetera.nbest(q.given(), kb, depth, 1)[0]
    return(forward.graph(best, forward.forward(best, kb), targets=q.given()))
コード例 #8
0
def xbestproof(q, kb, depth, x):
    xbest = etcetera.nbest(q.given(), kb, depth, x + 1)[x]
    return (forward.graph(xbest, forward.forward(xbest, kb),
                          targets=q.given()))
コード例 #9
0
def workflow(q, kb, depth):
    best = etcetera.nbest(q.given(), kb, depth, 1)[0]
    return (forward.graph(best, forward.forward(best, kb), targets=q.given()))