我刚开始使用与Jade agent.java集成的剪辑,我的事实和规则加载在不同的.clp文件中,我已经花了很多时间来比较我认为是数字的东西,但由于某种原因,它不起作用,尝试了许多不同的东西,没有什么东西使它工作:这里是我的事实的一部分:
(deffacts products
(product (name "USB Memory") (category storage) (part-number 1234) (price 9.99))
(product (name Amplifier) (category electronics) (part-number 2341) (price 399.99))
(product (name Speakers) (category electronics) (part-number 23241) (price 19.99))
(product (name "iPhone 7") (category smartphone) (part-number 3412) (price 99))
(product (name "Samsung Edge 7") (category smartphone) (part-number 34412) (price 88))
)
And here I have the rules that are not working:
(defrule my-rule14
(not (product (category smartphone) **(price<50)**))
=>
(printout t "no smartphones cheaper than 50" crlf ))
;; Defining a rule for finding smartphones cheaper than 100 dlls
(defrule my-rule15
(product (category smartphone) (name ?nameb) **(price<100))**
=>
(printout t ?nameb " is cheaper than 100 dlls" crlf ))没有一条规则起作用,我试着将比较改为{price<100},(price< 100),(价格< 100),(价格?价格)(测试(<?price< 100))
谢谢。
发布于 2022-05-25 18:43:02
基本编程指南的5.4.1.5和5.4.2节包含了所需语法的相关信息:
CLIPS (6.4 2/9/21)
CLIPS>
(deftemplate product
(slot name)
(slot category)
(slot part-number)
(slot price))
CLIPS>
(deffacts products
(product (name "USB Memory") (category storage) (part-number 1234) (price 9.99))
(product (name Amplifier) (category electronics) (part-number 2341) (price 399.99))
(product (name Speakers) (category electronics) (part-number 23241) (price 19.99))
(product (name "iPhone 7") (category smartphone) (part-number 3412) (price 99))
(product (name "Samsung Edge 7") (category smartphone) (part-number 34412) (price 88)))
CLIPS>
(defrule my-rule14
(not (product (category smartphone) (price ?price&:(< ?price 50))))
=>
(printout t "no smartphones cheaper than 50" crlf))
CLIPS>
(defrule my-rule15
(product (category smartphone) (name ?nameb) (price ?price))
(test (< ?price 100))
=>
(printout t ?nameb " is cheaper than 100 dlls" crlf ))
CLIPS> (reset)
CLIPS> (agenda)
0 my-rule15: f-5
0 my-rule15: f-4
0 my-rule14: *
For a total of 3 activations.
CLIPS> (run)
Samsung Edge 7 is cheaper than 100 dlls
iPhone 7 is cheaper than 100 dlls
no smartphones cheaper than 50
CLIPS> https://stackoverflow.com/questions/72373850
复制相似问题