(in-package 'USER) ;; This is the demo provided along with the CLASSIC tape. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Convenient Functions ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun no-winery (x) (null (cl-ind-role-values x (cl-named-role 'maker) :warn? nil))) ;; Returns any wines that match the description of individual x (defun wines (x) ;; x is @individual ;; ind-descriptor returns a concept that contains all the restrictions ;; on individual x (see cl-ind-descriptor) (remove-if #'no-winery (cl-concept-instances (ind-descriptor x)))) (defun meal (meal expression) ;; turn off warnings during the creation of the individual. (let* ((warnings? (cl-classic-warn-mode)) mealoutput) (util-set-warn nil) (setq mealoutput (cl-create-ind meal expression)) (util-set-warn warnings?) mealoutput)) (defun grapes (x) ;; x is the @individual descriptor created for a meal-course (let* ((grape-list nil) (inds (wines x))) (dolist (y inds) (setq grape-list (remove-duplicates (append grape-list (cl-ind-role-values y (cl-named-role 'grape)))))) grape-list)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;; Examples ;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #| ;; An example of getting the descendants of an unclassified concept: (cl-concept-descendants (cl-parse-concept '(and bordeaux early-harvest))) |# ;; Examples of finding the right wine ; This statement creates an ind which is a MEAL-COURSE and has a drink w1a. ; w1a gets created by the definition and inherits a number of restrictions ; from the rule associated with m1a. The set of restrictions on w1a is used ; by function Wines to retrieve any wines that match the restrictions. (cl-create-ind 'm1a '(and spicy-red-meat-course (fills drink w1a))) ; performs the query (wines @w1a) ; more of the same (cl-create-ind 'm2a '(and non-red-meat-course (fills drink w2a))) (wines @w2a) (cl-create-ind 'm3a '(and dark-meat-fowl-course (fills drink w3a))) (wines @w3a) (cl-create-ind 'm6 '(and meal-course (fills food duck) (fills drink w6) )) (wines @w6) (cl-create-ind 'm7 '(and meal-course (fills food turkey) (fills drink w7) )) (wines @w7) (cl-create-ind 'm8 '(and meal-course (fills food goose) (fills drink w8) )) (wines @w8) (cl-create-ind 'm9 '(and meal-course (fills food flounder) (fills drink w9) )) (wines @w9) (cl-create-ind 'm10 '(and meal-course (fills food swordfish) (fills drink w10) )) (wines @w10) ;;; Arno Demo ;; Just a few queries on the KB (cl-concept-instances @c{white-wine}) (cl-print-ind @forman-chardonnay) (cl-create-ind 'new-wine '(and wine (fills body full) (fills flavor moderate))) (cl-print-ind @new-wine) (cl-define-concept 'mod-or-strong-wine '(and wine (all flavor (one-of moderate strong)))) (cl-instance? @new-wine @mod-or-strong-wine) (cl-concept-instances @mod-or-strong-wine) (cl-concept-ancestors @mod-or-strong-wine) (cl-create-ind 'm1 '(and meal-course (fills food crab) (fills drink w1))) (cl-instance? @m1 @seafood-course) (cl-ind-ancestors @m1) (cl-print-concept (cl-ind-descriptor @w1)) (wines @w1) ;; No role fillers for flavor, but there is some partial info: (cl-ind-role-fillers @w1 @r{flavor}) (cl-print-concept (cl-ind-role-restrs @w1 'all @r{flavor})) ;; 2 meal-courses -- 1 drink ; In the following, some restrictions are set on w24 by m24 and some more ; are set on it by m25. Thus when wines is called after m25 is created, ; it will return any individuals that satisfy the restrictions imposed by ; both. (cl-create-ind 'm24 '(and meal-course (fills food oysters) (fills drink w24))) (cl-print-concept (cl-ind-descriptor @w24)) (wines @w24) (cl-create-ind 'm25 '(and meal-course (fills food cake) (fills drink w24))) (cl-print-concept (cl-ind-descriptor @w24)) (wines @w24) ; These will produce all concepts that are not disjoint from the ; concept in the first argument. @c{WINE} is used to prune the search ; to concepts WINE and its descendants. (cl-concept-find-compatible (cl-ind-descriptor @w1) @c{wine}) (cl-concept-find-compatible (cl-ind-descriptor @new-wine) @c{wine}) (cl-concept-find-compatible @mod-or-strong-wine @c{wine})