Pyclipsを使用してPython関数を呼び出すためのルールアクティベーションを取得する方法
-
12-11-2019 - |
質問
pyclips で実験しています。ルールが有効になっているとき、それはPython関数を呼び出します。
これまでのところ私が持っているものです:
import clips
def addf(a, b):
return a + b
clips.RegisterPythonFunction(addf)
clips.Build("""
(defrule duck
(animal-is duck)
=>
(assert (sound-is quack))
(printout t "it’s a duck" crlf))
(python-call addf 40 2 )
""")
.
しかし、「Animal-Is Duck」という事実をアサートすると、Python関数が呼び出されていません:
>>> clips.Assert("(animal-is duck)")
<Fact 'f-0': fact object at 0x7fe4cb323720>
>>> clips.Run()
0
.
私は何をしていますか?
解決
python-call
を去ると、ルールを閉じるのが短すぎる括弧があります。
clips.Build("""
(defrule duck
(animal-is duck)
=>
(assert (sound-is quack))
(printout t "it's a duck" crlf))
(python-call addf 40 2 ) ^
""") ^ |
| this one
|
should go here
.
addf
が実際に返されたことを確認したい場合は、結果をバインドして印刷することができます。
clips.Build("""
(defrule duck
(animal-is duck)
=>
(assert (sound-is quack))
(printout t \"it's a duck\" crlf)
(bind ?tot (python-call addf 40 2 ))
(printout t ?tot crlf))
""")
clips.Assert("(animal-is duck)")
clips.Run()
t = clips.StdoutStream.Read()
print t
. 所属していません StackOverflow