wood burning stoves 2.0*
The moose likes Other Java Products and Servers and the fly likes need help:dos based .clp to java gui Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "need help:dos based .clp to java gui" Watch "need help:dos based .clp to java gui" New topic
Author

need help:dos based .clp to java gui

mei galang
Greenhorn

Joined: Feb 05, 2006
Posts: 14
--------------------------------------------------------------------------------
hi im a student an im making an implementation of case based reasoning..anyway,
i have a big problem on making this sample DOS based .clp program into a java program with simple GUI..i hope you guys can help me.
attached is the code for a self learning decision tree, animal.clp

(deftemplate node
(slot name)
(slot type)
(slot question)
(slot yes-node)
(slot no-node)
(slot answer))

(defrule initialize-1
(not (node (name root)))
=>
(load-facts "examples/animal.dat")
(assert (current-node root)))

(defrule initialize-2
(declare (salience 100))
?fact & lt; - (next-gensym-idx ?idx)
=>
(retract ?fact)
(setgen ?idx))


(defrule ask-decision-node-question
?node & lt; - (current-node ?name)
(node (name ?name)
(type decision)
(question ?question))
(not (answer ?))
=>

(printout t ?question " (yes or no) ")
(assert (answer (read))))

(defrule bad-answer
?answer & lt; - (answer ~yes&~no)
=>
(retract ?answer))

(defrule proceed-to-yes-branch
?node & lt;- (current-node ?name)
(node (name ?name)
(type decision)
(yes-node ?yes-branch))
?answer & lt;- (answer yes)
=>
(retract ?node ?answer)
(assert (current-node ?yes-branch)))

(defrule proceed-to-no-branch
?node & lt;- (current-node ?name)
(node (name ?name)
(type decision)
(no-node ?no-branch))
?answer & lt;- (answer no)
=>
(retract ?node ?answer)
(assert (current-node ?no-branch)))

(defrule ask-if-answer-node-is-correct
?node & lt;- (current-node ?name)
(node (name ?name) (type answer) (answer ?value))
(not (answer ?))
=>
(printout t "I guess it is a " ?value crlf)
(printout t "Am I correct? (yes or no) ")
(assert (answer (read))))

(defrule answer-node-guess-is-correct
?node & lt;- (current-node ?name)
(node (name ?name) (type answer))
?answer & lt;- (answer yes)
=>
(assert (ask-try-again))
(retract ?node ?answer))

(defrule answer-node-guess-is-incorrect
?node & lt;- (current-node ?name)
(node (name ?name) (type answer))
?answer & lt;- (answer no)
=>
(assert (replace-answer-node ?name))
(retract ?answer ?node))

(defrule ask-try-again
(ask-try-again)
(not (answer ?))
=>
(printout t "Try again? (yes or no) ")
(assert (answer (read))))

(defrule one-more-time
?phase & lt;- (ask-try-again)
?answer & lt;- (answer yes)
=>
(retract ?phase ?answer)
(assert (current-node root)))

(defrule no-more
?phase & lt;- (ask-try-again)
?answer & lt;- (answer no)
=>
(retract ?phase ?answer)
(bind ?g (gensym*))
(assert (next-gensym-idx (sub-string 4 (str-length ?g) ?g)))

;; RETAIN
(save-facts "examples/animal.dat" node next-gensym-idx))

;; LEARNING PART/REVISE

(defrule replace-answer-node
?phase & lt;- (replace-answer-node ?name)
?data & lt;- (node (name ?name)
(type answer)
(answer ?value))
=>
(retract ?phase)
; Determine what the guess should have been
(printout t "What is the animal? ")
(bind ?new-animal (read))
; Get the question for the guess
(printout t "What question when answered yes ")
(printout t "will distinguish " crlf " a ")
(printout t ?new-animal " from a " ?value "? ")
(bind ?question (readline))
(printout t "Now I can guess " ?new-animal crlf)
; Create the new learned nodes
(bind ?newnode1 (gensym*))
(bind ?newnode2 (gensym*))
(modify ?data (type decision)
(question ?question)
(yes-node ?newnode1)
(no-node ?newnode2))
(assert (node (name ?newnode1)
(type answer)
(answer ?new-animal)))
(assert (node (name ?newnode2)
(type answer)
(answer ?value)))
; Determine if the player wants to try again
(assert (ask-try-again)))


(reset)
(run)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

Welcome to JavaRanch!

By a "DOS based .clp", I'm assuming you mean a command-line Jess program. The above is one of the sample programs that comes in the Jess distribution; the formatting has been removed and all the "<" characters have been HTML-itized, but otherwise, it doesn't look like you've changed it in any way. You're asking how to add a GUI to it? Well, first I have to ask you some questions:

Do you know Java language?
Have you written GUI programs in Java before?
Do you know the Jess language?
Do you want to write your GUI in Java, or in Jess?
[ February 06, 2006: Message edited by: Ernest Friedman-Hill ]

[Jess in Action][AskingGoodQuestions]
mei galang
Greenhorn

Joined: Feb 05, 2006
Posts: 14
Originally posted by Ernest Friedman-Hill:
Hi,

Welcome to JavaRanch!

By a "DOS based .clp", I'm assuming you mean a command-line Jess program. The above is one of the sample programs that comes in the Jess distribution; the formatting has been removed and all the "<" characters have been HTML-itized, but otherwise, it doesn't look like you've changed it in any way. You're asking how to add a GUI to it? Well, first I have to ask you some questions:

Do you know Java language?
Have you written GUI programs in Java before?
Do you know the Jess language?
Do you want to write your GUI in Java, or in Jess?

[ February 06, 2006: Message edited by: Ernest Friedman-Hill ]


first of all thank you so much for the reply, i really appreciate it
Do you know Java language? yes
Have you written GUI programs in Java before?yes
Do you know the Jess language?yes
Do you want to write your GUI in Java, or in Jess?
i've started writing GUI in Jess but I'm having difficulty, I would like to learn both and from then maybe I can decide which method is more suitable for my thesis.

thanks again, Sir.
mei galang
Greenhorn

Joined: Feb 05, 2006
Posts: 14
sir,

with regards to the DOS based animal.clp, yes, I refer to a jess program running on the command line.

as a follow up to my question about the node and the gen, i wrote my own version of a decision tree that suits my application, i used animal.dat as my basis, here's the sample code. the code isnt finished yet, i just want to know if im on the right track


(MAIN:: premises (name root) (type case) (prem "What is the problem?
You can choose from the following symptoms:
a. Your monitor shows improper display
b. Your pointer is behaving erratically
c. You hear weird sounds from your PC
d. Your computer is hanging") (a-node node1) (b-node node2) (c-node node3)
(d-node node4) (e-node node5) (f-node node6) (solution nil))

(MAIN:: premises (name node1) (type case) (prem "Your monitor shows improper display.
What's in the display or what did you do?
Here are the possible cases:
a. You tried to change monitor resolution
b. Your computer just boot but failed to display anything
c. There are black borders in the screen
d. There are erratic, fuzzy displays
e. The screen flickers or shrinks
f. Display is wiggly of blurred") (a-node node5) (b-node node6) (c-node node7)
(d-node node8) (e-node node9) (f-node node10) (solution nil))
(MAIN: :p remises (name node5) (type case) (prem "You tried to change monitor resolution.
What happened after?
Here are the possible cases:
a. The monitor screen shifts
b. You can't change your monitor resolution") (a-node node23) (b-node node24)
(c-node nil) (d-node nil) (e-node nil) (f-node nil) (solution nil))
(MAIN: :p remises (name node23) (type solution) (prem "Your monitor screens shifts")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: There is a problem with the adapter card.
I recommend the following solutions:
a. Check your program display settings
b. Adjust horizontal/vertical controls
c. Configure software or adapter card for monitor type"))
(MAIN: :p remises (name node24) (type solution) (prem "You can't change your monitor resolution")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: You have a low disk space memory or a corrupt driver.
I recommend the following solution/s:
Check for installed corrupt drivers (video card, motheboard, etc,
uninstall it, then try installing it again."))
(MAIN: :p remises (name node6) (type solution) (prem "Your computer just boot but failed to display anything.")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: There is a probem with the power cords.
I recommend the following solution/s:
Check your power cords for loose connection."))
(MAIN: :p remises (name node7) (type solution) (prem "There are black borders in the screen.")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: The problem may be in the configuration controls.
I recommend the following solution/s:
a. Adjust horizontal/vertical controls
b. Configure software or adapter card for monitor type."))
(MAIN: :p remises (name node8) (type solution) (prem "There are black borders in the screen.")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: The problem may be in the configuration controls.
I recommend the following solution/s:
a. Adjust horizontal/vertical controls
b. Configure software or adapter card for monitor type."))
(MAIN: :p remises (name node9) (type solution) (prem "The screen flickers or shrinks.")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: The problem may involve the PC card, the motherboard, the video card or monitor wiring.
I recommend the following solution/s:
a. Check PC card placement
b. Check power and data cables
c. Replace video card or motheboard if video adapter is built in."))
(MAIN: :p remises (name node10) (type solution) (prem "The screen flickers or shrinks.")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: The problem may involve the PC card, the motherboard, the video card or monitor wiring.
I recommend the following solution/s:
a. Check PC card placement
b. Check power and data cables
c. Replace video card or motheboard if video adapter is built in."))

(MAIN: :p remises (name node2) (type case) (prem "Your pointer is behaving erratically.
What exactly is happening to the pointer?
Here are the possible cases:
a. The pointer is moving shakily or unsteadily
b. The pointer is not working at all
c. The pointer was functioning then suddenly stopped")
(a-node node11) (b-node node12) (c-node node13)
(d-node nil) (e-node nil) (f-node nil) (solution nil))
(MAIN: :p remises (name node11) (type case) (prem "The pointer is moving shakily or unsteadily.
What kind of mouse do you have?
Here are the possible cases:
a. You have a non-optical/serial mouse
b. You have an optical mouse
(a-node node25) (b-node node26) (c-node nil)
(d-node nil) (e-node nil) (f-node nil) (solution nil))
(MAIN: :p remises (name node25) (type solution) (prem "You have a non-optical/serial mouse.")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: Your mouse ball might be dirty.
I recommend the following solution/s:
a. Clean the trackball then restart the PC
b. Inspect cables for damages."))
(MAIN: :p remises (name node26) (type solution) (prem "You have an optical mouse.")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: Your optical sensor might have been damaged.
I recommend the following solution/s:
Make sure optical sensors and grid surface are clean and not worn out."))
(MAIN: :p remises (name node12) (type solution) (prem "The pointer is not working at all.")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: The cable of the mouse might have a loose connection.
I recommend the following solution/s:
Make sure the cable connecting the pointing device to your computer is firmly plugged in."))
(MAIN: :p remises (name node13) (type solution) (prem "The pointer was functioning then suddenly stopped.")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: An offending program might have been used.
I recommend the following solution/s:
Disable pointing device using keyboard strokes. Go to start, control panel,
mouse, device settings, used device, disable, then restart the computer and try enabling it again."))

(MAIN: :p remises (name node3) (type case) (prem "You hear weird sounds from your PC.
What kind of sound?
Here are the possible cases:
a. You hear snapping sounds
b. You hear scratchy sounds
c. You hear cracking sounds
d. You hear popping sounds
e. You hear beeps")
(a-node node14) (b-node node15) (c-node node16)
(d-node node17) (e-node node18) (f-node nil) (solution nil))
(MAIN: :p remises (name node14) (type solution) (prem "You hear snapping sounds.")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: You probably have dirty speakers.
I recommend the following solution/s:
Have your speakers cleaned."))
(MAIN: :p remises (name node15) (type solution) (prem "You hear scratchy sounds.")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: There is probably an electrical magnetic interference device (like cell phone) besde your PC.
I recommend the following solution/s:
Try moving the device away from your speaker."))
(MAIN: :p remises (name node16) (type solution) (prem "You hear cracking sounds.")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: The speakers might not be positioned properly.
I recommend the following solution/s:
Try moving the speakers to a different location."))
(MAIN: :p remises (name node17) (type solution) (prem "You hear popping sounds.")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: The speakers might not be positioned properly.
I recommend the following solution/s:
Try moving the speakers to a different location."))
(MAIN: :p remises (name node18) (type case) (prem "You hear beeps.
How many?
Here are the possible cases:
a. You hear 1 long beep followed by 2 short beeps
b. You hear 1 long beep
c. You hear 1 short beep")
(a-node node27) (b-node node28) (c-node node29) (d-node nil) (e-node nil) (f-node nil)
(solution nil))
(MAIN: :p remises (name node27) (type solution) (prem "You hear 1 long beep followed by 2 short beeps.")
(a-node nil) (b-node nil) (c-node nil) (d-node nil) (e-node nil) (f-node nil)
(solution "Diagnosis: The problem may be in the motherboard or video card.
I recommend the following solution/s:
a. Run CMOS setup program and correct video settings
b. Set switches for proper display type
c. Check installation of video card or replace it
d. Replace motherboard if video card adapter is built in."))



thanks again in advance
[ February 08, 2006: Message edited by: mei galang ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Originally posted by mei galang:
i've started writing GUI in Jess but I'm having difficulty, I would like to learn both and from then maybe I can decide which method is more suitable for my thesis.


Well, you'd need to describe those difficulties before we can help -- tell me what you've done, and where you're lost, and I'll see what I can do. Please don't post hundreds of lines of code again -- nobody wants to read that. Just tell me what you're doing. Also let me know what resources you've been using: have you looked at the "frame.clp" example that comes with Jess? Do you have "Jess in Action," which has whole chapters devoted to GUIs? Have you read the manual all the way through?
mei galang
Greenhorn

Joined: Feb 05, 2006
Posts: 14
Originally posted by Ernest Friedman-Hill:


Well, you'd need to describe those difficulties before we can help -- tell me what you've done, and where you're lost, and I'll see what I can do. Please don't post hundreds of lines of code again -- nobody wants to read that. Just tell me what you're doing. Also let me know what resources you've been using: have you looked at the "frame.clp" example that comes with Jess? Do you have "Jess in Action," which has whole chapters devoted to GUIs? Have you read the manual all the way through?


sir,
thank you again for the time. I am also sorry for posting long codes.. Sir, I am in need of explanations regarding embedding jess into java wherein I will write my codes on java developing tool and embed jess codes in it then compile and run the program in the developing tool. I was hoping if there may be other means of communicating with you where we can understand each other more. Thank you again.
[ February 11, 2006: Message edited by: mei galang ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

We can't really commuinicate if you won't answer the questions that I ask you. But in any case, I asked you if you have used all the resources listed above. If you haven't, then please do; all of them will be helpful to you.
mei galang
Greenhorn

Joined: Feb 05, 2006
Posts: 14
Originally posted by Ernest Friedman-Hill:


Well, you'd need to describe those difficulties before we can help -- tell me what you've done, and where you're lost, and I'll see what I can do. Please don't post hundreds of lines of code again -- nobody wants to read that. Just tell me what you're doing. Also let me know what resources you've been using: have you looked at the "frame.clp" example that comes with Jess? Do you have "Jess in Action," which has whole chapters devoted to GUIs? Have you read the manual all the way through?


yes i have tried running frame.clp, i used it for making GUIs.
I have "Jess in Action".. i have read it but im having difficulty to embedd jess to java.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Originally posted by mei galang:
i have read it but im having difficulty to embedd jess to java.


So what have you tried, and what have the difficulties been?
mei galang
Greenhorn

Joined: Feb 05, 2006
Posts: 14
Originally posted by Ernest Friedman-Hill:


So what have you tried, and what have the difficulties been?


Im doing an implementation of Case-Based Reasoning approach using JAVA and JESS. Its an information system that troubleshoots a PC. Each troubleshooting situation is equivalent to a case.
It will ask the user to choose symptom(s) classified in to combo boxes. From there it will compare the symptoms to the rules for the cases inside JESS. It is supposed to give as an output all the cases that matched with the input of the user. The system that Im doing is also suppossed to learn, so there should be an interface to add new cases along with its symptoms and the solution to its problem, into its knowledge base.
Now my problem is, is it possible to generate a rule from a given input of a user in the application without hard coding the new rule?

These are my input values for a new case:
Problem: Memory is running low
Symptom1:There are many programs running.
Symptom2:A prompt that there is low memory is displayed.
Solution:
Close all programs that are not being used.

(defrule MAIN::$new_problem
(if $symptom1 is true or $symptom2 is true)
=>
(recommend-action $solution
(halt))
im not sure if this is possible in JESS but this is what im planning to do to make my knowledge base dynamic without touching the code itself.
i hope im not giving you a headache because your my only hope.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

That's easy to do in Jess. From Java, you can just build the rule as a string, then pass it to the "executeCommand()" method of your Rete object. The rule is compiled and added to the rule engine. You have to use proper syntax, of course.
mei galang
Greenhorn

Joined: Feb 05, 2006
Posts: 14
thanks sir, actually i've read about that in chapter 18 of JESS in action but my problem is im more comfortable programming JESS by importing java instead of the other way around.
is there a counterpart for "execteCommand()" and does the same thing to build new rules if im doing it in JESS?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

If you're writing Jess code, and you want to build more Jess code as a String and then execute it -- i.e., assemble the text of a rule, and then turn it into a rule -- you do that with the "(exec)" function. The "function index" chapter of the manual describes all the functions in the Jess language, including this one.
mei galang
Greenhorn

Joined: Feb 05, 2006
Posts: 14
Sir, are you referring to Appendix A?
If yes, I cant seem to find an "(exec)" command from the list of functions
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Originally posted by mei galang:
Sir, are you referring to Appendix A?


Yes, or chapter 8 (in the Jess 6 manual). I looked it up and it's named "eval", not "exec" -- my mistake, sorry!
mei galang
Greenhorn

Joined: Feb 05, 2006
Posts: 14
no problem sir.
anyway, i looked it up and its syntax is (eval<string>),
im so sorry im so clueless, is the string the input of the user? or can you possibly give an example? thanks a lot
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

(eval "(defrule my-rule (say-hello) => (printout t Hello crlf))")

Has the same effect as

(defrule my-rule
    (say-hello)
    =>
    (printout t Hello crlf))
mei galang
Greenhorn

Joined: Feb 05, 2006
Posts: 14
Originally posted by Ernest Friedman-Hill:
(eval "(defrule my-rule (say-hello) => (printout t Hello crlf))")

Has the same effect as

(defrule my-rule
    (say-hello)
    =>
    (printout t Hello crlf))


thanks for the reply, i'll try to incorporate it in my code.
mei galang
Greenhorn

Joined: Feb 05, 2006
Posts: 14
hi sir,
im currently working on the rules of my application, im supposed to be comparing the value of my 4 combo boxes to every rules. I want to be able to track how many matched with the values from the combo boxes. Now my question is, how can i compare them and at the same time keep track of the count of those values.
i have this psuedocode of what i want to happen but i think it is tedious and inefficient.

rule ...
( (if ?handler is x)
or (if ?handler2 is y)
...
or (if ?handlerx is a))
then
(if ?handler is x then (call_add_to_function))


or is it possible to call a function after every comparison in the if statement

if ?handler is x
(call_counter_funtion)
or
?handler2 is y
(call_counter_funtion)
then
statement


where ?handler,?handler2,?handlerx are the values from combo box

thanks in advance..i hope i didnt give you a headache again
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

I'm afraid I don't really understand the question; can you explain it again? Are you trying to do this during pattern matching, or are you writing if-then statements on the right side of a rule? I don't know what these "?handlerX" variables represent, either.
mei galang
Greenhorn

Joined: Feb 05, 2006
Posts: 14
yes, im doing a pattern matching while counting the matches.
what i want to do is to find a match for the value of the combobox inmy rules and then count the matches (ex. 2/4)

in relation to what i've mentioned before about my thesis
the items in the combo box will be the symptoms, i have 4 categories of symptoms of troubleshooting problems subdivided into 4 combo boxes. The user is to choose 1 symptom from each combo box that applies to its problem.
and then what i want to happen is, the values of the combo box will find a match to every rule and count how many matches were made.
the application will then output the rule's correspond solution with highest probability of match.
mei galang
Greenhorn

Joined: Feb 05, 2006
Posts: 14
about the ?handlerX sir, this is my variable to hold the value chosen symptom by the user from the combo box...
mei galang
Greenhorn

Joined: Feb 05, 2006
Posts: 14
Hi sir! I would like to thank you for assisting me in my project.
I already submitted my project and it was approved.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: need help:dos based .clp to java gui
 
Similar Threads
JESS: exist and test functions
Jess Query
Jess Question
About jess engine rule
jess