我一直试图在PyClips中打印变量的值而没有任何成功。任何帮助都将不胜感激。这是代码。
而不是"你是否是晦涩的"它打印"是吗?名字"
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))""")
我们将不胜感激任何帮助
答案 0 :(得分:1)
>>> 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.
>>>