def assert_true(query, e=None): if e is None: e = Engine() terms, vars = e.parse(query) term, = terms e.run_query_in_current(term) return dict([(name, var.dereference(None)) for name, var in vars.iteritems()])
def assert_true(query, e=None): if e is None: e = Engine() terms, vars = e.parse(query) term, = terms e.run_query_in_current(term) return dict([(name, var.dereference(None)) for name, var in vars.iteritems()])
def entry_point(argv): if len(argv) != 8: print( "Usage: spyrolog PROGRAM SIMILARITIES QUERY1|QUERY2|...|QUERYN MAX_DEPTH LAMBDA_CUT1|LAMBDA_CUT2|...|LAMBDA_CUTN E-TNORM|P-TNORM MIN_WIDTH" ) return 1 program_fname = argv[1] sim_fname = argv[2] queries = argv[3] max_depth = int(argv[4]) lambda_cuts = [float(i) for i in argv[5].split('|')] entity_tnorm, predicate_tnorm = argv[6].split('|') min_width = int(argv[7]) sim = get_similarity_from_file(sim_fname, 0, entity_tnorm, predicate_tnorm) e = Engine(load_system=False, similarity=sim, max_depth=max_depth) e.modulewrapper.current_module = e.modulewrapper.user_module with open(program_fname) as f: sim.parse_rulescores(f.read(), e) query_idx = 0 for query in queries.split('|'): cut = lambda_cuts[query_idx] scores = [] depths = [] rules = [] unifications = [] sim.lambda_cut = cut sim.reset_threshold() sim.query_idx = query_idx collector = GetAllScoresContinuation(e, scores, sim, depths, rules, unifications, min_width) e.max_depth = max_depth goals, var_to_pos = e.parse(query) goal = goals[0] try: e.run_query_in_current(goal, collector) except UnificationFailed: info = get_max_info(scores, depths, rules, unifications) if info[0] > 0: print(info[0], info[1], '|'.join(info[3]), query + ''.join(info[2])) else: print(0.0, 0) query_idx += 1 return 0
def assert_false(query, e=None): if e is None: e = Engine() term = e.parse(query)[0][0] py.test.raises(UnificationFailed, e.run_query_in_current, term)
def assert_false(query, e=None): if e is None: e = Engine() term = e.parse(query)[0][0] py.test.raises(UnificationFailed, e.run_query_in_current, term)