Help in clips programming

657 views
Skip to first unread message

Yunus Emre

unread,
Jan 15, 2012, 5:22:06 PM1/15/12
to CLIPSESG
Hi. We have a decision tree and attributes table. We need to write
some rules in clips. We tried to write some commands but we don’t know
how to end and run this Project. Could you help us in this Project?

My commands that i used;

(deftemplate attributes
(slot outlook
(allowed-values sunny overcast rain))
(slot temperature
(allowed-values hot mild cool))
(slot humidity
(allowed-values high normal))
(slot windy
(allowed-values true false))
(slot class
(allowed-values p n)))
(assert (attributes (outlook sunny)
(temperature hot)
(humidity high)
(windy false)
(class n)))
…………
(assert (attributes (outlook rain)
(temperature mild)
(humidity high)
(windy false)
(class n)))
(defrule r1
(outlook overcast)
=>
(printout t "Class P"))

Yunus Emre Durgun

unread,
Jan 15, 2012, 5:23:12 PM1/15/12
to CLIPSESG
Attributes and decision tree is here : http://imageshack.us/photo/my-images/38/attrdectr.png/

2012/1/15 Yunus Emre <yunusem...@gmail.com>

CLIPS Support

unread,
Jan 18, 2012, 3:01:43 PM1/18/12
to CLIPSESG
Put your constructs in one file: rules.clp

(deftemplate attributes
(slot outlook
(allowed-values sunny overcast rain))
(slot temperature
(allowed-values hot mild cool))
(slot humidity
(allowed-values high normal))
(slot windy
(allowed-values true false))
(slot class
(allowed-values p n)))

(defrule r1
(attributes (outlook overcast))
=>
(printout t "Class P"))

Put your test data in another test1.bat

(assert (attributes (outlook sunny)
(temperature hot)
(humidity high)
(windy false)
(class n)))

(assert (attributes (outlook rain)
(temperature mild)
(humidity high)
(windy false)
(class n)))


Then you can enter commands into the CLIPS command prompt:

CLIPS> (load "rules.clp")
%*
TRUE
CLIPS> (reset)
CLIPS> (batch "test1.bat")
TRUE
CLIPS> (assert (attributes (outlook sunny)
(temperature hot)
(humidity high)
(windy false)
(class n)))
<Fact-1>
CLIPS>
(assert (attributes (outlook rain)
(temperature mild)
(humidity high)
(windy false)
(class n)))
<Fact-2>
CLIPS> (run)
CLIPS>

In this case, your rule is looking for overcast weather and since
there is none, the rule does not execute

Yunus Emre Durgun

unread,
Jan 18, 2012, 4:04:16 PM1/18/12
to clip...@googlegroups.com
Thank you very much. Actually my all codes are in here and i couldn't work it. There is a warning. Can you help me to fix this programme?

Warning:

[CSTRCPSR4] Cannot redefine deftemplate attributes while it is in use.
ERROR:
(deftemplate MAIN::attributes
[CSTRCPSR1] WARNING: Redefining defrule: r1 +j+j
[CSTRCPSR1] WARNING: Redefining defrule: r2 =j+j+j
[CSTRCPSR1] WARNING: Redefining defrule: r3 =j+j+j
[CSTRCPSR1] WARNING: Redefining defrule: r4 =j+j+j
[CSTRCPSR1] WARNING: Redefining defrule: r5 =j+j+j
FALSE

Codes:


(deftemplate attributes
    (slot outlook
        (allowed-values sunny overcast rain))
    (slot temperature
        (allowed-values hot mild cool))
    (slot humidity
        (allowed-values high normal))
    (slot windy
        (allowed-values true false))))

(deftemplate response
    (slot class))


(defrule r1
(attributes (outlook overcast))
=>
(assert (response (class P))))

(defrule r2
(attributes (outlook sunny))
(and (attributes (humidity high)))
=>
(assert (response (class N))))

(defrule r3
(attributes (outlook sunny))
(and (attributes (humidity normal)))
=>
(assert (response (class P))))

(defrule r4
(attributes (outlook rain))
(and (attributes (windy true)))
=>
(assert (response (class N))))

(defrule r5
(attributes (outlook rain))
(and (attributes (windy false)))
=>
(assert (response (class P))))


(assert (attributes    (outlook sunny)
            (temperature hot)
            (humidity high)
            (windy false)))

(assert (attributes    (outlook sunny)
            (temperature hot)
            (humidity high)
            (windy true)))
(assert (attributes    (outlook overcast)
            (temperature hot)
            (humidity high)
            (windy false)))

(assert (attributes    (outlook rain)
            (temperature mild)
            (humidity high)
            (windy false)))
(assert (attributes    (outlook rain)
            (temperature cool)
            (humidity normal)
            (windy false)))
(assert (attributes    (outlook rain)
            (temperature cool)
            (humidity normal)
            (windy true)))
(assert (attributes    (outlook overcast)
            (temperature cool)
            (humidity normal)
            (windy true)))
(assert (attributes    (outlook sunny)
            (temperature mild)
            (humidity high)
            (windy false)))
(assert (attributes    (outlook sunny)
            (temperature cool)
            (humidity normal)
            (windy false)))

(assert (attributes    (outlook rain)
            (temperature mild)
            (humidity normal)
            (windy false)))
(assert (attributes    (outlook sunny)
            (temperature mild)
            (humidity normal)
            (windy false)))
(assert (attributes    (outlook overcast)
            (temperature mild)
            (humidity high)
            (windy true)))
(assert (attributes    (outlook overcast)
            (temperature hot)
            (humidity normal)
            (windy false)))

(assert (attributes    (outlook rain)
            (temperature mild)
            (humidity high)
            (windy true)))

2012/1/18 CLIPS Support <garyd...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "CLIPSESG" group.
To post to this group, send email to CLIP...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/CLIPSESG?hl=en

--> IF YOU NO LONGER WANT TO RECEIVE EMAIL <--
Visit this group at http://groups.google.com/group/CLIPSESG?hl=en
Click on "Edit my membership" link.
Select the "No Email" radio button.
Click the "Save these settings" button.

--> IF YOU WANT TO UNSUBSCRIBE <--
Visit this group at http://groups.google.com/group/CLIPSESG?hl=en
Sign in
Click on "Edit my membership" link.
Click the "Unsubscribe" button.
Note: This appears to be the most reliable way to unsubscribe

Alternately, send email to CLIPSESG-u...@googlegroups.com. You will receive an email which you must respond to as well to unsubscribe. Clicking the link mentioned in the unsubscribe reply does not appear to work reliably.

CLIPS Support

unread,
Jan 18, 2012, 4:24:41 PM1/18/12
to CLIPSESG
Issue a (clear) command before you try to reload your rules.

On Jan 18, 3:04 pm, Yunus Emre Durgun <yunusemredur...@gmail.com>
wrote:
> Thank you very much. Actually my all codes are in here and i couldn't work
> it. There is a warning. Can you help me to fix this programme?
>
> *Warning:*
>
> [CSTRCPSR4] Cannot redefine deftemplate attributes while it is in use.
> ERROR:
> (deftemplate MAIN::attributes
> [CSTRCPSR1] WARNING: Redefining defrule: r1 +j+j
> [CSTRCPSR1] WARNING: Redefining defrule: r2 =j+j+j
> [CSTRCPSR1] WARNING: Redefining defrule: r3 =j+j+j
> [CSTRCPSR1] WARNING: Redefining defrule: r4 =j+j+j
> [CSTRCPSR1] WARNING: Redefining defrule: r5 =j+j+j
> FALSE
>
> *Codes:*
> 2012/1/18 CLIPS Support <garydri...@gmail.com>
> > Visit this group athttp://groups.google.com/group/CLIPSESG?hl=en
> > Click on "Edit my membership" link.
> > Select the "No Email" radio button.
> > Click the "Save these settings" button.
>
> > --> IF YOU WANT TO UNSUBSCRIBE <--
> > Visit this group athttp://groups.google.com/group/CLIPSESG?hl=en

Yunus Emre Durgun

unread,
Jan 18, 2012, 5:00:20 PM1/18/12
to clip...@googlegroups.com
I think ı couldn't define my rules. My rules are there and i think, problem is in defining rule. I think i couldn't define rules correctly.

Rules








If outlook = overcast then class=P
If outlook = sunny and humidity=high then class=N
If outlook = sunny and humidity=normal then class=P
If outlook = rain and windy=false then class=N
If outlook = rain and windy=false then class=P


Do you think should i change (assert (response (class "."))) line? My last codes are here:


(deftemplate attributes
       (slot outlook
               (allowed-values sunny overcast rain))
       (slot temperature
               (allowed-values hot mild cool))
       (slot humidity
               (allowed-values high normal))
       (slot windy
               (allowed-values true false)))
(deftemplate response
       (slot class
               (allowed-values P N)))


(defrule  r1
(attributes (outlook overcast))
=>
(assert (response (class P))))

(defrule r2
(attributes (outlook sunny))
(and (attributes (humidity high)))
=>
(assert (response (class N))))

(defrule r3
(attributes (outlook sunny))
(and (attributes (humidity normal)))
=>
(assert (response (class P))))

(defrule r4
(attributes (outlook rain))
(and (attributes (windy true)))
=>
(assert (response (class N))))

(defrule r5
(attributes (outlook rain))
(and (attributes (windy false)))
=>
(assert (response (class P))))



2012/1/18 CLIPS Support <garyd...@gmail.com>

Click on "Edit my membership" link.
Select the "No Email" radio button.
Click the "Save these settings" button.

--> IF YOU WANT TO UNSUBSCRIBE <--
Reply all
Reply to author
Forward
0 new messages