Diff of /examples/family_relations/test.py [9c0a10] .. [f16399]  Maximize  Restore

Switch to unified view

a/examples/family_relations/test.py b/examples/family_relations/test.py
...
...
46
from pyke import knowledge_engine, krb_traceback, goal
46
from pyke import knowledge_engine, krb_traceback, goal
47
47
48
# Compile and load .krb files in same directory that I'm in (recursively).
48
# Compile and load .krb files in same directory that I'm in (recursively).
49
engine = knowledge_engine.engine('examples.family_relations')
49
engine = knowledge_engine.engine('examples.family_relations')
50
50
51
fc_goal = goal.compile('family.how_related(%person1, $person2, $relationship)')
51
fc_goal = goal.compile('family.how_related($person1, $person2, $relationship)')
52
52
53
def fc_test(person1 = 'bruce'):
53
def fc_test(person1 = 'bruce'):
54
    '''
54
    '''
55
        This function runs the forward-chaining example (fc_example.krb).
55
        This function runs the forward-chaining example (fc_example.krb).
56
    '''
56
    '''
...
...
82
    fc_time = fc_end_time - start_time
82
    fc_time = fc_end_time - start_time
83
83
84
    print "doing proof"
84
    print "doing proof"
85
    try:
85
    try:
86
        with engine.prove_goal(
86
        with engine.prove_goal(
87
               'bc_example.how_related(%person1, $person2, $relationship)',
87
               'bc_example.how_related($person1, $person2, $relationship)',
88
               person1=person1) \
88
               person1=person1) \
89
          as gen:
89
          as gen:
90
            for vars, plan in gen:
90
            for vars, plan in gen:
91
                print "%s, %s are %s" % \
91
                print "%s, %s are %s" % \
92
                        (person1, vars['person2'], vars['relationship'])
92
                        (person1, vars['person2'], vars['relationship'])
...
...
111
    fc_time = fc_end_time - start_time
111
    fc_time = fc_end_time - start_time
112
112
113
    print "doing proof"
113
    print "doing proof"
114
    try:
114
    try:
115
        with engine.prove_goal(
115
        with engine.prove_goal(
116
               'bc2_example.how_related(%person1, $person2, $relationship)',
116
               'bc2_example.how_related($person1, $person2, $relationship)',
117
               person1=person1) \
117
               person1=person1) \
118
          as gen:
118
          as gen:
119
            for vars, plan in gen:
119
            for vars, plan in gen:
120
                print "%s, %s are %s" % \
120
                print "%s, %s are %s" % \
121
                        (person1, vars['person2'], vars['relationship'])
121
                        (person1, vars['person2'], vars['relationship'])
...
...
143
143
144
    print "doing proof"
144
    print "doing proof"
145
    try:
145
    try:
146
        # In this case, the relationship is returned when you run the plan.
146
        # In this case, the relationship is returned when you run the plan.
147
        with engine.prove_goal(
147
        with engine.prove_goal(
148
               'example.how_related(%person1, $person2)',
148
               'example.how_related($person1, $person2)',
149
               person1=person1) \
149
               person1=person1) \
150
          as gen:
150
          as gen:
151
            for vars, plan in gen:
151
            for vars, plan in gen:
152
                print "%s, %s are %s" % (person1, vars['person2'], plan())
152
                print "%s, %s are %s" % (person1, vars['person2'], plan())
153
    except StandardError:
153
    except StandardError:

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks