Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. (deftemplate persoana (multislot nume)(slot ochi)(slot par)(slot nationalitate))
  2. (assert (persoana(nume Ion Ionescu)(ochi verzi)(par saten)(nationalitate franceza)))
  3. (assert (persoana(nume Bogdan Popesscu)(ochi caprui)(par blond)(nationalitate germana)))
  4. (assert (persoana(nume Ionel Romanu)(ochi albastrii)(par blond)(nationalitate germana)))
  5. (assert (persoana(nume Cristi Ardelean)(ochi verzi)(par blond)(nationalitate germana)))
  6. (assert (persoana(nume Mihai Popescu)(ochi purpurii)(par castaniu)(nationalitate romana)))
  7.  
  8. (facts)
  9.  
  10. (defrule rule1
  11. (persoana (nume $? ?prenume ?nume)(ochi verzi)(par saten)(nationalitate franceza))
  12. =>
  13. (printout t "Regula 1 -> Nume : " ?nume " Prenume " ?prenume crlf))
  14.  
  15. (defrule rule2
  16. (persoana (nume $? ?pn ?n) (ochi ?o & ~albastri) (par ?p & ~negru) (nationalitate ?nt))
  17. (not (persoana (nume ?pnn & ~ ?pn ?nn & ~?n) (ochi ?o)))
  18. (not (persoana (nume ?pnnn & ~?pn ?nnn & ~?n) (par ?p)))
  19. =>
  20. (printout t "Regula 2 -> Nume: " ?n " Prenume: " ?pn crlf)
  21. )
  22. (defrule rule3
  23. (persoana (nume $? ?pn1 ?n1) (ochi ?o1) (par ?p1 & ~blond) (nationalitate ?nt))
  24. (test (or (eq ?p1 saten) (eq ?o1 albastri)) )
  25. (persoana (nume $? ?pn2 ?n2) (ochi ?o2) (par ?p2 & ?p1) (nationalitate ?nt1) )
  26. (test (or (eq ?p1 saten) (not( eq ?o2 caprui)) ) )
  27. =>
  28. (printout t "Regula 3 ->" crlf)
  29. (printout t "Persoana 1")
  30. )
  31. (run)
  32.  
  33.  
  34. (defglobal ?*TASK_PRIORITY_1* = 2)
  35. (defglobal ?*TASK_PRIORITY_2* = 1)
  36. (deftemplate relat (slot mode (type STRING)) (slot son (type STRING))
  37. (slot parent (type STRING)))
  38. (assert (relat (mode "ako") (son "ballon") (parent "aircraft")))
  39. (assert (relat (mode "ako") (son "pr.driven") (parent "aircraft")))
  40. (assert (relat (mode "ako") (son "jet") (parent "aircraft")))
  41. (assert (relat (mode "ako") (son "blimp") (parent "ballon")))
  42. (assert (relat (mode "ako") (son "blimp") (parent "pr.driven")))
  43. (assert (relat (mode "ako") (son "special") (parent "pr.driven")))
  44. (assert (relat (mode "ako") (son "dc-3") (parent "pr.driven")))
  45. (assert (relat (mode "ako") (son "dc-9") (parent "jet")))
  46. (assert (relat (mode "ako") (son "concorde") (parent "jet")))
  47. (assert (relat (mode "has-shape") (son "ballon") (parent "round")))
  48. (assert (relat (mode "has-shape") (son "blimp") (parent "ellips")))
  49. (assert (relat (mode "is-a") (son "good year") (parent "blimp")))
  50. (assert (relat (mode "is-a") (son "spirit of stl") (parent "special")))
  51. (assert (relat (mode "is-a") (son "airforce 1") (parent "dc-9")))
  52.  
  53. (facts)
  54.  
  55. (defrule cauta-solutie-is-a
  56. (declare (salience ?*TASK_PRIORITY_1*))
  57. (relat (son ?a))
  58. ?m <- (relat (mode "is-a") (son ?a) (parent ?q))
  59. ?n <- (relat (mode "ako") (son ?q) (parent ?p))
  60. =>
  61. (assert (relat (parent ?p)))
  62. (retract ?m ?n))
  63. (defrule cauta-solutie
  64. (declare (salience ?*TASK_PRIORITY_1*))
  65. (relat (son ?a))
  66. ?v <- (relat (mode "ako") (son ?a) (parent ?p))
  67. =>
  68. (assert (relat (parent ?p)))
  69. (retract ?v)
  70. )
  71.  
  72. (defrule parinte-de-parinte
  73. (declare (salience ?*TASK_PRIORITY_2*))
  74. (relat (parent ?p))
  75. ?v <- (relat (mode "ako") (son ?p) (parent ?q))
  76. =>
  77. (retract ?v)
  78. (assert (relat (parent ?q)))
  79. )
  80. (defrule printeaza-solutie
  81. (declare (salience -1))
  82. ?n <- (relat (parent ?p))
  83. =>
  84. (printout t ?p crlf)
  85. (retract ?n)
  86. )
  87. (run)
  88.  
  89.  
  90.  
  91. (deftemplate Dama (slot x) (slot y) (slot used(allowed-values TRUE FALSE)))
  92. (foreach ?x (create$ 1 2 3 4)
  93. (foreach ?y (create$ 1 2 3 4 )
  94. (assert (Dama (x ?x) (y ?y) (used FALSE)))
  95. ))
  96. (defrule rezolvare
  97. ?id1<- (Dama (x ?x1) (y ?y ) (used FALSE))
  98. ?id2<- (Dama (x ?x2 & ~?x1) (y ?y2 & ~?y1) (used FALSE))
  99. ?id3<- (Dama (x ?x3 & ~?x2 & ~?x1) (y ?y3 & ~?y2 & ~?y1) (used FALSE))
  100. ?id4<- (Dama (x ?x4 & ~?x3 & ~?x2 & ~?x1) (y ?y4 & ~?y3 & ~?y2 & ~?y1) (used FALSE))
  101. (test (neq (abs (~ ?x1 ?x2)) (abs (~?y1 ?y2))))
  102. (test (neq (abs (~ ?x1 ?x3)) (abs (~?y1 ?y3))))
  103. (test (neq (abs (~ ?x1 ?x4)) (abs (~?y1 ?y4))))
  104. (test (neq (abs (~ ?x2 ?x3)) (abs (~?y2 ?y3))))
  105. (test (neq (abs (~ ?x2 ?x4)) (abs (~?y2 ?y4))))
  106. (test (neq (abs (~ ?x3 ?x4)) (abs (~?y3 ?y4))))
  107. =>
  108.  
  109. )
  110.  
  111.  
  112. (deftemplate Intreb (slot intrebare) (slot raspuns))
  113. (assert (Intreb (intrebare nel) (raspuns nil)))
  114. (defrule r1
  115. (Intreb (intrebare nil) (raspuns nil))
  116. =>(printout t "It is very big?(yes/no)" crlf)
  117. (bind ?r (read))
  118. (assert (Intreb (intrebare "It is very big?") (raspuns ?r)))
  119. )
  120. (defrule r2.1
  121. (Intreb (intrebare "It is very big?") (raspuns yes))
  122. =>
  123. (printout t "Does it have along neck?(yes/no)" crlf)
  124. (bind ?r (read))
  125. (assert (Intreb (intrebare "Does it have a long neck?") (raspuns ?r)))
  126. )
  127. (defrule r2.2
  128. (Intreb (intrebare "It is very big?") (raspuns no))
  129. =>
  130. (printout t "Does is squeak?(yes/no)" crlf)
  131. (bind ?r (read))
  132. (assert (Intreb (intrebare "Does it speak?") (raspuns ?r)))
  133. )
  134. (defrule r3.1
  135.  
  136. )
  137.  
  138. (run)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement