Ejemplo n.º 1
0
def ask_user(goal, dict, known, why):
    fact = substitute(goal, dict)
    if fact in known:
        return 1
    elif (['not'] + fact) in known:
        return 0

    while 1:
        ans = raw_input('is this true: "' + external([fact]) + '" ? ')
        if ans in positive:
            known.append(fact)
            return 1

        elif ans in negative:
            known.append(['not'] + fact)
            return 0

        elif ans == 'why':
            for (goal, dict, rule) in why:
                print 'to prove',
                print '"' + external([substitute(goal, dict)]) + '"',
                print 'by rule', rule
            print 'this was part of your original query.'

        elif ans == 'browse':
            browse_pattern(kbase, raw_input('enter browse pattern: '))

        elif ans == 'stop':
            raise stop_proof

        else:
            print 'what?  (expecting "y", "n", "why", "browse", or "stop")'
Ejemplo n.º 2
0
def ask_user(goal, dict, known, why):
    fact = substitute(goal, dict)
    if fact in known:
        return 1
    elif (['not'] + fact) in known:
        return 0
    
    while 1:
        ans = raw_input('is this true: "' + external([fact]) + '" ? ')
        if ans in positive:
            known.append(fact)
            return 1

        elif ans in negative:
            known.append(['not'] + fact)
            return 0

        elif ans == 'why':
            for (goal, dict, rule) in why:
                print 'to prove', 
                print '"' + external([substitute(goal,dict)]) + '"', 
                print 'by rule', rule
            print 'this was part of your original query.'
        
        elif ans == 'browse':
            browse_pattern(kbase, raw_input('enter browse pattern: '))

        elif ans == 'stop':
            raise stop_proof

        else:
            print 'what?  (expecting "y", "n", "why", "browse", or "stop")'
Ejemplo n.º 3
0
def ask_user(fact, known, why):
    global user_answers
    for (item, proof) in known:
        if item == fact: 
            return 1
        if item == ['not'] + fact: 
            return 0

    user_answers = 1
    while 1:
        ans = raw_input('is this true: ' + external([fact]) + ' ?') 
        if ans in ['y','Y','yes','YES']:
            known.append((fact, 'told'))
            return 1
        elif ans in ['n','N','no','NO']:
            known.append((['not'] + fact), 'told')
            return 0
        elif ans == 'why':
            print 'to see if rule', why, 'can be applied'
        elif ans == 'where':
            print_solns(known, None)
        elif ans == 'browse':
            browse_pattern(rulebase, raw_input('enter browse pattern: '))
        elif ans == 'stop':
            raise stop_chaining
        else:
            print 'what? ',
            print '(expecting "y", "n", "why", "where", "browse", or "stop")'
Ejemplo n.º 4
0
def ask_user(fact, known, why):
    global user_answers
    for (item, proof) in known:
        if item == fact:
            return 1
        if item == ['not'] + fact:
            return 0

    user_answers = 1
    while 1:
        ans = raw_input('is this true: ' + external([fact]) + ' ?')
        if ans in ['y', 'Y', 'yes', 'YES']:
            known.append((fact, 'told'))
            return 1
        elif ans in ['n', 'N', 'no', 'NO']:
            known.append((['not'] + fact), 'told')
            return 0
        elif ans == 'why':
            print 'to see if rule', why, 'can be applied'
        elif ans == 'where':
            print_solns(known, None)
        elif ans == 'browse':
            browse_pattern(rulebase, raw_input('enter browse pattern: '))
        elif ans == 'stop':
            raise stop_chaining
        else:
            print 'what? ',
            print '(expecting "y", "n", "why", "where", "browse", or "stop")'
Ejemplo n.º 5
0
def input_yes(prompt):
    while 1:
        ans = raw_input(prompt)
        if ans in positive:
            return 1
        elif ans in negative:
            return 0
        elif ans == 'browse':
            browse_pattern(kbase, raw_input('enter browse pattern: '))
        else: 
            print 'what?  (expecting "y", "n", or "browse")'
Ejemplo n.º 6
0
def input_yes(prompt):
    while 1:
        ans = raw_input(prompt)
        if ans in positive:
            return 1
        elif ans in negative:
            return 0
        elif ans == 'browse':
            browse_pattern(kbase, raw_input('enter browse pattern: '))
        else:
            print 'what?  (expecting "y", "n", or "browse")'
Ejemplo n.º 7
0
def show_proofs(known):
    while 1:
        print
        ans = raw_input('show proofs? ')
        if ans in ['y','Y','yes','YES']:
            [patt] = internal(raw_input('enter deductions pattern: '))
            for (fact, proof) in known:
                if match(patt, fact, {}, {})[0]:
                    trace_tree((fact, proof), 0)
        elif ans in ['n','N','no','NO']:
            break
        elif ans == 'where':
            print_solns(known, None)
        elif ans == 'browse':
            browse_pattern(rulebase, raw_input('enter browse pattern: '))
        else:
            print 'what?  (expecting "y", "n", "where", or "browse")'
Ejemplo n.º 8
0
def show_proofs(known):
    while 1:
        print
        ans = raw_input('show proofs? ')
        if ans in ['y', 'Y', 'yes', 'YES']:
            [patt] = internal(raw_input('enter deductions pattern: '))
            for (fact, proof) in known:
                if match(patt, fact, {}, {})[0]:
                    trace_tree((fact, proof), 0)
        elif ans in ['n', 'N', 'no', 'NO']:
            break
        elif ans == 'where':
            print_solns(known, None)
        elif ans == 'browse':
            browse_pattern(rulebase, raw_input('enter browse pattern: '))
        else:
            print 'what?  (expecting "y", "n", "where", or "browse")'