【发布时间】:2015-09-25 13:46:09
【问题描述】:
我阅读了here 如何在剪辑规则的 lhs 上调用 python 函数。
现在我有以下规则:
(defrule python_func_lhs "comment me"
(object (is-a clips_TEST_CLASS) (some_slot ?some_slot_value))
(test (eq (python-call python_print (str-cat "some_slot: " ?some_slot_value)) TRUE))
=>
;(assert (do_something))
)
我的问题是python函数调用了两次,先打印
some_slot:无
然后
some_slot: some_slot_value
似乎包含python函数的第二个规则部分没有“等待”匹配LHS规则的第一部分。
一旦 LHS 规则的第一部分匹配,如何让剪辑只调用一次 python 函数?换句话说,我想等到?some_slot_value 变量有值。
如果可能,我想避免创建多个规则并使用“控制事实”。
【问题讨论】:
-
Jess 和这件事有什么关系?
-
@laune 问题不是特定于 pyclips 的。在 jess 中,还应该可以在规则的 lhs 上调用 java 函数。但你是对的,我会改写问题或删除标签。
-
我刚刚在 Jess 中尝试过
(deffacts someData (Data (obj (new String "A"))))和(defrule find ?data <- (Data (obj ?a)) (test (eq (call ?a length) 1)) => (printout t "find executed" crlf)),效果很好。 -
@laune 感谢您的尝试。我仍在调查这个问题,我认为问题是这样的:“在生成部分匹配时,始终评估规则的 LHS 上的测试条件”。如果使用字段约束(& | ~)可能是一个解决方案,我会尝试。
-
这很可能是一个特定问题,具体取决于基于规则的系统的实施。 CLIPS 只是一个方言家族;规则引擎是单独的野兽。
标签: clips expert-system pyclips