Jess模式匹配'不是'规则的条件

时间:2015-06-15 15:50:11

标签: jess

我在jess上玩。我想制定不使用'〜'。

的规则

这是我的代码。

(clear)
(reset)

(deftemplate person
    (slot name)
    (slot eyes)
    (slot hair))

(defrule person-without-brown-hair
    (person (name ?name) (hair ?hair&:(not brown)))
=>
    (printout t ?name " does not have brown hair." crlf))

(assert (person (name "Jeon") (eyes green) (hair brown)))
(assert (person (name "Park") (eyes blue) (hair red)))

(run)

我的预期是多变的?头发不是棕色的。

1 个答案:

答案 0 :(得分:2)

请注意,函数(not ...)否定了它的参数。 TRUE为true,FALSE为false,任何其他符号为true。

要测试广告位值是否等于某个值,请使用(eq ...)(neq ...)(= ...)(<> ...)

(defrule person-without-brown-hair
    (person (name ?name) (hair ?hair&:(neq ?hair brown)))
=>
    (printout t ?name " does not have brown hair." crlf))

结果:

Park does not have brown hair.
1

直接匹配当然更可取。