CLIPS - 打印输出年龄的学生(defrule)与插入年份的deftemplate

时间:2018-05-01 12:10:25

标签: clips

我有一个deftemplate:

    (deftemplate student
    (multislot fio (type SYMBOL)(cardinality 1 3))
    (slot den_rozhdeniya (type INTEGER))
    (slot mecyaz_rozhdeniya (type SYMBOL))
    (slot god_rozhdeniya (type INTEGER))
    (multislot data_postupleniya (type SYMBOL NUMBER))
    (slot facultet (default fit)(type SYMBOL))
    (slot gruppa (type SYMBOL INTEGER))
    (multislot adress (type SYMBOL INTEGER))
    (multislot telefon (type NUMBER))
    (slot sredniy_ball(range 0 10) (type INTEGER FLOAT))
)

还有5名学生:

(assert (student(fio Semenova Yuliya Igorevna) (den_rozhdeniya 10)(mecyaz_rozhdeniya oktyabr) (god_rozhdeniya 2000) (data_postupleniya 29 avgust 2014)(gruppa 14-itd) (adress Molodeznaya 108, kv. 10) (telefon 23 56 89) (sredniy_ball 9.5))

(student(fio Korneeva Alina Sergeevna) (den_rozhdeniya 5)(mecyaz_rozhdeniya yanvar) (god_rozhdeniya 2001) (data_postupleniya 29 avgust 2015)(gruppa 15-itd) (adress Kalinina 8, kv. 4) (telefon 43 45 02) (sredniy_ball 8.5))

(student(fio Lenskaya Ekaterina Antonovna) (den_rozhdeniya 10)(mecyaz_rozhdeniya yanvar) (god_rozhdeniya 2000) (data_postupleniya 29 avgust 2016)(gruppa 16-itd) (adress Molodeznaya 1, kv. 78) (telefon 23 56 89) (sredniy_ball 7))

(student(fio Petrov Slava Andreevich) (den_rozhdeniya 8)(mecyaz_rozhdeniya may) (god_rozhdeniya 2002)(data_postupleniya 29 avgust 2017)(gruppa 17-itd) (adress Pyshkina 5, kv. 13) (telefon 23 85 12) (sredniy_ball 5.5))

(student(fio Ivanova Svetlana Kirilovna)(den_rozhdeniya 25)(mecyaz_rozhdeniya avgust) (god_rozhdeniya 2001) (data_postupleniya 29 avgust 2015)(gruppa 15-itd) (adress Molodeznaya 5, kv. 45) (telefon 78 32 51) (sredniy_ball 9))
)

我无法找到解决方案,如何打印这个规则时代的学生。

(god_rozhdeniya 2000)这是与出生年份和打印输出的插槽应该是:

  

Semenova Yuliya Igorevna 18

这是我的违规行为不起作用:

(defrule first
(student (fio ?fio)(god_rozhdeniya ?god_rozhdeniya) (age ?age)
(?age (- 2018 ?god_rozhdeniya))
=>
(printout t ?fio  ? age crlf))

1 个答案:

答案 0 :(得分:0)

         CLIPS (6.31 2/3/18)
CLIPS> 
(deftemplate student
    (multislot fio (type SYMBOL)(cardinality 1 3))
    (slot den_rozhdeniya (type INTEGER))
    (slot mecyaz_rozhdeniya (type SYMBOL))
    (slot god_rozhdeniya (type INTEGER))
    (multislot data_postupleniya (type SYMBOL NUMBER))
    (slot facultet (default fit)(type SYMBOL))
    (slot gruppa (type SYMBOL INTEGER))
    (multislot adress (type SYMBOL INTEGER))
    (multislot telefon (type NUMBER))
    (slot sredniy_ball(range 0 10) (type INTEGER FLOAT)))
CLIPS> 
(deffacts students 
   (student (fio Semenova Yuliya Igorevna) 
            (den_rozhdeniya 10)
            (mecyaz_rozhdeniya oktyabr)
            (god_rozhdeniya 2000)
            (data_postupleniya 29 avgust 2014)
            (gruppa 14-itd)
            (adress Molodeznaya 108, kv. 10)
            (telefon 23 56 89)
            (sredniy_ball 9.5))
   (student (fio Korneeva Alina Sergeevna)
            (den_rozhdeniya 5)(mecyaz_rozhdeniya yanvar)
            (god_rozhdeniya 2001)
            (data_postupleniya 29 avgust 2015)
            (gruppa 15-itd)
            (adress Kalinina 8, kv. 4)
            (telefon 43 45 02)
            (sredniy_ball 8.5))
   (student (fio Lenskaya Ekaterina Antonovna)
            (den_rozhdeniya 10)
            (mecyaz_rozhdeniya yanvar)
            (god_rozhdeniya 2000)
            (data_postupleniya 29 avgust 2016)
            (gruppa 16-itd)
            (adress Molodeznaya 1, kv. 78)
            (telefon 23 56 89)
            (sredniy_ball 7))
   (student (fio Petrov Slava Andreevich)
            (den_rozhdeniya 8)
            (mecyaz_rozhdeniya may)
            (god_rozhdeniya 2002)
            (data_postupleniya 29 avgust 2017)
            (gruppa 17-itd)
            (adress Pyshkina 5, kv. 13)
            (telefon 23 85 12)
            (sredniy_ball 5.5))
   (student (fio Ivanova Svetlana Kirilovna)
            (den_rozhdeniya 25)
            (mecyaz_rozhdeniya avgust) 
            (god_rozhdeniya 2001) 
            (data_postupleniya 29 avgust 2015)
            (gruppa 15-itd) 
            (adress Molodeznaya 5, kv. 45) 
            (telefon 78 32 51) 
            (sredniy_ball 9)))
CLIPS> 
(defrule first
   (student (fio $?fio)
            (god_rozhdeniya ?god_rozhdeniya))
  =>
  ;(bind ?year 2018)
  (bind ?year (nth$ 1 (local-time)))
  (printout t (implode$ ?fio) " " (- ?year ?god_rozhdeniya) crlf))
CLIPS> (reset)
CLIPS> (run)
Ivanova Svetlana Kirilovna 17
Petrov Slava Andreevich 16
Lenskaya Ekaterina Antonovna 18
Korneeva Alina Sergeevna 17
Semenova Yuliya Igorevna 18
CLIPS>