0
votes

I would like to solve the following very basic problem with CLIPS:

Given a list of restaurants and types of food served by those restaurants and also given a food craving, give me a suggestion on what restaurant to visit.

What I have so far is pretty basic. I can create a template for a restaurant with the different food possibilities:

;;;*************
;;;* EATERIES  *
;;;*************

(deftemplate restaurant
   (slot name
      (type SYMBOL)
      (default ?NONE))
   (slot food-served
      (type SYMBOL)
      (allowed-symbols salad coffee vegan breakfast burgers)
  (default blank)))

How would I then define specific restaurants with their food choices?

How would I specify the food I am craving?

How would I define rules, for example:

IF craving-salad THEN go-to-salad-bar
1

1 Answers

0
votes

I suggest you to create a model with restaurant and person templates and add some rules to manage your required logic. You can find a lot of example with CLIPS. It took me some times to understand how CLIPS works. Reading the manuals is a good start point and looking at examples is fundamental. Here a little script I tested for you. Run it in CLIPS.

(deftemplate restaurant
   (slot name
      (type SYMBOL))
   (slot food-served
      (type SYMBOL)
      (allowed-symbols salad coffee vegan breakfast burgers)))

(deftemplate person
   (slot name
      (type STRING))
   (slot craving
      (type SYMBOL)
      (allowed-symbols salad coffee vegan breakfast burgers)))

(defrule suggestion
   (restaurant (food-served ?food) (name ?restaurantName))
   (person (name ?personName) (craving ?craving))
   (test (eq ?food ?craving))
   =>
   (bind ?message (format nil "It seems that %s is craving %s. I suggest him to go to %s!" ?personName ?food ?restaurantName))
   (printout t ?message crlf))          


 (assert (restaurant (name McDonalds) (food-served burgers)))
 (assert (restaurant (name Dannys) (food-served breakfast)))
 (assert (restaurant (name KingOfSalads) (food-served salad)))
 (assert (restaurant (name CoffeeParadise) (food-served coffee)))

 (assert (person (name "Nicola") (craving burgers)))
 (assert (person (name "Rebecca") (craving salad)))
 (assert (person (name "James") (craving breakfast)))

 (run) 
 (exit)

Bye Nicola