PDDL error compiling - compilation

I am new to PDDL, i have been trying a blocksworld problem but i got the error:
Failed to parse the problem -- Not args must be a list with only one element, got [Primitive sobre (default_object ?obj, default_object ?obj2), Primitive libre (default_object ?obj3), Primitive en (default_object ?obj, default_object ?from)]
/tmp/solver_planning_domains_tmp_4BmsZdP37zJXS/domain.pddl: syntax error in line 16, '(':
domain definition expected
my files are these:
(define (domain blocly)
(:predicates (espacio ?e)
(ficha ?t)
(sobre ?t ?t)
(en ?t ?e)
(vacio ?e)
(libre ?t))
(:action movefichaficha
:parameters (?ficha ?ficha2 ?ficha3 ?from ?to)
:precondition (and (ficha ?ficha) (ficha ?ficha2) (ficha ?ficha3) (espacio ?from) (espacio ?to)
(sobre ?ficha ?ficha2) (libre ?ficha) (libre ?ficha3) (en ?ficha ?from) (en ?ficha2 ?from)
(en ?ficha3 ?to))
:effect (and (sobre ?ficha ?ficha3) (en ?ficha ?to) (libre ?ficha2)
(not (sobre ?ficha ?ficha2) (libre ?ficha3) (en ?ficha ?from))))
(:action movefichaesp
:parameters (?ficha ?ficha2 ?from ?to)
:precondition (and (ficha ?ficha) (ficha ?ficha2) (espacio ?from) (espacio ?to)
(sobre ?ficha ?ficha2) (vacio ?to) (en ?ficha ?from) (en ?ficha2 ?from))
:effect (and (libre ?ficha2) (en ?ficha ?to) (arriba ?ficha ?to)
(not (vacio ?to) (en ?ficha ?from) (sobre ?ficha ?ficha2))))
(:action moveoespficha
:parameters (?ficha ?ficha2 ?from ?to)
:precondition (and (ficha ?ficha) (ficha ?ficha2) (espacio ?from) (espacio ?to)
(libre ?ficha) (libre ?ficha2) (en ?ficha ?from) (en ?ficha ?to) ())
:effect (and (vacio ?from) (en ?ficha ?to) (sobre ?ficha ?ficha2)
(not (libre ?ficha2) (en ?ficha ?from) (en ?ficha ?from)))))
and these:
(define (problem blockly-world)
(:domain blocly)
(:objects t1 t2 t3 e1 e2 e3)
(:init (ficha t1)
(ficha t2)
(ficha t3)
(espacio e1)
(espacio e2)
(espacio e3)
(sobre t3 t2)
(sobre t2 t1)
(en t1 e1)
(en t2 e1)
(en t3 e1)
(libre t3)
(vacio e2)
(vacio e3))
(:goal (and (sobre t1 t2)
(sobre t2 t3)))

There are a number of problems in the source code.
The problem file lacks a final )
The unary not logical operator is used improperly, e.g.
(not (vacio ?to) (en ?ficha ?from) (sobre ?ficha ?ficha2))
should be rewritten as
(not (vacio ?to))
(not (en ?ficha ?from))
(not (sobre ?ficha ?ficha2))
The domain file uses an undeclared predicate, arriba. Since it has the same definition of en --and it is not mentioned in the (:init ...) block--, I am unsure whether this is a typo due to renaming arriba into en and forgetting to change one last occurrence of it, or not. Just in case it is not an error, you can fix it by adding
(arriba ?t ?e)
to the list of predicates. You should check on you own whether you need to add something to the (:init ...) block in the problem file or not.
Below, you can find a properly indented version of the source code with adequate fixes to the first two identified issues, and an attempt to solve the third issue:
blocky-prob.pddl:
(define (problem blockly-world)
(:domain blocly)
(:objects t1 t2 t3 e1 e2 e3)
(:init
(ficha t1)
(ficha t2)
(ficha t3)
(espacio e1)
(espacio e2)
(espacio e3)
(sobre t3 t2)
(sobre t2 t1)
(en t1 e1)
(en t2 e1)
(en t3 e1)
(libre t3)
(vacio e2)
(vacio e3)
)
(:goal (and
(sobre t1 t2)
(sobre t2 t3)
)
)
)
block-domain.pddl:
(define (domain blocly)
(:predicates
(espacio ?e)
(ficha ?t)
(sobre ?t ?t)
(en ?t ?e)
(arriba ?t ?e)
(vacio ?e)
(libre ?t)
)
(:action movefichaficha
:parameters (?ficha ?ficha2 ?ficha3 ?from ?to)
:precondition
(and
(ficha ?ficha)
(ficha ?ficha2)
(ficha ?ficha3)
(espacio ?from)
(espacio ?to)
(sobre ?ficha ?ficha2)
(libre ?ficha)
(libre ?ficha3)
(en ?ficha ?from)
(en ?ficha2 ?from)
(en ?ficha3 ?to)
)
:effect
(and
(sobre ?ficha ?ficha3)
(en ?ficha ?to)
(libre ?ficha2)
(not (sobre ?ficha ?ficha2))
(not (libre ?ficha3))
(not (en ?ficha ?from))
)
)
(:action movefichaesp
:parameters (?ficha ?ficha2 ?from ?to)
:precondition
(and
(ficha ?ficha)
(ficha ?ficha2)
(espacio ?from)
(espacio ?to)
(sobre ?ficha ?ficha2)
(vacio ?to)
(en ?ficha ?from)
(en ?ficha2 ?from)
)
:effect
(and
(libre ?ficha2)
(en ?ficha ?to)
(arriba ?ficha ?to)
(not (vacio ?to))
(not (en ?ficha ?from))
(not (sobre ?ficha ?ficha2))
)
)
(:action moveoespficha
:parameters (?ficha ?ficha2 ?from ?to)
:precondition
(and
(ficha ?ficha)
(ficha ?ficha2)
(espacio ?from)
(espacio ?to)
(libre ?ficha)
(libre ?ficha2)
(en ?ficha ?from)
(en ?ficha ?to)
)
:effect
(and
(vacio ?from)
(en ?ficha ?to)
(sobre ?ficha ?ficha2)
(not (libre ?ficha2))
(not (en ?ficha ?from))
(not (en ?ficha ?from))
)
)
)
The code is properly parsed by the PDDL solver fast-downward.py on my machine, which also finds a solution. Since I don't know what you are trying to model, I am unable to verify whether it matches what you want to model or not.
Notes: even if you are just learning for personal reasons, consider getting in the habit of using english names for your predicates, objects and variables. Moreover, consider that indenting the source code and properly describing the situation you are dealing with has the double benefit of attracting both upvotes and good answers to your questions.

Related

Filtering words from a list that matches my char in scheme

I just started to learn scheme.
I need to create a predicate function that will filter a list(maybe empty) and only output if they match with a char:
(filter-word '((#\g #\a #\m #\e)
(#\d #\o #\l #\l)
(#\d #\i #\c #\e))
#\a)
output:
((#\g #\a #\m #\e))
I'm trying to use filter and member, but I don't know how to structure this function, and I don't know if is possible to use filter lambda and member altogether.
Is Map a better option for this case?
(define (filter-word words ch)
(cond
[(null? words) words]
[(filter
(λ (words)(member? ch (words)) words))]))
I know is incomplete but in this case, the output is #<procedure:...
You can use filter directly, there's no need for an extra case. This should work:
(define (filter-word words ch)
(filter (lambda (word) (member ch word))
words))
For example:
(filter-word '((#\b #\u #\s)
(#\b #\a #\r)
(#\c #\a #\r))
'#\b)
=> '((#\b #\u #\s) (#\b #\a #\r))
(filter-word '((#\b #\u #\s)
(#\b #\a #\r)
(#\c #\a #\r))
'#\c)
=> '((#\c #\a #\r))

CLIPS does not recognize deftemplate name

I am trying to retract a deftemplate fact but when I do this CLIPS keeps saying I have to first declare the deffunction yet it is the appropriate deftemplate.What seems to be the problem?
I have attached the related code:
I get this error:
[EXPRNPSR3] Missing function declaration for Agriculture.
What seems to be the problem?
(deftemplate Agriculture
(slot weed
(type SYMBOL)
(allowed-symbols B G))
(slot crop
(type SYMBOL)
(allowed-symbols C S))
(slot organic-matter
(type INTEGER)
(allowed-values 1 2 3)))
(defrule Sencor-1
(and (Agriculture(weed B))
(Agriculture(crop C|S))
(Agriculture(organic-matter 1)))
=>
(printout t "Do not use Sencor!!"crlf))
(defrule Sencor-2
(and (Agriculture(weed B))
(Agriculture(crop C|S))
(Agriculture(organic-matter 2|3)))
=>
(printout t " " crlf "Use 3/4 pt/ac of Sencor" crlf ))
(defrule Lasso-1
(and (Agriculture(weed B|G))
(Agriculture(crop C|S))
(Agriculture(organic-matter 1)))
=>
(printout t crlf"Use 2 pt/ac of Lasso" crlf))
(defrule Lasso-2
(and (Agriculture(weed B|G))
(Agriculture(crop C|S))
(Agriculture(organic-matter 2)))
=>
(printout t crlf "Use 1 pt/ac of Lasso" crlf))
(defrule Lasso-3
(and (Agriculture(weed B|G))
(Agriculture(crop C|S))
(Agriculture(organic-matter 3)))
=>
(printout t crlf "Use 0.5 pt/ac of Lasso" crlf))
(defrule Bicep-1
(and (Agriculture(weed B|G))
(Agriculture(crop C))
(Agriculture(organic-matter 1)))
=>
(printout t crlf "Use 1.5 pt/ac of Bicep" crlf))
(defrule Bicep-2
(and (Agriculture(weed B|G))
(Agriculture(crop C))
(Agriculture(organic-matter 2)))
=>
(printout t crlf"Use 2.5 pt/ac of Bicep" crlf))
(defrule Bicep-3
(and (Agriculture(weed B|G))
(Agriculture(crop C))
(Agriculture(organic-matter 3)))
=>
(printout t crlf "Use 3 pt/ac of Bicep" crlf))
(defrule input
(initial-fact)
=>
(printout t crlf "What is the crop? (C:corn,S:soybean)")
(bind ?a (read))
(assert(Agriculture(crop ?a))) ;gets input from user
(printout t crlf "What is the weed problem? (B:broadleaf, G:grass)")
(bind ?b (read))
(assert(Agriculture(weed ?b)))
(printout t crlf "What is the % of organic matter content? (1:<2%,2:2-4%,3:>4%)")
(bind ?c (read))
(assert(Agriculture(organic-matter ?c)))
?d <- (Agriculture(crop ?a) (weed ?b) (organic-matter ?c))
(printout t ""crlf crlf "RECOMMENDATIONS:"crlf)
(retract ?d))
In the RHS of the input rule you state:
?d <- (Agriculture(crop ?a) (weed ?b) (organic-matter ?c))
This is interpreted as "Run function Agriculture and bind its results into ?d".
What you probably are trying to do is:
(bind ?d (assert (Agriculture (crop ?a) (weed ?b) (organic-matter ?c))))

CLIPS: Array in CLIPS? (Need some orientation, new in CLIPS)

I'm new in Clips. I'd like to know if it is a way to read an array (chain of numeric or characters with an index, sorry if it's the wrong name) on LHS. I have rules to ask for a value (s,cs,cn,n) then it assert the value to next asking rule, to finally read all the values in an answering rule to get a diagnostic, but in my small example I have 4 questions and 4 options for each one so mixing all the answers would give me 64 rules, and I have so at least 30 questions in my program so I think that would be too much rules (I'm doing my first Expert System an maybe this is normal). In any case I think I could get the values from questions into an array an read it in answering rules, but my questions are:
*How can I bind the values from my function into an array?
*Is it possible to verify that array in LHS?
*Do you have any other idea to verify the answer-rules? Hope you can help me.
(deffunction funcionPregunta (?pregunta $?valoresAceptados) ;;ask-question function
(printout t ?pregunta)
(bind ?respuesta (read))
(if (lexemep ?respuesta)
then (bind ?respuesta (lowcase ?respuesta)))
(while (not (member$ ?respuesta ?valoresAceptados)) do
(printout t ?pregunta)
(bind ?respuesta (read))
(if (lexemep ?respuesta)
then (bind ?respuesta (lowcase ?respuesta))))
?respuesta)
;;===============================================================
;; QUESTION RULES
;;===============================================================
(defrule pregunta1T5 "AGORAFOBIA"
(not (diagnostico ?))
=>
(assert (Pregunta2T5
(funcionPregunta "1.Siente miedo o ansiedad marcada. (always/frecuently/rare/never)? "
s cs cn n))))
(defrule Pregunta2T5 "AGORAPUBLICO"
(not (diagnostico ?))
(Pregunta2T5 ?Pregunta2T5)
=>
(assert (Pregunta3T5
(funcionPregunta "2.Siente miedo en una multitud. (always/frecuently/rare/never)? "
s cs cn n)))
)
(defrule Pregunta3T5 "AGORAMIEDO"
(not (diagnostico ?))
(Pregunta3T5 ?Pregunta3T5)
=>
(assert (Pregunta4T5
(funcionPregunta "3.Miedo de estar en una situacion. (always/frecuently/rare/never)? "
s cs cn n)))
)
(defrule Pregunta4T5 "AGORAANSIEDAD"
... ;; similar rules
;;===============================================================
;; ANSWERS RULES
;;===============================================================
(defrule Respuesta1T6 "RESULTADO 1 TAS"
(not (diagnostico ?))
(Pregunta2T6 s)(Pregunta3T6 s)(Pregunta4T6 s)(Pregunta5T6 s)
=>
(assert (diagnostico "TRASTORNO DE ANSIEDAD SOCIAL"))
)
(defrule Respuesta2T6 "RESULTADO 2 TAS"
(not (diagnostico ?))
(Pregunta2T6 cs)(Pregunta3T6 s)(Pregunta4T6 s)(Pregunta5T6 s)
=>
(assert (diagnostico "TRASTORNO DE ANSIEDAD SOCIAL"))
)
In the case of the two answer rules you've already got, the simplest way to reduce the number of rules is just to combine them:
(defrule Respuesta1T6-2T6
(not (diagnostico ?))
(Pregunta2T6 s | cs) ; s or cs is allowed
(Pregunta3T6 s)
(Pregunta4T6 s)
(Pregunta5T6 s)
=>
(assert (diagnostico "TRASTORNO DE ANSIEDAD SOCIAL")))
If you're creating lots of rules that differ only in the constants matched in the patterns, you should consider representing the rules as a combination of facts containing these constants and generic rules to process that data. For example, you could rewrite your question rules like this:
(deftemplate Pregunta ; question
(slot identidad) ; ID
(slot texto) ; text
(multislot respuestas) ; responses
(slot precursora ; precursor
(default ninguna))) ; none
(deftemplate Responder ; answer
(slot identidad) ; ID
(slot valor)) ; value
(deffacts Preguntas
(Pregunta (identidad AGORAFOBIA)
(texto "1. Siente miedo o ansiedad marcada. (always/frecuently/rare/never)? ")
(respuestas s cs cn n))
(Pregunta (identidad AGORAPUBLICO)
(texto "2. Siente miedo en una multitud. (always/frecuently/rare/never)? ")
(respuestas s cs cn n)
(precursora AGORAFOBIA))
(Pregunta (identidad AGORAMIEDO)
(texto "3. Miedo de estar en una situacion. (always/frecuently/rare/never)? ")
(respuestas s cs cn n)
(precursora AGORAPUBLICO)))
(defrule pedir-pregunta ; ask question
(not (diagnostico ?))
(Pregunta (identidad ?id)
(texto ?t)
(respuestas $?r)
(precursora ?p))
(or (test (eq ?p ninguna))
(Responder (identidad ?p)))
=>
(assert (Responder (identidad ?id)
(valor (funcionPregunta ?t ?r)))))
And your diagnosis rules like this:
(deftemplate Trastorno ; disorder
(slot nombre) ; name
(multislot sintomas)) ; symptoms
(deftemplate Sintoma
(slot identidad) ; ID
(slot responder) ; answer
(multislot valors)) ; values
(deffacts Trastornos
(Trastorno (nombre "TRASTORNO DE ANSIEDAD SOCIAL")
(sintomas AGORAFOBIA-cs-s AGORAPUBLICO-s AGORAMIEDO-s)))
(deffacts Sintomas
(Sintoma (identidad AGORAFOBIA-cs-s)
(responder AGORAFOBIA)
(valors cs s))
(Sintoma (identidad AGORAPUBLICO-s)
(responder AGORAPUBLICO)
(valors s))
(Sintoma (identidad AGORAMIEDO-s)
(responder AGORAMIEDO)
(valors s)))
(defrule Respuesta
(not (diagnostico ?))
(Trastorno (nombre ?n)) ; There is a disorder.
(forall (Trastorno (nombre ?n) ; For every symptom
(sintomas $? ?s $?)) ; of the disorder,
(Sintoma (identidad ?s) ; there is a list
(responder ?r) ; of possible values
(valors $?sv)) ; for that symptom
(Responder (identidad ?r) ; matched by a response.
(valor ?v&:(member$ ?v ?sv))))
=>
(assert (diagnostico ?n)))

CLIPS runtime crash

I wrote a program which asserts the facts in the LHS of this rule:
(defrule check-open-better (declare (salience 50))
?f1 <- (newnode (ident ?id) (gcost ?g) (fcost ?f) (father ?anc))
(status (ident ?id) (subject ?subject) (data $?eqL))
?f2 <- (status (ident ?old) (subject ?subject) (data $?eqL))
?f3 <- (node (ident ?old) (gcost ?g-old) (open yes))
(test
(eq
(implode$
(find-all-facts ((?f status))
(and
(eq(str-compare ?f:ident ?id) 0)
(eq(str-compare ?f:subject ?subject) 0)
(eq(str-compare (implode$ ?f:data) (implode$ $?eqL)) 0)
)
)
)
(implode$
(find-all-facts ((?f status))
(and
(eq(str-compare ?f:ident ?old) 0)
(eq(str-compare ?f:subject ?subject) 0)
(eq(str-compare (implode$ ?f:data) (implode$ $?eqL)) 0)
)
)
)
0)
)
(test (< ?g ?g-old))
?f4 <- (open-better ?a)
=>
(assert (node (ident ?id) (gcost ?g) (fcost ?f) (father ?anc) (open yes)))
(assert (open-better (+ ?a 1)))
(retract ?f1 ?f2 ?f3 ?f4)
(pop-focus)
(pop-focus))
node, newnode and status are defined as deftemplate.
When this rule is in the agenda, CLIPS crash like it was typed the (exit) command.
I'm sure it's not fault of the rules that assert facts that allow this rule to be added in the agenda. Does anyone know why?
If CLIPS is crashing, it's a bug in CLIPS. I tried reproducing the problem by filling in the missing pieces and running in CLIPS 6.3, 6.31, and 6.4, but was unable to get a crash.
(deftemplate newnode
(slot ident)
(slot gcost (type INTEGER))
(slot fcost)
(slot father))
(deftemplate status
(slot ident)
(slot subject)
(multislot data))
(deftemplate node
(slot ident)
(slot gcost (type INTEGER))
(slot open))
(deffacts start
(node (ident "1") (gcost 10) (open yes))
(open-better 0)
(newnode (ident "2"))
(status (ident "1"))
(status (ident "2")))
Generally, it's a bad idea to use the query functions from the conditions of a rule because 1) you can use pattern matching and 2) the query contained within a test CE will not be reevaluated unless there's some changes to prior patterns.
It's not clear what you're trying to do with the find-all-facts calls. First, there's cruft in there that you don't need. The str-compare and implode$ function calls are unnecessary and the third argument of 0 to eq will cause the test CE to always fail since the return values of the find-all-facts calls will never be 0.
(test
(eq
(find-all-facts ((?f status))
(and
(eq ?f:ident ?id)
(eq ?f:subject ?subject)
(eq ?f:data $?eqL)
)
)
(find-all-facts ((?f status))
(and
(eq ?f:ident ?old)
(eq ?f:subject ?subject)
(eq ?f:data $?eqL)
)
)
)
)
Both find-all-fact calls must return the same facts in order for the test CE to be satisfied. That can only be true if there are no status facts or the ?id and ?old variables have the same value.
Try this one, it should work. :)
(defrule check-open-better (declare (salience 50))
?f1 <- (newnode (ident ?id) (gcost ?g) (fcost ?f) (father ?anc))
(status (ident ?id) (subject ?subject) (data $?eqL))
?f2 <- (status (ident ?old) (subject ?subject) (data $?eqL))
?f3 <- (node (ident ?old) (gcost ?g-old) (open yes))
(test (< ?g ?g-old))
?f4 <- (open-better ?a)
=>
(if (eq
(implode$
(find-all-facts ((?f status))
(and
(eq ?f:ident ?id)
(eq ?f:subject ?subject)
(eq (implode$ ?f:data) (implode$ $?eqL)))))
(implode$
(find-all-facts ((?f status))
(and
(eq ?f:ident ?old)
(eq ?f:subject ?subject)
(eq (implode$ ?f:data) (implode$ $?eqL)) 0))))
then
(assert (node (ident ?id) (gcost ?g) (fcost ?f) (father ?anc) (open yes)))
(assert (open-better (+ ?a 1)))
(retract ?f1 ?f2 ?f3 ?f4))
(pop-focus)
(pop-focus))

CLIPS rule unmatch(don't fire) after retract

i have a project in clips with three modules, at the end of the second module i ask to user if he want to retract one of the previous answer, if he retract one of the answer of the second module, i need to retract all the answers of the second module and re-ask again. After i retract all the answers of the second module, i expect that this rule is activated
(defrule SECONDMODULE::domanda-esperto
(declare (salience ?*highest-priority*))
(livello-utente (livello esperto)) ;;assert in FIRSTMODULE and not retract
=>
(something)
)
But this rule is never activeted and it not apper in the AGENDA also if the facts that match the LHS is present in the fact list.
Sorry for my bad english.
EDIT.
#Gary First of all i ask 5 question to user, that are this:
(defrule starting-rule
(declare (salience ?*highest-priority*) (auto-focus TRUE))
=>
(printout t "***Inizio***" crlf)
(focus PROFILO)
(set-strategy random))
(defrule PROFILO::chiedi-se-possiede-auto
(not (domanda (nome possiede-auto) (domanda ?) (risposta ?)))
=>
(bind ?risposta (si-o-no "L'auto e' tua? "))
(assert (domanda (nome possiede-auto) (domanda "L'auto e' tua? ") (risposta ?risposta)))
)
(defrule PROFILO::frequenza-utilizzo-auto
(not(domanda (nome frequenza-utilizzo-auto) (domanda ?) (risposta ?)))
=>
(bind ?risposta (risposte-range "Quante volte a settimana in media utilizzi l'auto? " 0 1-2 3-5 5-7 ))
(assert (domanda (nome frequenza-utilizzo-auto) (domanda "Quante volte a settimana in media utilizzi l'auto? " ) (risposta ?risposta)))
)
(defrule PROFILO::conoscenza-meccanica-auto
(not (domanda (nome conoscenza-meccanica-auto) (domanda ?) (risposta ?)))
=>
(bind ?risposta (risposte-range "Quanto ti consideri esperto della meccanica dell'auto?" 0 1 2 3 4 5))
(assert (domanda (nome conoscenza-meccanica-auto) (domanda "Quanto ti consideri esperto della meccanica dell'auto?") (risposta ?risposta)))
)
(defrule PROFILO::kit-riparazione-rapida
(not (domanda (nome kit-riparazione-rapida) (domanda ?) (risposta ?)))
=>
(bind ?risposta (si-o-no "Possiedi un kit di riparazione rapida?"))
(assert (domanda (nome kit-riparazione-rapida) (domanda "Possiedi un kit di riparazione rapida?") (risposta ?risposta)))
)
(defrule PROFILO::anni-possesso-patente
(not(domanda (nome anni-possesso-patente) (domanda ?) (risposta ?)))
=>
(bind ?risposta (risposte-range "Da quanti anni possiedi la patente? " <1 1-5 >5 ))
(assert (domanda (nome anni-possesso-patente) (domanda "Da quanti anni possiedi la patente? ") (risposta ?risposta)))
)
After this i fire a rule that in according with the user asnwers delineate the profile of the user
(defrule PROFILO::livello-utente
?a<-(domanda (nome possiede-auto) (domanda ?) (risposta ?))
?b<-(domanda (nome anni-possesso-patente) (domanda ?) (risposta ?))
?c<-(domanda (nome conoscenza-meccanica-auto) (domanda ?) (risposta ?))
?d<-(domanda (nome kit-riparazione-rapida) (domanda ?) (risposta ?))
?e<-(domanda (nome frequenza-utilizzo-auto) (domanda ?) (risposta ?))
=>
(switch (fact-slot-value ?a risposta)
(case TRUE then (bind ?*punteggio* (+ ?*punteggio* 1)))
)
(switch (fact-slot-value ?d risposta)
(case TRUE then (bind ?*punteggio* (+ ?*punteggio* 1)))
)
(switch (fact-slot-value ?b risposta)
(case <1 then (bind ?*punteggio* (+ ?*punteggio* 1)))
(case 1-5 then (bind ?*punteggio* (+ ?*punteggio* 2)))
(case >5 then (bind ?*punteggio* (+ ?*punteggio* 3)))
)
(switch (fact-slot-value ?c risposta)
(case 1 then (bind ?*punteggio* (+ ?*punteggio* 1)))
(case 2 then (bind ?*punteggio* (+ ?*punteggio* 2)))
(case 3 then (bind ?*punteggio* (+ ?*punteggio* 3)))
(case 4 then (bind ?*punteggio* (+ ?*punteggio* 4)))
(case 5 then (bind ?*punteggio* (+ ?*punteggio* 5)))
)
(switch (fact-slot-value ?e risposta)
(case 1-2 then (bind ?*punteggio* (+ ?*punteggio* 1)))
(case 3-5 then (bind ?*punteggio* (+ ?*punteggio* 2)))
(case 5-7 then (bind ?*punteggio* (+ ?*punteggio* 3)))
)
(bind ?f ?*punteggio*)
(if (> ?f 9) then (assert (livello-utente (livello esperto))))
(if (< ?f 6) then (assert (livello-utente (livello principiante))))
(if (and (> ?f 5) (< ?f 10)) then (assert (livello-utente(livello medio))))
)
After that i go in the second module where one of this two rule ia actived in according with the profile of the user determinate in the fist module
(defrule DIAGNOSI::domanda-esperto
(declare (salience ?*highest-priority*))
(livello-utente (livello esperto))
=>
(bind ?risposta (risposte-range "In quale tra le seguenti aree e' presente il problema?" Olio-motore Olio-freni Acqua Carburante Altro))
(assert (domanda (nome area-problema) (domanda "In quale tra le seguenti aree e' presente il problema?") (risposta ?risposta)))
)
(defrule DIAGNOSI::domanda-medio
(declare (salience ?*highest-priority*))
(livello-utente (livello medio))
=>
(bind ?risposta (si-o-no "Sapresti indicare l'area di provenienza del problema tra le seguenti: Olio motore, Olio freni, Acqua, Carburante, Altro?"))
(assert (domanda (nome domanda-area-problema) (domanda "Sapresti indicare l'area di provenienza del problema tra le seguenti: Olio motore, Olio freni, Acqua, Carburante, Altro?") (risposta ?risposta)))
(if (eq ?risposta TRUE)
then (bind ?risposta (risposte-range "In quale tra le seguenti aree e' presente il problema?" Olio-motore Olio-freni Acqua Carburante Altro))
(assert (domanda (nome area-problema) (domanda "In quale tra le seguenti aree e' presente il problema?") (risposta ?risposta)))
)
After this there is a series of other question that i do to user. After that i ask if he want to retract one of this, and if he chooseone of the two (domanda-medio, domanda-esperto) i have to retract all the answers of the second module. After i retract all the answers of the second module, this two rule is never activeted and it not apper in the AGENDA also if the facts that match the LHS is present in the fact list (livello-utente (livello ?))
#GaryRiley ok i don't know why but adding `
(not (diagnosi (nome ?)))`
to the two rule it work.

Resources