I'm just starting to look seriously at jess, and thought i'd try to whip up a simple app myself and get familiar with the syntax. I have a question already.
Given a static list of recipes, I want to search a list of items in the pantry and see what recipes I can completely fulfill. I have a simple batch file to create def templates and assert a recipe.
;kbatch.clp
;
(deftemplate pantry-list "items in pantry"
(slot name)
(multislot listitems))
;
(deftemplate pantry-list "items in pantry"
(slot name)
(multislot listitems))
(deftemplate recipe "a recipe"
(slot name)
(multislot ingredients)
)
(slot name)
(multislot ingredients)
)
(batch krule.clp)
(batch kfunc.clp)
(batch kfunc.clp)
(deffacts recipes "Favorite Recipes"
(recipe (name beer) (ingredients barley hops yeast))
)
(recipe (name beer) (ingredients barley hops yeast))
)
(reset)
(facts)
(watch activations)
(facts)
(watch activations)
I also have some functions to assert recipes and pantry items.
(deffunction f-pantry ()
" generate a pantry list"
(assert
(pantry-list (name a-list) (listitems bread "peanut butter" barley))
(pantry-list (name b-list) (listitems salt))
)
)
" generate a pantry list"
(assert
(pantry-list (name a-list) (listitems bread "peanut butter" barley))
(pantry-list (name b-list) (listitems salt))
)
)
(deffunction frecipe-sandwich ()
" generate sandwich recipes"
(assert
(recipe (name "pbj sandwich") (ingredients bread "peanut butter" jelly))
(recipe (name "pastrami sandwich") (ingredients bread pastrami cheese))
)
)
" generate sandwich recipes"
(assert
(recipe (name "pbj sandwich") (ingredients bread "peanut butter" jelly))
(recipe (name "pastrami sandwich") (ingredients bread pastrami cheese))
)
)
And finally, now I want to actually find what recipes are fulfilled. I wrote my very first rule, which at least catches valid pantry items (the ones that exist in a recipe). I even assert a transient rule, thinking this might be on the right track.
(defrule match-pantry-item-to-recipe
(recipe (name ?name) (ingredients $? ?item $?))
(pantry-list (name ?listname) (listitems $? ?item $?))
=>
(printout t ?name " ingredient found " ?item crlf)
(assert (f-found ?name ?item))
)
(recipe (name ?name) (ingredients $? ?item $?))
(pantry-list (name ?listname) (listitems $? ?item $?))
=>
(printout t ?name " ingredient found " ?item crlf)
(assert (f-found ?name ?item))
)
Any help would be greatly appreciated, even if it is just an approach to the proper solution.
Regards,
Ken
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
