def OR(goal, why, how, top): ask = 1 res = [] dict1 = how[top][1][1] for rule in kbase.match_then(goal, dict1): for then in rule['then']: then, cft = certainty(then) dict2 = {} matched, changes = match(goal, then, dict1, dict2) if matched: ask = 0 why2 = [(goal, dict1, rule['rule'])] + why how2 = how + [(goal, (rule['rule'], dict2))] for (proof, cfi) in AND(rule['if'], why2, how2, len(how)): res.append((proof, cft * cfi)) for (var, env) in changes: env[var] = '?' if ask: cf = ask_user(kbase, goal, dict1, known, why) if cf: res = [(how + [(goal, 'told')], cf)] return res
def ask_user1(kbase, goal, dict, known, state): why = [] (x, x, x, rule1, state) = state while state: (dict, goals, curr, rule2, state) = state why = why + [(goals[curr], dict, rule1)] rule1 = rule2 return ask_user(kbase, goal, dict, known, why)
def ask_user1(goal, dict, known, state): why = [] (x, x, x, rule1, state) = state while state: (dict, goals, curr, rule2, state) = state why = why + [(goals[curr], dict, rule1)] rule1 = rule2 return ask_user(goal, dict, known, why)
def OR(goal, dict, why, how, cont): # match 'then' rules = 0 for rule in kbase: # select rule for then in rule['then']: # and descend dict2 = {} matched, changes = match(goal, then, dict, dict2) if matched: rules = 1 why2 = [(goal, dict, rule['rule'])] + why how2 = how + [(goal, (rule['rule'], dict2))] AND(rule['if'], dict2, why2, cont, how2) for (var, env) in changes: env[var] = '?' if not rules: if ask_user(goal, dict, known, why): apply(cont[0], cont[1] + (how + [(goal, 'told')], ))
def OR(goal, dict, why, how, cont): # match 'then' rules = 0 for rule in kbase: # select rule for then in rule['then']: # and descend dict2 = {} matched, changes = match(goal, then, dict, dict2) if matched: rules = 1 why2 = [(goal, dict, rule['rule'])] + why how2 = how + [(goal, (rule['rule'], dict2))] AND(rule['if'], dict2, why2, cont, how2) for (var, env) in changes: env[var] = '?' if not rules: if ask_user(goal, dict, known, why): apply(cont[0], cont[1] + (how + [(goal, 'told')],) )
def OR(goal, stack, why, how): ask = 1 res = [] for rule in kbase: for then in rule['then']: dict2 = {} matched, changes = match(goal, then, stack[0], dict2) if matched: ask = 0 why2 = [(goal, stack[0], rule['rule'])] + why how2 = how + [(goal, [rule['rule'], '?'])] below = AND(rule['if'], [dict2] + stack, why2, how2) for (stack2, proof) in below: proof[len(how2) - 1][1][1] = stack2[0] res.append((stack2[1:], proof)) for (var, env) in changes: env[var] = '?' if ask and ask_user(goal, stack[0], known, why): res = [(stack, how + [(goal, 'told')])] return res
def OR(goal, stack, why, how): ask = 1 res = [] for rule in kbase: for then in rule['then']: dict2 = {} matched, changes = match(goal, then, stack[0], dict2) if matched: ask = 0 why2 = [(goal, stack[0], rule['rule'])] + why how2 = how + [(goal, [rule['rule'], '?'])] below = AND(rule['if'], [dict2] + stack, why2, how2) for (stack2, proof) in below: proof[len(how2)-1][1][1] = stack2[0] res.append((stack2[1:], proof)) for (var, env) in changes: env[var] = '?' if ask and ask_user(goal, stack[0], known, why): res = [(stack, how + [(goal, 'told')])] return res