Jess 模式匹配 'not' 规则条件
Jess pattern matching 'not' condition on rule
我在玩 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)
我的预期是可变的?头发不是棕色的。
请注意,函数 (not ...)
否定其参数。 TRUE 为真,FALSE 为假,其他任何符号都为真。
要测试槽值是否等于某个值,请使用 (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
直接匹配当然更好
我在玩 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)
我的预期是可变的?头发不是棕色的。
请注意,函数 (not ...)
否定其参数。 TRUE 为真,FALSE 为假,其他任何符号都为真。
要测试槽值是否等于某个值,请使用 (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
直接匹配当然更好