None of the rules here match the "need-X" trigger facts that the
backward-chaining mechanism uses. You should study the example at
http://www.jessrules.com/jess/docs/61/language.html#chaining .
Two additional notes on this code: first, indenting your code helps
tremendously in making it readable; this is very hard for us to
read. Second, you can write this:
(call (new java.lang.String (fetch reponse) ) startsWith "m")
like this:
((fetch reponse) startsWith m)
I think ben said salma wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hello,
>
> i'm writing a simple example to show how Jess do the backward chaining.here
> my example:
> ;;****************
> ;;* DEFFUNCTIONS *
> ;;****************
> (deffunction ask-question (?question $?allowed-values)
> (printout t ?question )
> (bind ?answer (read))
> (if (lexemep ?answer)
> then (bind ?answer (lowcase ?answer))
> (store answer ?answer) )
> (while (eq FALSE (member$ ?answer ?allowed-values)) do
> (printout t ?question crlf)
> (bind ?answer (read))
> (if (lexemep ?answer)
> then (bind ?answer (lowcase ?answer))))
> (store reponse ?answer))
> (deffunction yes-or-no-p (?question)
> (bind ?response (ask-question ?question "oui" "non" "o" "n"))
> (bind ?reponse (fetch reponse))
> (import java.lang.String )
> (new java.lang.String "reponse" )
> (if (call (new java.lang.String (fetch reponse) ) startsWith "o")
> then TRUE
> else FALSE))
> ;;;***************************
> ;;;*DEFINITIONS DES DEFTEMPLATE *
> ;;;***************************
> (deftemplate assassin
> (slot noma)
> (slot nomv)
> (slot jour))
> (deftemplate p-desire-t
> (slot nomdt)
> (slot nomdv))
> (deftemplate a-interet-t
> (slot nomit)
> (slot nomiv))
> ;;;**********************
> ;;;* REGLES D'INFERENCE *
> ;;;**********************
> (defrule assassinat "R1"
> (declare (salience 30))
> (poss_de-arme ?x)
> (cong_ ?x dimanche)
> (p-desire-t(nomdt ?x) (nomdv ali))
> (suspect ?x)
> =>
> (assert (assassin(noma ?x)(nomv ali) (jour dimanche)))
> (printout t ?x " a tu_ Ali dimanche" crlf)
> (retract 1))
> (do-backward-chaining a-interet-t)
> (do-backward-chaining p-desire-t)
> ;(set-strategy breadth)
> (defrule nom-suspect "R2"
> (declare (salience 10))
> =>
> (ask-question "Ali a _t_ assassin_ dimanche. Qui suspectez vous pouvoir le
> tuer (karim/sami/mohamed/jamel)?"
> "karim" "sami" "mohamed" "jamel")
> (if (call (new java.lang.String (fetch reponse) ) startsWith "k")
> then (assert(suspect karim))
> (if(yes-or-no-p "Est ce que votre suspect poss_de une arme (oui/non)?")
> then (assert(poss_de-arme karim))
> else (retract 1)(printout t " votre suspect ne peut pas _tre le tueur" crlf
> crlf)));
> (if (call (new java.lang.String (fetch reponse) ) startsWith "s")
> then (assert(suspect sami))
> (if(yes-or-no-p "Est ce que votre suspect poss_de une arme (oui/non)?")
> then (assert(poss_de-arme sami))
> else (retract 1)(printout t " votre suspect ne peut pas _tre le tueur" crlf
> crlf)))
> (if (call (new java.lang.String (fetch reponse) ) startsWith "m")
> then (assert(suspect mohamed))
> (if(yes-or-no-p "Est ce que votre suspect poss_de une arme (oui/non)?")
> then (assert(poss_de-arme mohamed))
> else (retract 1)(printout t " votre suspect ne peut pas _tre le tueur" crlf
> crlf)))
> (if (call (new java.lang.String (fetch reponse) ) startsWith "j")
> then (assert(suspect jamel))
> (if(yes-or-no-p "Est ce que votre suspect poss_de une arme (oui/non)?")
> then (assert(poss_de-arme jamel))
> else (retract 1)(printout t " votre suspect ne peut pas _tre le tueur" crlf
> crlf))))
>
> (defrule cong_"R3"
> (declare (salience 10))
> (poss_de-arme ?x)
> (suspect ?x)
> =>
> (if(yes-or-no-p "Est ce que votre suspect est en cong_ dimanche le jour du
> crime (oui/non)?")
> then (assert(cong_ ?x dimanche))
> else (retract 1)(printout t " votre suspect ne peut pas _tre le tueur" crlf
> crlf)))
>
>
> (defrule peut-desire-tuer "R4"
> (declare (salience 10))
> (desire-vonger ?x ali)
> (suspect ?x)
> =>
> (assert(p-desire-t (nomdt ?x) (nomdv ali))))
>
> (defrule peut-desire-tuer "R5"
> (declare (salience 10))
> (a-interet-t (nomit ?x) (nomiv ali))
> (suspect ?x)
> =>
> (assert(p-desire-t (nomdt ?x) (nomdv ali))))
>
> (defrule des-vonger "R6"
> (declare (salience 10))
> (suspect ?x)
> =>
> (if(yes-or-no-p "Est ce que votre suspect d_sirait se vonger de Ali
> (oui/non)?")
> then (assert(desire-vonger ?x ali))))
>
> (defrule a-interet-tuer "R7"
> (declare (salience 10))
> (h_rite ?x ali)
> (suspect ?x)
> =>
> (assert(a-interet-t (nomit ?x) (nomiv ali))))
>
> (defrule h_rite "R8"
> (declare (salience 10))
> (suspect ?x)
> =>
> (if(yes-or-no-p "Est ce que votre suspect h_rite de Ali (oui/non)?")
> then (assert(h_rite ?x ali))))
>
> (defrule a-interet-tuer "R9"
> (declare (salience 10))
> (doit-argent ?x ali)
> (suspect ?x)
> =>
> (assert(a-interet-t (nomit ?x) (nomiv ali))))
> (defrule doit-argent "R10"
> (declare (salience 10))
> (suspect ?x)
> =>
> (if(yes-or-no-p "Est ce que votre suspect doit de l'argent _ Ali
> (oui/non)?")
> then (assert(doit-argent ?x ali))))
>
> (defrule a-interet-tuer "R11"
> (declare (salience 10))
> (vu-commettre-crime ali ?x)
> (suspect ?x)
> =>
> (assert(a-interet-t (nomit ?x) (nomiv ali))))
>
> (defrule voir-commettre "R12"
> (declare (salience 10))
> (suspect ?x)
> =>
> (if(yes-or-no-p "Est ce que Ali a vu votre suspect commettre un crime
> (oui/non)?")
> then (assert(vu-commettre-crime ali ?x))))
>
> the example look like:
> if A, B, C then Z
> if E then C
> if F tnen C
> if G then F
> if H then F
> if I then F
> KB={A, B}
>
> i want to evaluate Z with a backward chaining . it run succeffully if i
> insert a fact" I" that correspond with the rule if F then C , but it fail if
> i insert the fact H or G .
> . is there something wrong in my rules ?
>
>
> ---------------------------------
> Yahoo! Mail r_invente le mail ! D_couvrez le nouveau Yahoo! Mail et son
> interface r_volutionnaire.
---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://herzberg.ca.sandia.gov
--------------------------------------------------------------------
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]
--------------------------------------------------------------------