I want to do a guide for a student who want to register in a college, knowing his statues, or anything related t a college system..
First < ask question which question type he want to ask "Foundation|diploma level|advance diploma|bachelor...
then, id choice 1> ask: are you registered in "college Name? (yes/no)"
if yes > assert another question, No> print some advice, then go to another
.
.
some questions needs to get user input from a given choices .. "how do it"
"which level in diploma?" level1/level2/level3/level4
.
.
It is just like a guide program....
Your rule is missing a close right parenthesis. If you add it, you can get the rule to reactivate itself when you select level4.
CLIPS> (assert (case14))
<Fact-1>
CLIPS> (agenda)
0 choice4: f-1
For a total of 1 activation.
CLIPS> (watch facts)
CLIPS> (run)
<== f-1 (case14)
Which level in diploma of IS (level1 ,level2, level3, level4)?level4
==> f-2 (case14)
<== f-2 (case14)
Which level in diploma of IS (level1 ,level2, level3, level4)?level4
==> f-3 (case14)
<== f-3 (case14)
Which level in diploma of IS (level1 ,level2, level3, level4)?level3
==> f-4 (case15)
CLIPS>
Related
Am writing a project, my code will be in the form as describe below in the code, Is there any need to include salience and how can I use interface? The software will require the user to answer a question in the form of yes or no. I want to know how to do this in the form of checkboxes, where the user will tick the appropriate symptoms of a disease, then the software will be able to predict the kind of disease. thank you . please help
CLIPS> (defrule bacterial-fruit-blotch-of-watermelon
=>
(print "Is the plant showing a symptom of Oily and water-soaked cotyledons? ")
(assert (OWS (read)))
(print "Is the plant showing a symptom of Yellow halo paralleling veins? ")
(assert (YHP (read)))
(print "Is the plant showing a symptom of Small dark and angled lesion on leaves? ")
(assert (SDA (read)))
(print "Is the plant showing a symptom of Dark green blotch on the upper surface of developing fruit? ")
(assert (DGB (read))))
CLIPS> (defrule check
(OWS yes)
(YHP yes)
(SDA yes)
(DGB yes)
=>
(println "The plant is showing a symptom of bacterial fruit blotch of watermelon disease."))
CLIPS> (defrule bacterial-rind-necrosis
=>
(print " Is the plant showing a symptom of corky, dry necrosis? ")
(assert (corky (read)))
(print " Is the plant showing a symptom of misshapen? ")
(assert (misshaping (read)))
(print " Is the plant showing a symptom of dark ,water-soaked depression? ")
(assert (dark (read))))
CLIPS> (defrule check-two
(corky yes)
(misshaping yes)
(dark yes)
=>
(println "The plant is showing a symptom of bacterial rind necrosis of watermelon disease."))
CLIPS> (reset)
CLIPS> (run)
Is the plant showing a symptom of Oily and water-soaked cotyledons? no
Is the plant showing a symptom of Yellow halo paralleling veins? n
Is the plant showing a symptom of Small dark and angled lesion on leaves? no
Is the plant showing a symptom of Dark green blotch on the upper surface of developing fruit? no
Is the plant showing a symptom of corky, dry necrosis? yes
Is the plant showing a symptom of misshapen? yes
Is the plant showing a symptom of dark ,water-soaked depression? yes
The plant is showing a symptom of bacterial rind necrosis of watermelon disease.
CLIPS>
If you want to provide flexibility in how your program interacts with the user, the best thing to do is to separate the code that reasons about symptoms and diseases from the code that interacts with the user. In your current implementation, these are intermingled.
To reimplement your code, first define a deftemplate for representing the symptoms and their associated questions:
(deftemplate symptom
(slot id)
(slot question)
(slot indicative (default yes)))
The indicative slot represents the response to a question that is indicative of a problem. So if the question is "Are the leaves a sickly yellow?", the indicative response would be yes, and if the question is "Are the leaves a healthy green?", the indicative response would be no.
The symptoms from your rules can now be represented as a group of facts:
(deffacts symptoms
(symptom (id ows)
(question "Is the plant showing a symptom of Oily and water-soaked cotyledons?"))
(symptom (id yhp)
(question "Is the plant showing a symptom of Yellow halo paralleling veins?"))
(symptom (id sda)
(question "Is the plant showing a symptom of Small dark and angled lesion on leaves?"))
(symptom (id dgb)
(question "Is the plant showing a symptom of Dark green blotch on the upper surface of developing fruit?"))
(symptom (id corky)
(question "Is the plant showing a symptom of corky, dry necrosis?"))
(symptom (id misshaping)
(question "Is the plant showing a symptom of misshapen?"))
(symptom (id dark)
(question "Is the plant showing a symptom of dark, water-soaked depression?"))
)
The diseases can be similarly represented as a group of facts:
(deftemplate disease
(slot id)
(multislot symptoms))
(deffacts diseases
(disease (id "bacterial fruit blotch")
(symptoms ows yhp sda dgb))
(disease (id "bacterial rind necrosis")
(symptoms corky misshaping dark))
)
The responses to questions and any disease conclusions will also be represented as facts:
(deftemplate answer
(slot id)
(slot value))
(deftemplate conclusion
(slot id))
With the symptoms and diseases represented as data, we can now add a generic rule which determines if every symptom of a disease is present:
(defrule conclude-disease
;; There is a disease
(disease (id ?disease))
;; For every symptom of that disease
(forall (disease (id ?disease)
(symptoms $? ?symptom $?))
(symptom (id ?symptom)
(indicative ?value))
;; There is a response indicative
;; of a problem
(answer (id ?symptom)
(value ?value)))
=>
;; Conclude the plant has the disease
(assert (conclusion (id ?disease))))
Now we can add code to handle interacting with the user. We'll start with your initial approach of using the keyboard to get responses from the user:
(deffunction ask-question (?question $?allowed-values)
(printout t ?question " " ?allowed-values " ")
(bind ?answer (read))
(if (lexemep ?answer)
then (bind ?answer (lowcase ?answer)))
(while (not (member$ ?answer ?allowed-values)) do
(printout t ?question " " ?allowed-values " ")
(bind ?answer (read))
(if (lexemep ?answer)
then (bind ?answer (lowcase ?answer))))
?answer)
(defrule ask-symptom
;; There is a symptom
(symptom (id ?symptom)
(question ?question))
;; For a disease
(disease (id ?disease)
(symptoms $? ?symptom $?))
;; That we have not determined
(not (answer (id ?symptom)))
;; And there is no prior response to a symptom
;; of that disease that is non-indicative.
(not (and (disease (id ?disease)
(symptoms $? ?other-symptom $?))
(symptom (id ?other-symptom)
(indicative ?value))
(answer (id ?other-symptom)
(value ~?value))))
=>
;; Ask the user the symptom question
(bind ?value (ask-question ?question yes no))
;; And assert the response.
(assert (answer (id ?symptom)
(value ?value))))
The ask-symptom rule improves upon the prior approach by not asking about symptoms for diseases that have a non-indicative response for a symptom. So if the response to necrosis is no, the user will not be asked about misshapen or depression.
Finally, some rules can be added to display the conclusions. These rules are given lower salience so that all of the questions are asked before any conclusion is displayed.
(defrule print-conclusion
(declare (salience -10))
(conclusion (id ?disease))
=>
(println "The plant is showing symptoms of " ?disease " watermelon disease."))
(defrule print-no-conclusion
(declare (salience -10))
(not (conclusion))
=>
(println "The plant is not showing all symptoms of a watermelon disease."))
If you want to use an interface rather than interacting through a console, you'd need to replace the code just added for asking questions and displaying conclusions.
CLIPS provides for querying the fact-list. For example, here's how you'd get a list of all the symptom facts from the CLIPS command prompt:
CLIPS> (find-all-facts ((?s symptom)) TRUE)
(<Fact-1> <Fact-2> <Fact-3> <Fact-4> <Fact-5> <Fact-6> <Fact-7>)
CLIPS>
What you can do in your interface is to query CLIPS for all of the symptom facts and then dynamically create the check boxes to display using the slot values in the facts.
When the user is ready for a response, you could have a diagnose button in your interface. When the user clicks that button, you can assert an answer fact with the appropriate values for each check box. After asserting those facts, you can run CLIPS and then use the query functions to retrieve the conclusion facts and then display the results. Alternately, any time a checkbox is changed you can assert the facts and run CLIPS.
If you download CLIPS from SourceForge, there are examples of integrating CLIPS with GUIs for .NET, Java, and iOS.
So I'm trying to build a program that takes user's input by displaying a message on the screen “Enter your subject”.
In the second rule, I'm to mention subject names “artificial intelligence”, “operating system” and “compiler construction” and check that entered subject from the first rule matches with the mentioned subjects by displaying this message on the screen.
“Your entered subject is true”.
Here is the code:
(deftemplate subject
(slot subject)
(slot artificial intelligence)
(slot operating system)
(slot compiler construction))
(defrule reading-input
(printout t "Enter your subject:")
(assert(var(read))))
(defrule checking-input
(var? artificial intelligence)
(var? operating system)
(var? compiler construction)
(com(artificial intelligence ? artificial intelligence))
(test(=?artificial intelligence ? artificial intelligence))
(test(=?operating system ? operating system))
(test(=? compiler construction ? compiler construction))
(=>
printout t "Your entered subject is true:"))
CLIPS (6.31 6/12/19)
CLIPS>
(defrule reading-input
=>
(printout t "Enter your subject: ")
(assert (var (readline))))
CLIPS>
(defrule checking-input
(var "artificial intelligence" |
"operating system" |
"compiler construction")
=>
(printout t "Your entered subject is true." crlf))
CLIPS> (reset)
CLIPS> (run)
Enter your subject: operating system
Your entered subject is true.
CLIPS> (reset)
CLIPS> (run)
Enter your subject: algorithms
CLIPS>
is there a way to output the name of the fired rule in CLIPS?
Example:
(defrule this-is-my-rule
...
=>
(printout t "this-is-my-rule: and these are the outputs" crlf) ;;#1
)
Instead of writing manually the name of the rule in #1, I'd like to use a psecific command (if any).
Is it possible, please?
Thank
Nicola
There isn't a mechanism for programmatically determining the name of the currently executing rule, but you can use the watch debugging command to print the name of each rule as it is executed:
CLIPS> (defrule rule-1 =>)
CLIPS> (defrule rule-2 =>)
CLIPS> (defrule rule-3 =>)
CLIPS> (watch rules)
CLIPS> (run)
FIRE 1 rule-3: *
FIRE 2 rule-2: *
FIRE 3 rule-1: *
CLIPS>
I am new to JESS and I know a little of its functionality. I have a program that asks for a students id-number and the program goes and gets the student's subjects.
The thing is by the end of procedure the program asks the user if he/she wants to get another student's subjects.
If the user wants to input another student, It will go back to the first rule that fired but when I tried that, the rule only activated and did not fire.
What could be the problem? I made sure there was (run) of course.
Here's my code.
(defrule check-subject
?a <- (phase check-back)
?stud <- (lookupID (id ?id))
(student-information (id-number ?id)
(course ?course)
(subjects-taken $?taken)
(year ?year)
(semester ?sem))
(prospectus-information (curriculum-name ?course)
(1st-year-1st-sem-subjects $?subjects1))
=>
(printout t "Student took: " (intersection$ $?taken $?subjects1) crlf)
(printout t "Student flunked: " (complement$ $?taken $?subjects1) crlf)
(assert (back-subject (complement$ $?taken $?subjects1)))
(retract ?a ?stud)
(ask))
And I have the function ask
(deffunction ask ()
(printout t "Consult another? (y/n) ")
(if (eq (read) y)
then (assert (phase choose-student))))
And my defrule when phase choose-student is asserted
(defrule student-select
(phase choose-student)
=>
(printout t "Input Student ID: ")
(assert (lookupID (id (read)))))
The rule student-select, activates but never fires. My program stops there.
It's better to write the control part of an application separate from the rules.
(deffunction ask ()
(printout t "Consult another? (y/n) ")
(if (eq (read) y) then
(printout t "Input Student ID: ")
(assert (lookupID (id (read))))
(return TRUE)
else
(return FALSE)))
Use this in a while function:
(while (ask) do (run))
And you won't need the (phase choose-student) any more.
Here is my code
(deffacts startup
(bird canary)
(colour-canary yellow)
(bird ostrich)
(can-not-fly ostrich)
)
(defrule r-bird-test
(bird ?var)
(not (bird ostrich))
=>
(printout t ?var " ****" crlf)
)
Now, when i (reset) and (run) it doesn't print "canary ****". Am i not using the not condition properly? Can anyone point out what i am missing here? Thanks.
As written the not conditional element prevents the rule from executing if the fact (bird ostrich) is present. Since that fact is present once you perform a (reset), the rule does not execute. If you want the rule to execute for each bird fact where ?var is not ostrich, you need to write the rule this way:
CLIPS>
(deffacts startup
(bird canary)
(colour-canary yellow)
(bird ostrich)
(can-not-fly ostrich))
CLIPS>
(defrule r-bird-test
(bird ?var&~ostrich)
=>
(printout t ?var " ****" crlf))
CLIPS> (reset)
CLIPS> (run)
canary ****
CLIPS>