Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (deftemplate persoana (multislot nume)(slot ochi)(slot par)(slot nationalitate))
- (assert (persoana(nume Ion Ionescu)(ochi verzi)(par saten)(nationalitate franceza)))
- (assert (persoana(nume Bogdan Popesscu)(ochi caprui)(par blond)(nationalitate germana)))
- (assert (persoana(nume Ionel Romanu)(ochi albastrii)(par blond)(nationalitate germana)))
- (assert (persoana(nume Cristi Ardelean)(ochi verzi)(par blond)(nationalitate germana)))
- (assert (persoana(nume Mihai Popescu)(ochi purpurii)(par castaniu)(nationalitate romana)))
- (facts)
- (defrule rule1
- (persoana (nume $? ?prenume ?nume)(ochi verzi)(par saten)(nationalitate franceza))
- =>
- (printout t "Regula 1 -> Nume : " ?nume " Prenume " ?prenume crlf))
- (defrule rule2
- (persoana (nume $? ?pn ?n) (ochi ?o & ~albastri) (par ?p & ~negru) (nationalitate ?nt))
- (not (persoana (nume ?pnn & ~ ?pn ?nn & ~?n) (ochi ?o)))
- (not (persoana (nume ?pnnn & ~?pn ?nnn & ~?n) (par ?p)))
- =>
- (printout t "Regula 2 -> Nume: " ?n " Prenume: " ?pn crlf)
- )
- (defrule rule3
- (persoana (nume $? ?pn1 ?n1) (ochi ?o1) (par ?p1 & ~blond) (nationalitate ?nt))
- (test (or (eq ?p1 saten) (eq ?o1 albastri)) )
- (persoana (nume $? ?pn2 ?n2) (ochi ?o2) (par ?p2 & ?p1) (nationalitate ?nt1) )
- (test (or (eq ?p1 saten) (not( eq ?o2 caprui)) ) )
- =>
- (printout t "Regula 3 ->" crlf)
- (printout t "Persoana 1")
- )
- (run)
- (defglobal ?*TASK_PRIORITY_1* = 2)
- (defglobal ?*TASK_PRIORITY_2* = 1)
- (deftemplate relat (slot mode (type STRING)) (slot son (type STRING))
- (slot parent (type STRING)))
- (assert (relat (mode "ako") (son "ballon") (parent "aircraft")))
- (assert (relat (mode "ako") (son "pr.driven") (parent "aircraft")))
- (assert (relat (mode "ako") (son "jet") (parent "aircraft")))
- (assert (relat (mode "ako") (son "blimp") (parent "ballon")))
- (assert (relat (mode "ako") (son "blimp") (parent "pr.driven")))
- (assert (relat (mode "ako") (son "special") (parent "pr.driven")))
- (assert (relat (mode "ako") (son "dc-3") (parent "pr.driven")))
- (assert (relat (mode "ako") (son "dc-9") (parent "jet")))
- (assert (relat (mode "ako") (son "concorde") (parent "jet")))
- (assert (relat (mode "has-shape") (son "ballon") (parent "round")))
- (assert (relat (mode "has-shape") (son "blimp") (parent "ellips")))
- (assert (relat (mode "is-a") (son "good year") (parent "blimp")))
- (assert (relat (mode "is-a") (son "spirit of stl") (parent "special")))
- (assert (relat (mode "is-a") (son "airforce 1") (parent "dc-9")))
- (facts)
- (defrule cauta-solutie-is-a
- (declare (salience ?*TASK_PRIORITY_1*))
- (relat (son ?a))
- ?m <- (relat (mode "is-a") (son ?a) (parent ?q))
- ?n <- (relat (mode "ako") (son ?q) (parent ?p))
- =>
- (assert (relat (parent ?p)))
- (retract ?m ?n))
- (defrule cauta-solutie
- (declare (salience ?*TASK_PRIORITY_1*))
- (relat (son ?a))
- ?v <- (relat (mode "ako") (son ?a) (parent ?p))
- =>
- (assert (relat (parent ?p)))
- (retract ?v)
- )
- (defrule parinte-de-parinte
- (declare (salience ?*TASK_PRIORITY_2*))
- (relat (parent ?p))
- ?v <- (relat (mode "ako") (son ?p) (parent ?q))
- =>
- (retract ?v)
- (assert (relat (parent ?q)))
- )
- (defrule printeaza-solutie
- (declare (salience -1))
- ?n <- (relat (parent ?p))
- =>
- (printout t ?p crlf)
- (retract ?n)
- )
- (run)
- (deftemplate Dama (slot x) (slot y) (slot used(allowed-values TRUE FALSE)))
- (foreach ?x (create$ 1 2 3 4)
- (foreach ?y (create$ 1 2 3 4 )
- (assert (Dama (x ?x) (y ?y) (used FALSE)))
- ))
- (defrule rezolvare
- ?id1<- (Dama (x ?x1) (y ?y ) (used FALSE))
- ?id2<- (Dama (x ?x2 & ~?x1) (y ?y2 & ~?y1) (used FALSE))
- ?id3<- (Dama (x ?x3 & ~?x2 & ~?x1) (y ?y3 & ~?y2 & ~?y1) (used FALSE))
- ?id4<- (Dama (x ?x4 & ~?x3 & ~?x2 & ~?x1) (y ?y4 & ~?y3 & ~?y2 & ~?y1) (used FALSE))
- (test (neq (abs (~ ?x1 ?x2)) (abs (~?y1 ?y2))))
- (test (neq (abs (~ ?x1 ?x3)) (abs (~?y1 ?y3))))
- (test (neq (abs (~ ?x1 ?x4)) (abs (~?y1 ?y4))))
- (test (neq (abs (~ ?x2 ?x3)) (abs (~?y2 ?y3))))
- (test (neq (abs (~ ?x2 ?x4)) (abs (~?y2 ?y4))))
- (test (neq (abs (~ ?x3 ?x4)) (abs (~?y3 ?y4))))
- =>
- )
- (deftemplate Intreb (slot intrebare) (slot raspuns))
- (assert (Intreb (intrebare nel) (raspuns nil)))
- (defrule r1
- (Intreb (intrebare nil) (raspuns nil))
- =>(printout t "It is very big?(yes/no)" crlf)
- (bind ?r (read))
- (assert (Intreb (intrebare "It is very big?") (raspuns ?r)))
- )
- (defrule r2.1
- (Intreb (intrebare "It is very big?") (raspuns yes))
- =>
- (printout t "Does it have along neck?(yes/no)" crlf)
- (bind ?r (read))
- (assert (Intreb (intrebare "Does it have a long neck?") (raspuns ?r)))
- )
- (defrule r2.2
- (Intreb (intrebare "It is very big?") (raspuns no))
- =>
- (printout t "Does is squeak?(yes/no)" crlf)
- (bind ?r (read))
- (assert (Intreb (intrebare "Does it speak?") (raspuns ?r)))
- )
- (defrule r3.1
- )
- (run)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement