Diff of /pyke/goal.py [9c0a10] .. [f16399] Maximize Restore

  Switch to unified view

a/pyke/goal.py b/pyke/goal.py
...
...
5
EXAMPLE USAGE:
5
EXAMPLE USAGE:
6
6
7
    from pyke import goal
7
    from pyke import goal
8
8
9
    bruce_related_to = \
9
    bruce_related_to = \
10
      goal.compile('bc_example.how_related(bruce, %who, @ans)')
10
      goal.compile('bc_example.how_related(bruce, $who, $ans)')
11
11
12
    def main():
12
    def main():
13
        with bruce_related_to(my_engine, who='thomas') as gen:
13
        with bruce_related_to(my_engine, who='thomas') as gen:
14
            for vars_dict, plan in gen:
14
            for vars, plan in gen:
15
                print vars_dict['ans']
15
                print vars['ans']
16
'''
16
'''
17
17
18
import itertools
18
import itertools
19
from pyke import contexts
19
from pyke import contexts
20
20
21
def compile(goal_str):
21
def compile(goal_str):
22
    from pyke import krb_compiler
22
    from pyke import krb_compiler
23
    return prover(goal_str, *krb_compiler.compile_goal(goal_str))
23
    return prover(goal_str, *krb_compiler.compile_goal(goal_str))
24
24
25
class prover(object):
25
class prover(object):
26
    def __init__(self, goal_str, rb_name, goal_name, patterns, python_vars, pattern_vars):
26
    def __init__(self, goal_str, rb_name, goal_name, patterns, pattern_vars):
27
        #print "prover", rb_name, goal_name, patterns, python_vars, pattern_vars
27
        #print "prover", rb_name, goal_name, patterns, pattern_vars
28
        self.goal_str = goal_str
28
        self.goal_str = goal_str
29
        self.rb_name = rb_name
29
        self.rb_name = rb_name
30
        self.goal_name = goal_name
30
        self.goal_name = goal_name
31
        self.patterns = patterns
31
        self.patterns = patterns
32
        self.python_vars = python_vars
33
        self.pattern_vars = pattern_vars
32
        self.pattern_vars = pattern_vars
34
33
35
    def prove(self, engine, **args):
34
    def prove(self, engine, **args):
36
        assert len(args) == len(self.python_vars), \
37
               "incorrect number of arguments to goal: expected %d, got %d" % \
38
                 (len(self.python_vars), len(args))
39
        context = contexts.simple_context()
35
        context = contexts.simple_context()
40
        for var in self.python_vars:
36
        for var, value in args.iteritems():
41
            context.bind(var, context, args[var])
37
            context.bind(var, context, value)
42
        return producer(engine, self.rb_name, self.goal_name, self.patterns,
38
        return producer(engine, self.rb_name, self.goal_name, self.patterns,
43
                        context, self.pattern_vars)
39
                        context, self.pattern_vars)
44
40
45
    def prove_1(self, engine, **args):
41
    def prove_1(self, engine, **args):
46
        try:
42
        try: