pythonclipsclipspy

How to programmatically define a rule in clipspy?


Just installed clipspy on Fedora 26. I can assert simple facts like so:

>>> from clips import Environment
>>> env = Environment()
>>> env.assert_string('(a)')
ImpliedFact: f-1     (a)

How do I programmatically define a rule please? I can't find any examples or documentation about that. TIA.


Solution

  • You can find the documentation here: clipspy documentation

    However, you can either use build or eval like in CLIPS:

    >>> env.build(...your defrule)
    >>> env.eval("(build ...)")
    

    or you can create it with:

    clips.agenda.Rule(env, rule_you_want_to_define)
    

    Don't forget the " " around your rule definition.