我正在尝试通过以下JessTab规则找到家庭本体论中主张的人们的平均年龄:
(defrule print_people_total_age
(object (https://wiki.csc.calpoly.edu/OntologyTutorial/family_example.owl#age ?a1))
=>
(bind ?s 0)
(bind ?num 0)
(foreach ?a (create$ ?a1) (+ ?s ?a) (++ ?num) (printout t "Total age " ?s " and average age is " (/ ?s ?num) " of persons" crlf)))
该规则可以很好地编译,但是在激活时会出现以下错误:
Jess reported an error in routine +
while executing (+ ?s ?a)
while executing (foreach ?a (create$ ?a1) (+ ?s ?a) (++ ?num) (printout t "Total age " ?s " and average age is " (/ ?s ?num) " of persons" crlf))
while executing defrule MAIN::print_people_total_ageSSS
while executing (run).
Message: Not a number: "~@http://www.w3.org/2001/XMLSchema#integer 20".
我哪里错了?
您需要了解规则执行的基础知识,最值得注意的是,与规则匹配的每个事实(或一组事实)都会导致该规则的执行,并且所有这些执行彼此独立。为了合并包含在多个事实中的数据,您可以使用累积的CE;否则,可能会失败。在更复杂的情况下,可能需要一个辅助事实。
(defrule sumofages
?res <- (accumulate (progn (bind ?s 0)(bind ?n))
(progn (bind ?s (+ ?s ?a)) (++ ?n))
(create$ ?n ?s)
(object (age ?a)))
=>
(bind ?s (nth$ 2 ?res))
(bind ?n (nth$ 1 ?res))
(printout t "Total age " ?s
" and average age is " (/ ?s ?n) " of persons" crlf))
您还应该确保了解算术功能的基本原理。(+ ?s ?a)?
添加但不更改操作数。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句