Title: Adventures in Rule-Based Programming – A CLIPS Tutorial
Author: Gary Riley
Publisher: Secret Society Software, LLC
Year: 2022
In an earlier article, I had talked about the relevance of Rule-based systems today. In that article I had also listed a few Rule engines that are popular and widely used. One of them is CLIPS, an OPS5 inspired rule engine written in C language.
Gary Riley, the author of the book, was part of the team at NASA that originally created CLIPS in the 1980s. After leaving NASA in 1996, he continues to independently support the software in its current public domain form.
The present book is an excellent addition to the official documentation: User Guide, Basic Programming Guide, Advanced Programming Guide, and Interfaces Guide. With such good documentation already available, what is the need for a book like this? If you are new to CLIPS or would just like to know what you can do with a Rule engine, then this book is a great place to start your journey. You might also want to take a look at another book [1] that he co-authored many years ago on Expert Systems.
This book teaches CLIPS using the example of an interactive Text Adventure (also called Interactive Fiction) game. This is a well-chosen and somewhat off-beat example in my opinion that makes the book even more interesting.
Chapter 1 lays the foundation by introducing Rule-based programming. Then it talks about Text Adventure games and some tools available for building them. The chapter concludes by showing how to install CLIPS environment and how to interact with the CLIPS shell.
Chapter 2 explains the concrete syntax of Rules, Patterns, Constraints, and Fact templates in CLIPS. It also shows how the “agenda” keeps track of rule activations. Chapter 3 extends this further by discussing how to organize the rules in the file system and how to load them. The “Batch” and a few other commands are introduced in this context. The significance of the “Salience” property of rules is also touched upon. The Text Adventure example is developed gradually, incorporating the CLIPS features discussed in the chapter.
Chapters 4 and 5 discuss more advanced features of rules such as complex constraints involving predicates and patterns. When many rules have a similar structure, the author shows how such rules can be generalized to reduce the number of rules. This is somewhat similar to the “generic” functions in traditional programming languages.
Chapter 6 is devoted to a detailed exposition of “Facts”. Various operations and queries on the facts database are demonstrated in the context of the game being developed. The “find-all-facts” function, for example, retrieves all facts in the database that match the given pattern. Its counterpart, the “do-for-all-facts” function, can be used to apply a sequence of operations on a collection of facts that match a pattern.
Chapter 7 covers “Modules”, a useful feature for organizing rules in the knowledge base. In a medium to large project, it is common (in fact, necessary) to define several modules and keep logically related rules in the same package. This minimizes the need for unnecessarily associating “salience” with possibly conflicting rules, and it additionally allows CLIPS engine to use stack-based “agenda” for deciding what rule to fire next. To put this idea into practice, the author shows how it is possible to group the rules corresponding to the Text Adventures game into different modules.
Chapter 8, the last chapter in the book, describes some finer and practical aspects of developing applications with CLIPS. How to save session data and restore the state at a later point in time is one of the topics explained here. This is particularly relevant in the context of the game covered in the book. Developing a CLIPS project, like any other non-trivial application in other languages, tends to be iterative, where features are added and then tested. The “batch” command is a convenient way to automatically execute a series of commands in the context of regression testing. Once the functionality is completed and rules have been fully tested, it is quite likely that this “reasoning engine” will be embedded as part of a larger application (I have used CLIPS in embedded mode in one of my applications). Chapter 8 covers these three areas in sufficient detail.
By the time you complete the book, you will have a good working knowledge of CLIPS and will be ready to use it in your own project. Of course, you may need to consult the official documentation for other finer details in case you get stuck at some point.
I congratulate the author for coming out with such an eminently readable book on CLIPS!
Have a great day!
References
1) Expert Systems: Principles and Programming, Joseph C. Giarratano and Gary D. Riley, 4th Edition, 2005, Thomson Course Tehnology.
Recent Comments