Greetings, GPT3 and CLIPS

88 views
Skip to first unread message

Ged Byrne

unread,
Mar 15, 2023, 12:38:00 PM3/15/23
to CLIPSESG
Greetings ClipsSegers,

I'd like to introduce myself because I'm just starting a masters dissertation that is uses CLIPS to do Graph Processing.   I've worked with Drools before but this is the first time I'm using CLIPS seriously and I'm learning the ropes.

I'd like to have Gary Riley and Ryan Johnston for creating some amazing learning resources.

Another useful resource I've discovered is ChatGPT, which I thought I'd share with the group because I don't know if the chatbot's CLIPs knowledge is common knowledge yet.  

For example, here was a conversation about creating a template for a Vertex:

  • Using CLIPS rule engine create a template to represent a single vertex in a graph model
  • Sure, here's an example template to represent a single vertex in a graph model using CLIPS rule engine: (deftemplate vertex
      (slot name (type SYMBOL))
      (slot value (type INTEGER))
      (multislot edges (type SYMBOL))) Explanation: The deftemplate keyword is used to define a new template named vertex. The vertex template has three slots: name, value, and edges. The name slot is of type SYMBOL, which represents a symbolic value (e.g. a string). The value slot is of type INTEGER, which represents a numerical value. The edges slot is a multislot of type SYMBOL, which can store multiple symbolic values (i.e. the names of other vertices that this vertex is connected to).

For every code sample it gave me, a full explanation was provided. I'll just show the code from now on. Through conversation I was able to edit the slots. Of particular interest is what happened when I renamed a slot to id:
  • Please rename type to id
  • Sure, here's the modified vertex template with the type slot renamed to id: (deftemplate vertex
      (slot id (type SYMBOL))
      (slot value (type INTEGER))) ... Renaming the type slot to id means that each instance of this vertex template will have a unique identifier rather than a type.
This insight into the change's meaning took me by surprise. I decided to test further and asked for a rule that would create any vertexes that were included in an edge definition but missing from the fact base. During this process it started to make small errors, like duplicate names, but fixed the bug as once it was pointed out. I'm skipping over these for brevity. Here is the rule it created:
  • (defrule create-missing-vertex
      ?edge <- (directed-edge (from ?from) (to ?to))
      (or (not (vertex (id ?from)))
          (not (vertex (id ?to))))
      =>
      (if (not (vertex (id ?from)))
          then (assert (vertex (id ?from) (value 0)))
               (printout t "Created new vertex: " ?from crlf))
      (if (not (vertex (id ?to)))
          then (assert (vertex (id ?to) (value 0)))
               (printout t "Created new vertex: " ?to crlf)))
This isn't how I would have done it, so I prompted for a different solution and I was impressed with the result.
  • Could the rule be simplified using unification?
  • Yes, you can simplify the rule using unification to check whether a vertex exists or not. Here's the modified rule: (defrule create-missing-from-vertex
      ?edge <- (directed-edge (from ?from) (to ?to))
      (not (vertex (id ?from)))
      =>
      (assert (vertex (id ?from) (value 0)))
      (printout t "Created new vertex: " ?from crlf))

    (defrule create-missing-to-vertex
      ?edge <- (directed-edge (from ?from) (to ?to))
      (not (vertex (id ?to)))
      =>
      (assert (vertex (id ?to) (value 0)))
      (printout t "Created new vertex: " ?to crlf))
Obviously, the single rule with conditionals was already using unification, but it seemed to understand what I was getting at.

I found this whole interaction fascinating. I'd recommend giving it a try. The question is whether this is something that genuinely help learning and improve productivity.

Regards,

Ged Byrne

Ryan Johnston

unread,
Mar 15, 2023, 11:31:37 PM3/15/23
to CLIPSESG
Thanks for sharing, Ged! Glad you found stuff I wrote helpful. Let us know how your dissertation goes.

Ged Byrne

unread,
Mar 16, 2023, 4:57:48 AM3/16/23
to clip...@googlegroups.com
Hi Ryan,

One thing I would like to do is create a browser based sandbox like your Tour of Go.  

I hope you don’t mind me asking a few questions. 

Did you compile CLIPS to WASM yourself?   

Are there any technical or license issues that would prevent me from reusing your library?

Do you know if it is possible to have CLIPS callback to a javascript function on the RHS of a rule?

Regards,


Ged



--
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.
---
You received this message because you are subscribed to a topic in the Google Groups "CLIPSESG" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clipsesg/H-J1l-d7IE8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clipsesg+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clipsesg/6a80d4d6-c5c6-41f9-9fbb-19886a3fbee1n%40googlegroups.com.

Ryan Johnston

unread,
Mar 27, 2023, 10:27:00 PM3/27/23
to CLIPSESG
Did you compile CLIPS to WASM yourself?

Yes I did. I used Emscripten and used emcc & emar in the makefile shipped with clips source code. Here's the diff:

69c69
< release : CC = emcc
---
> release : CC = gcc
94c94
<       $(CC) -o clips main.o -L. -lclips -sEXPORTED_FUNCTIONS=_CreateEnvironment,_BatchStar,_Clear,_Reset $(LDLIBS)
---
>       $(CC) -o clips main.o -L. -lclips $(LDLIBS)
98c98
<       emar cq $@ $(OBJS)  
---
>       ar cq $@ $(OBJS)


Are there any technical or license issues that would prevent me from reusing your library?

I don't believe so. Take a look at the readme.txt file in the root of the clips source code for licensing info for CLIPS. Here's the licensing info for emscripten: https://emscripten.org/docs/introducing_emscripten/emscripten_license.html.

Do you know if it is possible to have CLIPS callback to a javascript function on the RHS of a rule?

This is possible. Take a look at this page in the Emscripten docs: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html. You'll also want to read the Advanced Programming Guide for CLIPS: https://clipsrules.net/documentation/v640/apg640.pdf

Ryan Johnston

unread,
Mar 27, 2023, 10:36:12 PM3/27/23
to CLIPSESG
I've posted a (corrected) patch file as a gist:

Compiling CLIPS to WASM

I included instructions for downloading the files and compiling there. Enjoy!

Ryan Johnston

unread,
Mar 27, 2023, 10:46:09 PM3/27/23
to CLIPSESG
Also, one tiny plug for my first attempt at compiling CLIPS to WASM: https://clips.run/

I wouldn't necessarily use the method I used to compile CLIPS to WASM for https://clips.run, but I keep it around for historical/sentimental reasons.

Ged Byrne

unread,
Mar 29, 2023, 12:15:06 PM3/29/23
to clip...@googlegroups.com
Thanks, this is very helpful.

Reply all
Reply to author
Forward
0 new messages