Пример #1
0
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
Пример #2
0
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
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
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')], ))
Пример #6
0
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')],) )
Пример #7
0
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
Пример #8
0
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