Search code examples
python-2.7clipsexpert-systempyclips

Displaying the value of a variable in PyClips


I have been trying to print the value of a variable in PyClips without any success.Any help would be appreciated. Here is the code.

Instead of "Are you observative" it prints "Are you ?name"

def clips_raw_input(prompt):
    return clips.String(raw_input(prompt))

clips.RegisterPythonFunction(clips_raw_input, "input")


clips.Assert("(quality observative) ")
clips.Assert("(quality communicative) ")
clips.Assert("(quality emotionally-stable) ")
clips.Assert("(has human true)")

r1 = clips.BuildRule(
       "what-are-qualities",
       """(quality ?name)
       (not (has ?name ?))""",
        """(bind ?response (python-call input Are you ?name))
       (assert (has ?name ?response))""")

Any help will be appreciated


Solution

  • >>> import clips
    >>> def clips_raw_input(prompt):
    ...         return clips.String(raw_input(prompt))
    ... 
    >>> clips.RegisterPythonFunction(clips_raw_input, "input")
    >>> r1 = clips.BuildRule(
    ...        "what-are-qualities",
    ...        """(quality ?name)
    ...        (not (has ?name ?))""",
    ...        """(bind ?response (python-call input (str-cat "Are you " ?name "? ")))
    ...        (assert (has ?name ?response))""")
    >>> clips.Reset()
    >>> clips.Assert("(quality observative) ")
    <Fact 'f-1': fact object at 0x10450b330>
    >>> clips.Assert("(quality communicative) ")
    <Fact 'f-2': fact object at 0x10450b360>
    >>> clips.Assert("(quality emotionally-stable) ")
    <Fact 'f-3': fact object at 0x10450b3f0>
    >>> clips.Assert("(has human true)")
    <Fact 'f-4': fact object at 0x10450b450>
    >>> clips.Run()
    Are you emotionally-stable? yes
    Are you communicative? no
    Are you observative? yes
    3
    >>> clips.PrintFacts()
    f-0     (initial-fact)
    f-1     (quality observative)
    f-2     (quality communicative)
    f-3     (quality emotionally-stable)
    f-4     (has human true)
    f-5     (has emotionally-stable "yes")
    f-6     (has communicative "no")
    f-7     (has observative "yes")
    For a total of 8 facts.
    >>>