def test_newWorkingMemory(self): r = Record() mem = drools.newWorkingMemory("TestDrools", (JythonRule(),)) mem.assertObject(r) self.assertEquals(r.n, 0) mem.fireAllRules() self.assertEquals(r.n, 1)
class B2D: def __init__(self): self.salience = 10 self.parameters = (('b', State), ('d', State)) def condition_B(b, d): return b.name == 'B' and b.state == FINISHED def condition_D(b, d): return d.name == 'D' and d.state == NOTRUN def consequence(workingMemory, b, d): print d.name + ' finished' d.state = FINISHED workingMemory.modifyObject(workingMemory.getFactHandle(d), d) self.condition_B = condition_B self.condition_D = condition_D self.consequence = consequence if __name__ == '__main__': workingMemory = drools.newWorkingMemory('State', (Bootstrap(), A2B(), B2C(), B2D())) for x in ([State(x) for x in 'A B C D'.split()]): workingMemory.assertObject(x) workingMemory.fireAllRules() # Copyright (c) 2005 Eric Dobbs Some rights reserved. # # This work is licensed under the Creative Commons Attribution # License. To view a copy of this license, visit # http://creativecommons.org/licenses/by/2.0/ or send a letter to # Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, # USA.
return f1.value != -1L def condition_d(f1, f2, f3): return f2.value != -1L def condition_e(f1, f2, f3): return f3.value == -1L def consequence(workingMemory, f1, f2, f3): f3.value = f1.value + f2.value print '%s == %s' %(f3.sequence, f3.value) workingMemory.modifyObject(workingMemory.getFactHandle(f3), f3) workingMemory.retractObject(workingMemory.getFactHandle(f1)) self.condition_a = condition_a self.condition_b = condition_b self.condition_c = condition_c self.condition_d = condition_d self.condition_e = condition_e self.consequence = consequence if __name__ == '__main__': workingMemory = drools.newWorkingMemory('Fibonacci', (Recurse(), Bootstrap1(), Bootstrap2(), Calculate())) workingMemory.assertObject(Fibonacci(50)) workingMemory.fireAllRules() # Copyright (c) 2005 Eric Dobbs Some rights reserved. # # This work is licensed under the Creative Commons Attribution # License. To view a copy of this license, visit # http://creativecommons.org/licenses/by/2.0/ or send a letter to # Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, # USA.