Presentation is loading. Please wait.

Presentation is loading. Please wait.

Simple Rule Based Systems Directly implementing rule based systems in Java Need vocabulary Simplicity sometimes works.

Similar presentations


Presentation on theme: "Simple Rule Based Systems Directly implementing rule based systems in Java Need vocabulary Simplicity sometimes works."— Presentation transcript:

1 Simple Rule Based Systems Directly implementing rule based systems in Java Need vocabulary Simplicity sometimes works

2 Simple Rules do { fired = false;... if ( (!wm[influenza] && wm[nasal_congestion] && wm[viremia]) { wm[influenza] = true; fired = true; continue; }... // more rules } while (fired == true);

3 CLIPS Install and set shortcut as needed for your system. Prompt CLIPS> To quit type (exit) CLIPS> (exit) For help type (help) CLIPS> (help)

4 Facts Form: List with parentheses around it. (Harry likes Sally) Order counts –(Sally likes Harry) is not the same fact. Can have strings or numbers –(car price 25000)

5 Entering Facts CLIPS> (assert (Harry likes Sally)) –Assert is a command to enter the fact CLIPS> (facts) –Show all facts CLIPS> (clear) –Erase all facts CLIPS> (reset) –Erases all facts except (initial-fact)

6 Retracting Facts Use (facts) to see fact number Use retract with the number –CLIPS> (retract 3) –Removes fact number 3

7 Rules Example CLIPS> (defrule valuable_horse ( ?x horse) ( ?x parent_of ?y) ( ?y is_fast) ( ?z <- (buy_nothing) => ( assert (?x is_fast)) (printout t “buy this horse” ?x crlf) (retract ?z) ) ) ; Close all braces

8 Useful Commands CLIPS> (save “duck.clp”) CLIPS> (load “duck.clp”); Loads all rules in file CLIPS> (save-facts “duck-facts.fct”) – Saves all facts CLIPS> (load-facts “duck-facts.fct”) – Loads all facts in file. CLIPS> (rules) shows rules CLIPS> (ppdefrule duck) shows rule duck CLIPS> (run ) runs rules

9 Reading Data Use the (read) function. Wherever (read) is encountered, the program waits for the user to type something in, then substitutes that response. –Try (assert (user-input (read))) at the CLIPS prompt. –After you press return, you'll need to type something else (anything) before the command will complete. –When you look at the facts, you'll see a new fact with your input as the second item.

10 Read Example (defrule what-is-child (animal ?name) (not (child-of ?name ?)) => (printout t "What do you call the child of a " ?name "?") (assert (child-of ?name (read))) )

11 Result When you run it, the system will now prompt you for the name of the young of any animal it doesn't know about. It will use the data you enter to assert a fact, which could then be used by other rules.

12 Example 2 (defrule are-lights-working (not (lights-working ?)) => (printout t "Are the car's lights working (yes or no)?") (assert (lights-working (read))) )


Download ppt "Simple Rule Based Systems Directly implementing rule based systems in Java Need vocabulary Simplicity sometimes works."

Similar presentations


Ads by Google