Using PyClips, I am trying to create rules in Clips that dynamically retrieve data from the Python interpreter. To do this, I register the external function described in the manual .
The code below is a toy example of a problem. I do this because I have an application with a large body of data, in the form of an SQL database, which I want to use with Clips. However, I donβt want to waste time converting all this data into Clips statements if I can just βconnectβ the clips directly to the Python namespace.
However, when I try to create a rule, I get an error message. What am I doing wrong?
import clips #user = True #def py_getvar(k): # return globals().get(k) def py_getvar(k): return True if globals.get(k) else clips.Symbol('FALSE') clips.RegisterPythonFunction(py_getvar) print clips.Eval("(python-call py_getvar user)") # Outputs "nil" # If globals().get('user') is not None: assert something clips.BuildRule("user-rule", "(neq (python-call py_getvar user) nil)", "(assert (user-present))", "the user rule") #clips.BuildRule("user-rule", "(python-call py_getvar user)", "(assert (user-present))", "the user rule") clips.Run() clips.PrintFacts()
Cerin source share