예제 #1
0
def GEN(goal, dict, goals, why, how):  # match 'then'
    ask = 1
    for rule in kbase:  # select rule
        for then in rule['then']:  # and descend
            dict2 = {}
            matched, changes = match(goal, then, dict, dict2)
            if matched:
                ask = 0
                why2 = [(goal, dict, rule['rule'])] + why
                how2 = how + [(goal, (rule['rule'], dict2))]
                TEST(pushgoals(rule['if'], dict2, goals), why2, how2)
            for (var, env) in changes:
                env[var] = '?'

    if ask and ask_user(goal, dict, known, why):
        TEST(goals, why, how + [(goal, 'told')])
예제 #2
0
파일: backwrd6.py 프로젝트: liubiggun/PP4E
def GEN(goal, dict, goals, why, how):  # match 'then'
    ask = 1
    for rule in kbase:  # select rule
        for then in rule["then"]:  # and descend
            dict2 = {}
            matched, changes = match(goal, then, dict, dict2)
            if matched:
                ask = 0
                why2 = [(goal, dict, rule["rule"])] + why
                how2 = how + [(goal, (rule["rule"], dict2))]
                TEST(pushgoals(rule["if"], dict2, goals), why2, how2)
            for (var, env) in changes:
                env[var] = "?"

    if ask and ask_user(goal, dict, known, why):
        TEST(goals, why, how + [(goal, "told")])
예제 #3
0
def GEN(goal, dict, goals, why, how):                           # match 'then'
    ask = 1
    for rule in kbase.match_then(goal, dict):                   # select rule
        for then in rule['then']:                               # and descend
            dict2 = {}
            matched, changes = match(goal, then, dict, dict2)
            if matched:
                ask   = 0
                why2  = [(goal, dict, rule['rule'])] + why
                how2  = how + [(goal, (rule['rule'], dict2))]
                TEST(pushgoals(rule['if'], dict2, goals), why2, how2)
            for (var, env) in changes:
                env[var] = '?'    

    if ask and ask_user(kbase, goal, dict, known, why):
        TEST(goals, why, how + [(goal, 'told')])
예제 #4
0
def OR(goal, why, how, top):
    ask = 1
    res = []
    dict1 = how[top][1][1]

    for rule in kbase:
        for then in rule['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 in AND(rule['if'], why2, how2, len(how)):
                    res.append(proof)

            for (var, env) in changes:
                env[var] = '?'

    if ask and ask_user(goal, dict1, known, why):
        res = [how + [(goal, 'told')]]
    return res
예제 #5
0
def OR(goal, why, how, top):
    ask = 1
    res = []
    dict1 = how[top][1][1]

    for rule in kbase:
        for then in rule['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 in AND(rule['if'], why2, how2, len(how)):
                    res.append(proof)

            for (var, env) in changes: 
                env[var] = '?'

    if ask and ask_user(goal, dict1, known, why):
        res = [how + [(goal, 'told')]]
    return res