I am brand spanking new to JESS and i wanted to know if any could help with
this question. I am just trying to see how i could out put the childs grand
parent. Here is the code.

;;;*************
;;;* TEMPLATES *
;;;*************

(deftemplate member (slot child)(slot mother)(slot father)(slot gender))

;;;*****************
;;;* INITIAL STATE *
;;;*****************

(deffacts family
(member (child "Alex")(mother "Carmen")(father "Miguel")(gender "Male"))
(member (child "Loren")(mother "Carmen")(father "Miguel")(gender "Female"))
(member (child "Carmen")(mother "Rosa")(father "Jorge")(gender "Female"))
(member (child "Miguel")(mother "Josefina")(father "Octavio")(gender
"Male"))
)

;;;******************
;;;* FUNCTIONS *
;;;******************

(deffunction get-grandparents (?child)
(printout t ?child " <<< ")
)

(deffunction select-relation (?gender ?relation)
;;;CHECK IS BROTHER/SISTER
(if (eq ?gender "Female")
then
;;;THESE ARE FEMALES
(if (eq ?relation "sibling")
then
(return "sister"))
;;; (if (eq ?relation "grandparent")
;;; then
;;; (return "grandmother"))



else
;;;THESE ARE MALES
(if (eq ?relation "sibling")
then
(return "brother"))
;;; (if (eq ?relation "grandparent")
;;; then
;;; (return "grandfather"))
)
)



;;;******************
;;;* RULES *
;;;******************

;;;;;Find a child's mom
(defrule findmom
(declare (salience 50))
(member (mother ?mom) (child ?child))
(ask ?child)
=>
(printout t ?child "'s mom is " ?mom crlf))

;;;;;Find a child's dad
(defrule finddad
(declare (salience 40))
(member (father ?dad) (child ?child))
(ask ?child)
=>
(printout t ?child "'s dad is " ?dad crlf))

;;;;;Find a child's sibling (brother/sister)
(defrule findsibling
(declare (salience 30))
(member (child ?sibling))
(member (father ?dad) (child ?sibling))
(member (father ?dad) (child ?child))
(member (gender ?gender) (child ?sibling))
(ask ?child)
(ask ~?sibling)
=>
(printout t ?child "'s " (select-relation ?gender "sibling") " is "?sibling
crlf))

;;;;;Find a child's grandparents (grandmother/grandfather)
(defrule findgrandparent
(declare (salience 20))
(member (father ?dad) (child ?child))
(ask ?child)
=>
(printout t ?dad "'s " " ise " crlf))





;;;;;;prompt user for questions. This rule fires first.
(defrule askQuestions
=>
(printout t crlf "*****************************************"crlf
"Type a child's name in quotes and I will tell you the name of the child's
parents, grandparents, uncle/aunt, and sibblings." crlf )
(assert (ask (read)))
)

;;;;;; Initialize working memory (facts)
;;;;;; Note: function (read) will be replaced with user input in the command
console.
(reset)
(run)
--
View this message in context: 
http://www.nabble.com/Newbie-question-tp15518587p15518587.html
Sent from the Jess mailing list archive at Nabble.com.

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to