Вы находитесь на странице: 1из 674

EXSYS

Expert System Development Software

Professional for Windowed Environments

MANUAL

Copyright EXSYS Inc. 1983-1996 All rights reserved. All product names are trademarks of their respective manufacturers.

Table of Contents
A A1: A2: A3: A4: A5: Introduction System Requirements 5 Runtime License 6 Installing EXSYS Professional 7 Technical Support 9 Compatibility Between GUI EXSYS and Non-GUI EXSYS 10 A6: Working in Multi-user Environments 11 A7: Features in EXSYS Professional 13 A8: EXSYS Professional Files 15 B B1: B2: B3: B4: B5: B6: B7: B8: C Developing Expert System Knowledge Bases What Can an Expert System Do? 1 How to Select an Appropriate Problem 2 Building an Expert System 5 Backward Chaining 14 Using Confidence Modes 19 Using the Command Language 22 Using the Report Generator 23 Creating Your First Expert System 24 EXSYS Rule Editor

C1: Starting the Rule Editor 2 C2: Opening an Existing Knowledge Base 3 C3: Starting a New Knowledge Base 4 Subject 4 Author 4 Confidence Mode 5 Calculation Mode 9 Threshold Level For Display of Results 10 Derivation Mode 11 Rule Display Mode 13 Starting Text 14 Ending Text 14 Starting External Program 15 Initial Choice Value 15 Finished Setting Parameters 16 Entering Choices 16
Table of Contents

C4: Main System Title Screen 17 C5: Saving the Changes to a Knowledge Base 18 C6: Exiting the Editor 20 C7: System Help 21 C8: Copying Text from Other Applications 24 C9: Adding a New Rule to the Knowledge Base 25 C10: Editing a Rule in the Knowledge Base 26 C11: Building a Rule 28 Positioning of New Conditions 28 Adding a Qualifier Condition 29 Adding / Editing a Qualifier 31 Editing an Existing Qualifier Value 32 Deleting an Existing Qualifier Value 33 Options for Each Qualifier 33 Qualifier Name 33 Display of Qualifier Values with Results 34 Maximum Number of Values 34 Default Value 34 Automatic Data Acquisition 36 Custom Formula Systems 36 Finished Setting Qualifier Parameters and Values 36 C12: Selecting Qualifier Values to Build a Condition 37 Adding a New Value 39 Correcting Typographical Errors 39 Qualifier Conditions Combined with OR 39 C13: To Change the AND / OR Blocks 42 C14: Using Qualifiers 43 C15: Mathematical Expressions and Variables 45 Variables 45 Math Expressions in the IF Part 45 Math Expressions in the THEN/ELSE Part 46 Building Math Conditions in a Rule 46 THEN / ELSE Part 47 Variable Parameters 48 Entering the Expression to Assign 53 Expressions 54 Arithmetic Operators 54 Boolean Operators 54 ANSI Standard Order of Priority 56 Conditional Tests 57
Table of Contents

C16:

C17: C18: C19: C20: C21: C22:

C23: C24: C25: C26: C27: C28: C29: C30: C31: C32:

Approximately Equal Operator 57 Syntax Checking 57 Conditional Operator 58 Functions 59 Special Functions 61 AGE Function 64 Adding a Choice Condition 65 Choices in the THEN/ELSE Part 65 Choices in the IF Part 66 Adding a New Choice 67 Deleting a Choice 68 Editing a Choice 68 Adding a Command Condition 69 To Copy or Move a Condition 70 To Delete a Condition 72 To Change a Condition 72 To Scroll to the Previous or Next Rule 72 To Add / Edit the Note, Reference and Name 72 Note 72 Reference 73 Name 73 To Repeat a Condition from the Previous Rule 75 Consistency Checking of New Rules 76 Deleting a Rule 79 Moving a Block of Rules 80 Printing a Knowledge Base 82 Displaying the Qualifiers, Variables or Choices 84 Running the Rules 85 Canceling a Run 86 Changing the Knowledge Base Parameters 87 Automatic Validation / Tree Diagrams 88 Introduction 88 Running in Validation Mode 90 Setting the Test Parameters 91 Validation Results 95 Custom Reports 97 Validation Testing to Compare Versions of a Knowledge Base 98 External Program Problems 99 100
Table of Contents

C33: Examining Existing Tree Diagram Files

C34: C35: C36: C37: C38: C39: C40:

Notebook 101 Asking for Help 102 Editing the Knowledge Base Text Files 103 The Questions Menu 104 Trace the History of the Run 105 Hypertext 107 Custom Formula Confidence 108 Using Custom Formulas Confidence System 108 Confidence Variables 109 Assigning a Confidence Formula 111 User-Supplied Confidence Ratings 112 C41: Custom Help Screens 114 C42: Loop Error Messages 115 D D1: D2: D3: D4: D5: D6: D7: D8: EXSYS Runtime

Starting the RUNTIME 1 Opening an Existing Knowledge Base 2 System Help 3 Notebook 6 Display of Rules During Runtime 7 Title Screen 8 Starting Text 9 User Interaction 10 Asking for a Qualifier Value 10 Asking for a Variable Value 12 D9: External Program Input 13 D10: Custom Screens 13 D11: Asking Why a Question is Being Asked 14 D12: Asking for More Information on a Question 16 D13: UNDO a Previous Answer 17 D14: Save Input 18 D15: Recover Input 19 D16: Displaying the Known Data 20 D17: Displaying the Status of the Choices 21 D18: Displaying a Rule 23 D19: Ending Text 26 D20: Displaying Results 27 Confidence Modes 27 D21: Change and Rerun 30

Table of Contents

D22: Custom Results Screens 31 D23: Existing the Runtime 32 E Configure Options E1: Editor/Runtime Configure Files 1 E2: Knowledge Base Configure Files 2 E3: Creating Configure Files 3 Change Connector Words 4 Asks for Specified Data at the Start of a Run 5 Calling an External Program After Change and Rerun Commands 6 Change the Name of the Configure File Used 7 Allow Data from External Programs to be Modified During Change and Rerun 8 Change the Name of the Command File Executed 9 Control of Runtime Menu Options 10 Automatically Reads a Series of Records of Data and Executes the Rules 11 Change the Standard Ending Message if No Choices are Set 13 External Program Flag File Control 14 Add Extra Space When Printing Rules 14 Stops Execution When Any Choice Has a Final Value Set Greater Than 0 15 Forward Chaining Options 16 Sets an Alternate Knowledge Base Help File 22 Limits Options Available to User of Runtime 23 Turns Off Loop Error Checking 24 Displays Choices Without Sorting by Value 24 Switch Off Color Display 25 Prevents Deletion of RETURN.DAT After Reading 25 Prevents Display of Results at Any Time 26 Disables Option to Use Passwords 26 Eliminates Starting Questions 27 Do Not Display Title and Author 27 Prevents Display of Values Assigned to Choices 28 Prevents Backward Chaining on Simple Expressions 29 Allows Choices with No Value Set to Test False 30 Changes the Name of the File Used to Pass Data to External Programs 31
Table of Contents

Load Password from Command Line or .CFG File 32 Reads Custom Help File When Rules are Read 33 Recovers Data Saved Previously with QUIT 34 Turns Off DISPLAY Command During "Change and Rerun" 35 Releases Memory Used for String Variables 36 Changes the Name of the Report Specification To Be Used 37 Turns Off Report Generator During "Change and Rerun" 38 Changes the Default to Rerun Rules at End 39 Changes the Name of File Used to Return Data from External Programs 40 Changes How Rounding is Handled in Calculations 41 Writes a File of Information on Rule Execution, Data and Other Functions 42 Sets the Number of Times UNDO Can be Called 43 Sets WORKING Screen Color 44 Sets Printer Width 45 F Report Generator F1: Commands 1 Make a Beep Noise 2 Print Data on Choices 3 Examples 5 Close a File for Display 7 Display a File in a Window 8 Exit to the Operating System 10 Select the Output File 11 Print Text Only for First Set of Data in DATALIST 13 Unconditional and Conditional Branches 14 Print the Data Input by the User 16 Print the Notes and References 17 Data on Qualifiers 18 Examples 21 Restart the System 22 Call an External Program 23 Save the Input Data for a RECOVER 24 Print Text String 25
Table of Contents

Print Data on Variables 26 Options 28 Examples 30 G Internal Commands and Data Acquisition

G1: Internal Commands in a Rule 1 G2: Commands Used for Data Acquisition 2 G3: Internal Command Window 4 Direct Command Input 4 Blackboard Interface 5 dBase III Interface 6 Clear Out Known Data or Rules 13 Read a File of Data 17 Display a File in a Window 19 Frame Interface 23 LINDO Linear Programming Interface Lotus 123 Interface Commands 24 Run a Report Specification File 29 Run an External Program 31 Stop Program Execution 32 Table Interface 33 H H1: H2: H3: H4: H5: H6: External Program Calls

23

Syntax 2 RUN Command Window 7 Microsoft Windows Program Calls 8 Macintosh Program Calls 10 UNIX and VMS Program Calls 11 Returning Data to EXSYS 11 RAM Disks 14 Erasing RETURN.DAT 14 Passing Back a Command from an External Program 15 Returning Hypertext Words from External Programs 15 H7: Calling Programs from THEN/ELSE 16 H8: Calling Programs from the Report Generator, Command File or Custom Screen File 18 H9: Calling an External Program at the Start of a Run H10: Calling External Programs from Variables 20 H11: Calling External Programs from Qualifiers 22
Table of Contents

19

H12: Problems Calling External Programs 24 H13: Calling External Programs - Summary 26 H14: DATALIST: Analyzing a Multiple Record Data Report 28 H15: DATAREAD: Reading a File of Data 30 I Customizing the User Interface

I1: GUI Custom Screen Definition Language 2 I2: Screen Files 3 I3: Screen File Structure 4 Indicating the Qualifier or Variable 4 Hypertext Keywords 5 Custom Screens for Confidence Variables 5 I4: Returned Data 5 Returning Commands 6 Passing Back a Hypertext Call 7 I5: Syntax for a RCT 7 I6: Setting the Window Size 8 I7: Embedded Variables 8 I8: GUI Custom Screen Commands 9 I9: Custom Screen Examples 24 I10: EXSYS_CS Custom Screen Preview 35 I11: Custom Screens to Ask Questions 36 I12: Context Sensitive Help Files 38 I13: Hypertext 39 Defining Screens 40 Flagging Keywords 40 Using Keywords 41 The .HYT File 41 Example: 42 I14: Inserting Value Text in the Middle of Qualifiers I15: ASCII Codes 44 I16: Embedding Data in Text 45 Variables 45 Formulas 46 Qualifiers 46 Embedding Qualifier Values 47 Embedding Expressions 48 Recursive Brackets 48 [[ ]] Replacement in the Report Generator and Command File 49
Table of Contents

43

Command Language

J1: Changing the Name of the Command File 2 J2: Expressions and Variables 2 Request User Input for a Specific Item 3 Make a Beep Noise to Alert User 4 Branch Point Label 5 Cause a "Change and Rerun" Option 6 Allow Command Files to be Commented 7 Erase Data or Reset Rules to Unused 8 Call Another Command File 10 Cause the Next Record of Data to be Read from a DATALIST File 11 dBase III Interface Commands 12 Display the Contents of a File 15 Exit a Command File Called by Another Command File 17 Exit to the Operating System 18 Unconditional Branch 19 Allow Conditional Execution of Blocks of Rules 22 Pause Until a Key is Pressed 24 Recover Data saved with a QUIT or SAVEDATA Command 25 Run a Report Generator Specification 26 Display the Results of the Run 27 Run the Rules or a Subset of the Rules 28 Run an External Program 31 Save the Current System Data 32 Assign a Value to a Variable, Qualifier or Choice 33 Execute a Block of rules While a Condition is True 35 K K1: K2: K3: K4: K5: Rule Compiler Getting Started 2 Starting the Rule Compiler 4 Editing the Text Files 5 Producing Files That Can Be Compiled 5 Commands 7 Allow Comments to be Added to a File 9 Define the Subject of the Expert System 10 Define the Author of the Expert System 11
Table of Contents

Define the Starting Text of the System 12 Define the Ending Text of the System 13 Define an External Program to Call at the Start of a Run 14 Set the Threshold for Choice Display 15 Define the Confidence System to be Used 16 Set the Initial Choice Confidence Value 18 Set Option to Display Rules as a System Runs 19 Set Option for How Many Rules to Use in Deriving Information 20 Define List of Qualifiers and Parameters 21 New Qualifiers or Values Found in the Rules 26 Define List of Variables and Parameters 27 Text Only Variables Found in the Rules 31 Define List of Choices 32 Use Only Defined Qualifiers, Variables and Choices 33 Define a Rule 34 Qualifier Conditions in Rules 36 Choice Conditions in Rules 38 Formula Conditions in Rules 40 Text Conditions in Rules 42 NOTE and REFERENCE Text 44 Special Cases 45 Set Space Allocated for Compile 47 K6: Error Messages 48 L Frame and Table Interface

L1: TABLE and NTABLE 1 Data Table Syntax 1 L2: Frame 3 What is a Frame 3 Specifying a Slot 4 Specifying the Frame Row 6 How to Create a Frame 7 Inheritance 8 L3: Reading from a Frame 11 L4: Writing to a Frame 12 L5: Examples 13 L6: Including FRAME and TABLE in Your Expert System 14
Table of Contents

Blackboard Manager

M1: Introduction 1 Recommended Uses for EXSYSBB 1 EXSYSBB Blackboards 1 Communication Between EXSYSBB and Your Applications 2 M2: Calling EXSYSBB 2 3 M3: Including EXSYSBB in Your Expert System Associated with a Qualifier or Variable 3 Run as the Result of a Rule Firing 4 From the Command Language 4 From the Report Generator 4 From the Screen Definition Language 4 Called from the Operating System 4 Called from Other Programs 4 M4: Blackboard Command Window 5 M5: Reading From a Blackboard 6 M6: Writing to a Blackboard 7 M7: Deleting Data From a Blackboard 8 M8: Attributes and Values 9 M9: Parameters 11 M10: External Call Values (demons): 17 M11: Operating Modes 18 M12: Error Messages 19 M13: Common Errors 20 N LINDO Interface N1: Introduction 1 N2: Calling the LINDO Specification File 2 LINDO Specification File 3 N3: Model Commands 5 N4: ~IF test expression, ~ELSE, ~ENDIF 6 N5: ~Results 7 N6: Return Data Commands 7 LINDO Data ID 7 N7: Sample EXSYS / LINDO Interface 12

Table of Contents

O O1: O2: O3: O4: O5: O6: O7:

Utility Programs Compressing Edited Files 1 Rule Organizer 2 Moving Files Between Operating Systems Pager 4 EX_TIME 7 Repeat 10 EXSQ - Report File Squeezer 11

P SQL Commands Introduction 1 P1: Installation 1 DLL Notes 2 INTERSOLV 2 SQL Interface Technical Support 3 Backward Compatibility 3 P2: SQL Commands 4 Reading a Single Item of Data into a Single EXSYS Variable 4 SQL Commands that Return Multiple Items of Data 5 P3: Connecting to the Database 6 Connection Strings 7 P4: Executing an SQL Command 8 Selecting the Next Record of Returned Data 8 Selecting the Previous Record of Returned Data 9 Selecting a Random Record of Returned Data 10 Finding the Number of Records of Returned Data 10 Creating Random Access Buffers for Returned Data 11 Releasing the Data Returned from an SQL Command 11 Disconnecting from a Database 12 Reading a Specific Field of Returned Data 12 Reading the Name of a Column of Returned Data 13 Reading the Number of Columns of Returned Data 13 P5: Transactions 14 Beginning a Transaction 14 Committing a Transaction 14 Canceling a Transaction 15 P6: Using SQL Commands 15 Some Basic SQL Commands 16
Table of Contents

ExDesign Custom Screen Design Program

Q1: Introduction 1 Q2: Master System Help 1 Q3: File Menu 1 New 2 Open 3 Save 4 SaveAs 5 Print 5 Exit 5 About 5 Adding a New Screen 5 Q4: Object Menu 6 Return Strings 7 Rectangles 9 Push Button 9 Radio Button 11 Check Box 12 Slide Bar 13 Edit Box 15 Line 18 Arrow 19 Oval 20 Rectangle 20 Rounded Rectangle 21 Text 21 Mouse Box 22 PCX 24 Meters 25 List Boxes, Buttons and Edits Q5: Aligning Objects 31 Q6: Selecting Multiple Objects 32 R Fuzzy Logic

27

R1: Introduction 1 How Fuzzy Logic Is Implemented in EXSYS Professional 3 Defuzzification 6 Advantage of Fuzzy Sets 7 IF / THEN Only 8
Table of Contents

R2: Building Fuzzy Systems - The Mechanics 8 Starting a System 8 Fuzzifying a Qualifier 9 Choices in a Fuzzy System 15 R3: Defuzzifying a Variable 18 Validation and Defuzzified Variables 20 R4: Building Fuzzy Systems - Techniques and Demos 21 When 21 How 22 Demos 25 R5: Graphing Validation Data 26 Setting Constraints 27 Display Variables 29 Examining Values on the Graph 29 Constraints on the Validation Graph 30 R6: Combination of Confidence 30 IF PART 30 Qualifier Conditions 31 Variable Conditions 33 Choice Conditions 34 Overall IF Confidence 34 If Conditions Summary 36 Rule Confidence Threshold 36 THEN PART 37 Choices (THEN Part) 37 Qualifiers (THEN Part) 39 Variables (THEN Part) 39 Changing the Way Confidence is Combined 40 S Screen Templates

Introduction 1 S1: Using Templates 2 S2: To Add Templates to Your System 2 S3: Previewing Your Screens 3 S4: Template Designs 3 Template Styles: 4 - 14 S5: Modifying / Creating Your Own Templates S6: Editing an Existing Template 19 S7: Handling Individual Screens 19
Table of Contents

15

Chapter A

Introduction
At EXSYS Inc., we believe that expert systems will be widely implemented only if the systems are easy to build. Having the experts build the systems themselves can produce large numbers of systems rapidly. The widespread use of smaller expert systems is often far more effective than one large expert system. This approach requires that the tools to build the system be easy to use. It is not reasonable to ask experts to spend 6 months learning how to use an expert system tool, but it is reasonable to ask them to spend a few days. To be implemented effectively, an expert system shell must not be significantly more difficult to use than a word processor. It is reasonable to ask experts to build their own expert systems, only if the shell is easy to use. We believe that this is the future of expert systems. The goal at EXSYS is to provide easy-to-use tools so that people can build their own expert systems. Both developers and users of expert systems have become more sophisticated. End users now request more from an expert system than a few years ago. A few years ago, simple systems were considered major accomplishments. Now users expect more power and flexibility in an expert system and developers of such systems require the tools to build them. In order to meet this goal, EXSYS Professional was created. EXSYS Professional offers a new level of sophistication to knowledge engineers developing expert systems, while retaining the easy-to-use EXSYS interface that has proven so successful. EXSYS Professional provides many commands to modify the default operation of the shell. If these new capabilities are not used, EXSYS Professional automatically uses safe defaults. EXSYS Professional is a generalized expert system development package. An Expert system is a type of artificial intelligence program that emulates the interaction a user might have with a human expert to solve a problem. The user answers by selecting one or more answers from a list or by entering data. The computer will continue to ask questions until it has reached a conclusion. The conclusion may be the selection of a single solution or a list of possible solutions arranged in order of likelihood. The computer can explain, in English, how it arrived at its conclusion and why.

A - INTRODUCTION

Expert systems can be developed with EXSYS for any problem that involves a selection from among a definable group of choices where the decision is based on logical rules. The rules can involve relative probabilities of a choice being correct. Any area where a person or group has special expertise needed by others is a possible area for EXSYS. Expert systems can help automate anything from automating complex regulations to aiding customers in selecting from among a group of products, from automated user assistance to identification of diseases or problems with a piece of equipment is possible. Expert systems deal with knowledge rather than data and the files they use are often referred to as knowledge bases. The rules that the program uses are IF-THEN-ELSE type rules. A rule is made up of a list of IF conditions (normal English sentences or algebraic expressions) and lists of THEN and ELSE conditions (more sentences) or statements about the probability of a particular choice being the appropriate solution to the problem. If the computer determines that all IF conditions in a rule are true it adds the rule's THEN conditions to what it knows to be true. If any of the IF conditions are false, the ELSE conditions are added to what is known. The computer determines what additional information it needs and how best to get the information. If possible, the program will derive information from other rules rather than asking the user. This ability to derive information allows the program to combine many small pieces of knowledge to arrive at logical conclusions about complex problems. The rule editor allows the rules to be easily modified, added or deleted. The final goal of an expert system is to select the most appropriate solution to a problem based on the data input by the user. If more than one solution is possible the program will provide a list of the possible solutions arranged in order of probability. Essentially all of the instruction necessary to run an expert system knowledge base is provided by the program and all output is in English. Little or no training is required to run an already developed knowledge base. The principal development tool in EXSYS Professional is the EXSYS Professional Rule Editor. It enables you to rapidly generate your own expert system knowledge bases. All options available to you are displayed on the screen. The "Learning to Use EXSYS Professional" videotape takes you step-by-step through a series of lessons on the generation of your own expert system knowledge bases. When running the rule editor, help screens are available for more detailed information on command options. All input is in the form of normal English text or algebraic expression. Since most of the input to the program comes from items selected from a list, virtually all of the typo problems that can confuse some expert system development programs are effectively eliminated. New rules entered are checked
A - INTRODUCTION
2

against the existing rules for consistency. The final decision on whether or not a rule should be included is left up to you. You have various options for assigning and combining probability values. EXSYS Professional also includes a rule compiler that allows you to create or edit rules with a word processor and then compile the rules for use with the EXSYS Professional Runtime or Editor. In general, we believe that it is better to use the EXSYS Professional Rule Editor, rather than a text editor, to create and edit rules. The Rule Editor is faster, easier and provides error checking. However, there are times when having the ability to edit the rules directly can be very powerful. Also, the rule compiler allows other programs to generate EXSYS rules which can be compiled into the EXSYS Professional form. It is even possible to have expert systems that create their own new rules which can be added to make the systems more capable. We feel that EXSYS Professional offers the correct balance of power with ease-of-use. Very complex expert system problems can be handled in EXSYS Professional, but a new user will still be able to learn to create systems in a few days. Also, EXSYS Professional will continue to grow. As users continue to suggest new features, they will be added to the program to make it even more capable. EXSYS Professional is easy to use, no special languages are needed and all input is in the form of either English text, algebraic expression or menu selection. The developer of an expert system works within the EXSYS Professional Rule Editor, which provides menus, prompts and help. It is not necessary to memorize complex rule syntax. EXSYS Professional also includes a rule compiler that allows development or editing of knowledge bases with a word processor. For more complex applications and increased control, there is a command language that can be used to control the execution of the expert system. The command language gives the developer greater control and flexibility in developing rule based systems. Rule subsets, looping and conditional tests are part of the command language. EXSYS Professional expert systems can be run by an end user with essentially no training. The end user of the expert system can ask HOW conclusions were reached or WHY information is needed. The program will respond with a full explanation of the logic used to arrive at the conclusion, including backward chaining and external program calls for data. The developer can customize screens and decide what options are available to the end user. For particularly large or complex problems, blackboarding can be utilized to divide a problem into smaller expert systems that communicate through a common data file (a "blackboard").

A - INTRODUCTION

The EXSYS editor, runtime and utility programs are written in C for high speed and efficient utilization of memory. Expert systems developed with EXSYS Professional function the same way on Microsoft Windows, VAX/VMS Motif, Macintosh Sun Open Look and OS/2 Presentation Manager computers. The EXSYS application need only be moved to the new environment and run with the appropriate runtime program. EXSYS versions are also available in Japanese (with kanji support for Kanji MS-DOS and Kanji Unix computers) and Spanish.

A - INTRODUCTION

A1: System Requirements


IBM PC or compatible 2 Meg RAM Hard disk VGA Monitor Microsoft Windows

Macintosh All Macintosh computers are supported except the Classic. EXSYS will run on the Classic, but some buttons will be off the screen. 4 Meg RAM Hard disk System 6 or System 7

DEC VAX/VMS EXSYS runs on all DEC VAX computers running VMS Motif. EXSYS is a small program for the VAX and runs in all configurations. UNIX EXSYS runs on many UNIX computers. EXSYS is a small program for all but the smallest UNIX computers and should run in all configurations.

A - INTRODUCTION

A2: Runtime License


The EXSYS software is not "copy protected." Copy protection makes a program more difficult to use and adds to the cost of the software. The intention throughout the development of EXSYS Professional has been to make it easy and user friendly and to bring you a quality, supported software package. We feel that copy protection runs contrary to these goals. The Runtime program supplied in with the development environment is for development only. It will display a message at the start of each session reminding you of this. A copy of the runtime that does not display this message is provided when you purchase a Runtime License. A Runtime license is required to distribute copies of the EXSYS Professional Runtime program. There are two separate license categories: commercial and non-commercial. The non-commercial Runtime license entitles the developer to distribute applications to an unlimited number of users on a non-commercial basis--that is, as long as the application is not sold by itself or as part of a package that is sold. The applications can be given away, distributed to coworkers, or in other ways distributed in a non-profit manner. The commercial license is intended for those individuals planning to market their applications. We believe that if an application is marketed, part of its capability and sales value comes from the EXSYS software and that EXSYS should receive a small payment per copy of the program marketed. Consequently we have instituted the Commercial Runtime License. Contact EXSYS Inc. for information on Commercial Runtime Licenses Note: Please remember, even if you have a Runtime license, the license agreement prohibits sub-licensing. That is, you can not give a copy of the Runtime to someone else and have them distribute it to others. All distribution must be from a license holder. If person A has a runtime license and creates an application which he or she gives to person B, person B cannot make additional copies, unless they obtain their own Runtime license. Runtime licenses are also available for versions of EXSYS Professional running on other operating systems.

A - INTRODUCTION

A3: Installing EXSYS Professional


MS Windows OS/2 (Presentation Manager)
Exit Windows (or Presentation Manager) and return to the DOS level. Select the drive to install to by entering the drive letter, for example: C: Create a new directory called EXSYSP on your hard disk with the DOS command MD \EXSYSP Make this new directory the default directory by entering CD \EXSYSP Copy the contents of all of the disks to the new directory by putting the distribution floppy disk in drive A and entering COPY A:*.* C:\EXSYSP /V

Once EXSYS Professional is installed on the hard disk, store the distribution disk in a safe place.

Macintosh
Create a new folder called EXSYS on your hard disk by selecting New Folder. Insert the distribution disks and copy all files and programs in the disk into the EXSYS folder. Once EXSYS Professional is installed on the hard disk, store the distribution disk in a safe place.

A - INTRODUCTION

DEC VAX/VMS Computers


The program is supplied on one TK-50 tape. Create a directory named [EXSYS]. Copy the contents of the tape into [EXSYS]. The tape is a save_set labeled EXSYS. All parameters such as block size, etc. are default VMS settings. When a new program is added to VAX/VMS, you must install the new command or use the RUN command. The RUN command is used by entering: RUN EXSYSP If RUN is used, you cannot pass argument vectors to the program. To install a new command, you must enter the following at the VMS $ prompt. EXSYSP := $[directory]EXSYSP.EXE EDITXSP := $[directory]EDITXSP.EXE This will allow you to call EXSYSP or EDITXSP without using RUN and will allow you to pass in a knowledge base name or use command line options. For example, you can enter EXSYSP PCDEMO.

UNIXComputers
The UNIX version of EXSYS Professional is distributed on a "tar" tape for the specific target computer. The instructions on the device driver to use are provided with the tape.

A - INTRODUCTION

A4: Technical Support


If you encounter problems using EXSYS 1. Run the expert system TECHHELP to see if it can solve your problem. To run this system, enter click on the EXSYSP icon to start the runtime program. Select Open from the main menu and select TECHELP.RUL in the EXSYSP directory. 2. Re-read the manual section related to the problem. 3. If you are still having problems, give us a call at (505) 256-8356 from 9:00-5:00 PM Mountain time Monday to Friday or Email: tnexsys@pop,nm.org. After hours you can leave a message on an answering machine and we'll call you back. If you are calling for technical support, please have your registration number and version number handy. Please have a detailed description of the problem, what the program did or did not do, what other operations were being done, etc. There is an enormous number of command combinations possible in EXSYS Professional. If you are having a problem, it may be due to a combination of commands. In some cases it will not be possible for us to fully understand what the problem is or be able to correct it without seeing the actual rules being run. If we can not reproduce the problem, we may ask that you send us a copy of your rules or a sample system that shows the problem.

A - INTRODUCTION

A5: Compatibility Between GUI EXSYS and Non-GUI EXSYS


The GUI versions (MS Windows, Macintosh, VMS Motif, Sun Open Look and Presentation Manager) of EXSYS Professional can read files created with the non-GUI versions of EXSYS without modification. All files will be identical, except: 1. The GUI custom screen language is different from the Non-GUI custom screen language. 2. The command language commands for positioning the cursor and writing to the screen are not supported. 3. Certain configuration options which have no meaning in a GUI environment are not supported. With the exception of three items above, an expert system developed with the Non-GUI version of EXSYS should run in the GUI versions without modification.

A - INTRODUCTION

10

A6: Working in Multi-user Environments

When EXSYS Professional is used in a multi-user environment, some special precautions have to be taken to prevent inadvertent clashes between users. For example, if two users are accessing the same expert system which calls an external program, their RETURN.DAT files could overwrite each other. Likewise, reports and other output could be confused. To avoid this, EXSYS Professional checks the environment variable EXSYS to see if it exists and has a path associated with it. If the environment variable EXSYS has a path associated with it, all user specific files will be written to or read from files preceded by that path. This is similar to using the HOME path in UNIX. It is possible to override the addition of the path when necessary. If the specification for a read or write in the rules starts with \ in DOS or OS/2 / in UNIX [ in VMS the path from the EXSYS environment variable will NOT be used. The path associated with the environment variable must end in a way that a file name can be appended to it to make a legal path. For example, suppose in UNIX the environment variable EXSYS is \RULES\MY_DATA\ The report command: FILE ABCD would actually open a file: \RULES\MY_DATA\ABCD However, the command FILE \OTHER\ABCD would not have the path added and would open \OTHER\ABCD Likewise, a run command would look for the RETURN.DAT file in \RULES\MY_DATA\RETURN.DAT The addition of the path applies to all files created or read that are unique to a particular user: DATALIST, RETURN.DAT, PASS.DAT, and report output files. The path is not applied to files used by the system: .RUL, .TXT, .OUT, .CMD, .HLP, .SCR, .CFG files or external program calls.

A - INTRODUCTION

11

The use of the environment variable EXSYS makes the path data available to called external programs. If this approach is being used, make sure the called external program also reads the environment variable and writes the RETURN.DAT file to the correct location. Note: See your operating system manual for information on setting environment variables. Environment variables are not supported on the Macintosh. You should also store the EXSYS Professional .HLP files in a single directory accessible by all users. Normally the .HLP files are looked for in the current directory. Adding the command line or .CFG option EXSYS_HELP=<path> causes EXSYS Professional to look on this path for the help files needed. This command would normally be put in the files EXSYSP.CFG and EDITXSP.CFG configure file.

A - INTRODUCTION

12

A7: Features in EXSYS Professional


Inference Engine:
IF/THEN/ELSE Production Rules AND / OR Conditions Up to 128 Conditions in IF/THEN/ELSE Up to 64 OR Groups in a Rule Minimum Questions to User Backward/Forward Chaining (w. Subsets) Procedural Command Language Rule Sub-sets Rule Names Automatic Chaining on Variables Sub-goal Confidence Five Confidence Systems Blackboarding Dynamic Agenda Manager Batch Mode Processing Change and Rerun Clear (Forget) Data UNDO Previous Input (10 levels) Complex Boolean Expressions Advanced Math Functions Array Functions Table Look-up Frame Data with Inheritance

Developer Environment:
Rule Editor with Context Knowledge Rule Compiler (Text Editor Files) Procedural Command Language Incremental Compile Run or Edit with Single Keystroke Automatic Consistency Checking Automatic Global Change Rule Names Reference by Name Color Coding Menu Driven Repeat Conditions Where Title/Author Option Start/End Text Option Configure File Options User Menu Control Report Generator Language
A - INTRODUCTION
13

Custom Screen Language Custom Hypertext Files Interface Command Generator OR Block Validity Checking Cross Reference Listings Rule Compiler Format Output C Code Output Format

External Interface:
Linear Programming (LINDO) External Program calls: Front End Data Dependent Rule Dependent Command Language Report Dependent Direct Lotus 123 Interface Direct dBase III Interface Graphics Interface Menu Driven Command Definition

End User Interface:


Default Question Format Custom Screen Definition WHY and HOW Display Known Data Rule Notes User Help: Hypertext System Help Custom Help Screens Help with Custom Hypertext Help with External Programs Rule Reference Data Variable Data Embedded in Help Messages or Hypertext Easily Readable Rules Option Controls Input Verification with Custom Messages Color Coding of Conditions

A - INTRODUCTION

14

A8: EXSYS Professional Files


EXSYS Professional uses a number of files to store, configure, run and communicate between expert systems. The files below are marked as EXECUTABLE (the name entered to call the program from the operating system, or there is an executable icon to click on), REQUIRED (needed to run a knowledge base) or OPTIONAL (not required except to perform a special function). Files marked with an * are created by the user and are not on the distribution disks. <ES name> is the name of the expert system file created by a user.

EDITXSP.CFG The configure file for all knowledge bases run with EDITXSP.EXE. This file is automatically read whenever EDITXSP.EXE is used and the configure commands implemented (This is an ASCII file created and edited with a text editor). OPTIONAL EDITXSP(.EXE) The EXSYS Professional editor program for creating and editing knowledge bases. This is the program used to modify EXSYS Professional rules, qualifiers, formulas, etc. EDITXSP has the ability to run knowledge bases during development. EXECUTABLE EXSYSP.CFG The configure file for all knowledge bases run with EXSYSP.EXE. This file is automatically read whenever EXSYSP.EXE is used and the configure commands implemented. (This is an ASCII file created and edited with a text editor.) OPTIONAL EDITXSP.HLP The EXSYS Professional Editor help file. This file contains the help information displayed from EDITXSP. (This file should not be modified.) REQUIRED

A - INTRODUCTION

15

EXSYSP(.EXE) The EXSYS Professional Runtime program. This is the program for running existing, fully developed knowledge bases. EXECUTABLE EXSYSP.HLP The EXSYS Professional help file. This file contains the help information displayed from EXSYSP. (This file should not be modified.) REQUIRED EXSYSRC(.EXE) The EXSYS Professional Rule Compiler. Used for compiling knowledge bases developed or edited in a word processor. This program produces files that can be used with EXSYSP or EDITXSP. EXECUTABLE EXSYSRC.HLP The EXSYS Professional Rule Compiler help file. This file contains the help information displayed from EXSYSRC. (This file should not be modified.) REQUIRED EXSYS-CS(.EXE) The EXSYS Professional Screen Display Utility. Used for displaying custom screens. EXECUTABLE EXSYS_CS.HLP The EXSYS Professional Screen Display help file. This file contains the help information displayed from EXSYS_CS. (This file should not be modified.) REQUIRED PASS.DAT* The default file to pass data from EXSYS Professional to external programs. The name of this file can be changed as a command line option or in the .CFG file with PASS= (This is an ASCII file created by EXSYS). OPTIONAL RETURN.DAT* The default file to return data to EXSYS Professional from external program calls or DATALIST commands. The name of this file can be changed as a command line option or in the .CFG file with RETURN= (This is an ASCII file created by the external program called). OPTIONAL
A - INTRODUCTION
16

<ES name>.CFG* The configure file associated with the specified knowledge base. This file is automatically read whenever the specified knowledge base is used and the configure commands implemented (This is an ASCII file created and edited with a text editor). OPTIONAL <ES name>.CMD* The command file associated with the specified knowledge base. This file would contain commands controlling order of rule execution, looping, etc. It would override the normal EXSYS Professional backward or forward chaining modes. OPTIONAL <ES name>.HLP* The custom help file data. This file contains the custom help information for qualifiers and variables to be used with the specified knowledge base (This is an ASCII file created and edited with a text editor) OPTIONAL <ES name>.HYT* A file created by EXSYS Professional of offset information for the .SCR file. This file should never be modified by the user.GENERATED BY EXSYS <ES name>.OUT* The report generator specification file for the specified knowledge base. This file contains the report generator commands to be used when the knowledge base has completed its run (This is an ASCII file created and edited with a text editor). OPTIONAL <ES name>.RUL* The rule file associated with the specified knowledge base. This file contains the text independent numeric representation of the knowledge base rules. The contents of the file are read when EXSYS or EDITXS reads the rules (This file is modified by the editor EDITXS.EXE and should not be changed by any other program). REQUIRED

A - INTRODUCTION

17

<ES name>.SCR* The screen definition file associated with the specified knowledge base. This file contains definitions for some or all of the qualifiers and variables in EXSYS Professional. This screen would be used to ask the end user for data. OPTIONAL <ES name>.TXT* The text file associated with the specified knowledge base. This file contains the text portion of the EXSYS rules. The contents of the file is accessed when text must displayed to the user (This file is modified by the editor EDITXS.EXE and should not be changed by any other program). REQUIRED TECHHELP.* A technical support expert system. If you have problems running EXSYS Professional, this should be able to answer many of your questions.

A - INTRODUCTION

18

Chapter B Developing Expert System Knowledge Bases B1: What Can an Expert System Do?
The first question in considering the development of an expert system is "Why build an expert system?" Expert systems cannot solve all problems. Understanding why an expert system is desired, understanding what type of system it must be and how it must work are primary questions. The usual reasons for building an expert system are to Disseminate problem-solving knowledge, not just facts, with minimal training of end users. Standardize the conclusions for a given set of data. Interface with other programs and provide analytical capability. Free a human expert from repetitive, routine jobs in order to do activities an expert system cannot do. Codify a problem-solving technique for future users. Provide a safe and effective training tool. Allow the problem-solving skills of several people to be combined. The goal of a particular expert-system project may be a combination of several of the above. Before developing an expert system, first decide on the goals. A system designed to automatically analyze a spreadsheet may be very different from one designed to provide a problem-solving capability or training of users.

B - DEVELOPING EXPERT SYSTEMS

B2: How to Select An Appropriate Problem


An unlimited number of problems can be solved by an expert system. In theory, any decision-making process can be converted to an expert system; however, in practice, many problems cannot be effectively converted. For example, a problem may be incompletely understood or be just too large or complex for conversion to an expert system. The most important first step in developing an expert system is to define an appropriate problem. Often, even if a large problem cannot be solved, part of the problem can be. Factors that should be considered in defining a problem for the expert system include:

1. Does a human know how to solve the problem?


If no human expert can solve the problem, it is not possible to develop rules describing the solution. The techniques of solving the problem must be known and defined in order to create an expert system.

2. Does the problem have a definable solution?


EXSYS Professional and most other expert system shells are designed to select one or more possible solutions from a group. If all of the possible solutions cannot be specified, writing rules to solve the problem is difficult. Some problems can be handled that have a very large number of solutions, configuration problems are a good example, but a definable set of possible solutions is known.

B - DEVELOPING EXPERT SYSTEMS

3. Is the level of understanding and scope appropriate?


A graph can best illustrate the question. The level of understanding is on the horizontal axis ranging from limited understanding (a simple, well defined solution) to deep understanding (a solution requiring insight and innovation). The other axis is the scope of the problem, ranging from very specific to very wide problems.

Wide

Problems

S c o p e
Specific

Expert Systems

Limited

Deep

Level of Understanding

Defining the problem to fall within the shaded area of the graph is very important. A problem that has too wide a scope or that requires too deep a level of understanding is not appropriate for an expert-system solution. Expert systems cannot emulate deep understanding with insightful solutions to new problems. As the scope of the problem gets larger and larger, the number of rules necessary to express the problem becomes very large. To solve problems with a wide scope, first narrow the scope and solve a small part of the problem. Once that part works, do another part of the problem. Eventually the collection of expert systems can solve a wide range of problems. Keeping realistic goals is very important. An human expert cannot be captured in a computer; only a small part of the problem-solving skill can be expressed in an expert system. A human expert can solve new problems based on experience and intelligence; a computer cannot. However, the expert system can solve the specific problems it has been designed for and will do so for many non-expert users, 24 hours a day. Moreover, the expert system gives consistent answers and usually faster than the human expert can.

B - DEVELOPING EXPERT SYSTEMS

4. Has the technique for solving the problem been documented?


A vast number of problems meet the requirements for successful, worthwhile, and effective expert-system development. Remember, an expert system does not have to solve a major problem to be worthwhile. Any area where one person possesses a problem-solving skill that is needed by others is often well documented and has good potential for an expert system. The areas may seem very mundane or uninteresting, but these are often the best for expert system development because they are well understood and well documented. The solution may be a decision tree, manual procedure, regulations, or specific, written instructions. Such well-defined problems can be easily converted to expert systems and the solution is made more accessible to end users through an expert system. Solving a problem with an expert system is much easier than looking up procedures in a manual and less prone to error.

B - DEVELOPING EXPERT SYSTEMS

B3: Building an Expert System


Once a suitable problem has been defined, the problem-solving techniques must be converted to expert system rules. A particular problem may be solved in a variety of ways. Different expert system developers have different approaches and techniques of preference. Some developers write backward-chaining systems while others prefer forward chaining. Some use modular systems with blackboards; others prefer large, single systems. Some embed the expert system and others embed the external programs. As long as the system gives the correct results, no one way is more correct than another. More difficult problems sometimes require clever approaches. As you gain experience in converting human knowledge to rule form, you will be able to better determine what approach is going to be best for you in developing a particular system.

Tree-Structured Approach
To get started, choose a simple problem that has a well-defined set of solutions and few alternatives. Even then, the system can be written in a variety of ways. For example, suppose we want to write a system to identify the items on a desk. The desk has a telephone, a computer, a pencil, paper, and floppy disks. One way to write a system is to first create a decision-tree diagram. If the decision tree is complete, the systems developed from it will be complete. First we will make a simple decision tree for the problem of identifying the items on the desk:
TELEPHONE

Black Color? YES Makes noise? NO Color? White

COMPUTER

Black Flat

FLOPPY DISK PAPER

Shape White

Cylindrical

PENCIL

B - DEVELOPING EXPERT SYSTEMS

This very shallow tree can be converted directly to rules by just tracing each branch of the tree. Tracing each branch always allows a tree to be converted to rules, but if the tree has many branching points, this approach may result in more rules than are needed. For this example, at the same time we identify the items, we can indicate the level of confidence in the answer. We are using the 0-10 Confidence Mode. Beginning with the top branch,
TELEPHONE

Color? YES Makes noise? NO Color?

Black

White

COMPUTER

Black Flat

FLOPPY DISK PAPER

Shape White

Cylindrical

PENCIL

the rule would be: Rule 1 IF The item makes noise and The color is black THEN Telephone - Confidence=10/10 The rules for the other branches would be: Rule 2 IF The item makes noise and The color is white THEN Computer - Confidence=10/10 Rule 3 IF The item does not make noise and The color is black THEN Floppy Disk - Confidence=10/10

B - DEVELOPING EXPERT SYSTEMS

Rule 4 IF The item does not make noise and The color is white and The shape is flat THEN Paper - Confidence=10/10 Rule 5 IF The item does not make noise and The color is white and The shape is cylindrical THEN Pencil - Confidence=10/10

Use of Sub-sets of Rules for Sub-goals


Any decision-tree diagram can be converted to rules, but if large decision trees need to be translated, identifying sub-goals may make the system easier to manage. Using sub-goals may increase the total number of rules, but ease of use and maintenance are increased. If a black pen is added to the desk, the form would be:

Color? YES Makes noise? NO

Black

TELEPHONE

White Flat

COMPUTER FLOPPY DISK

Shape Black Color?

Cylindrical Flat

PEN PAPER

Shape White

Cylindrical

PENCIL

B - DEVELOPING EXPERT SYSTEMS

We could convert this option to rules as before, by adding a "shape" condition to Rule 3 and adding a new rule for "PEN." However, since the "Shape?" test is repeated, we can restructure the diagram.
TELEPHONE

Color? YES Makes noise? NO

Black

White Black Color? Cylindrical Shape White Black

COMPUTER PEN

PENCIL FLOPPY DISK

Color? Flat

White

PAPER

We can now create sub-goals. This example will require more rules to specify the sub-goal, but the rules will be less complex. In a large system, sub-goals provide a very convenient way to specify a branch point in one condition rather than many. Sub-goals are simply a way of specifying part of the decision process. In this example, if the item does not make noise, we can divide the possible solutions into two categories - writing tools and information storage media (quite a euphemism for paper). Rules 1 and 2 would be the same as above, but now we will add new rules 3 and 4: Rule 3 IF The item does not make noise and The shape is cylindrical THEN The item is a writing tool Rule 4 IF The item does not make noise and The shape is flat THEN The item is information storage media

B - DEVELOPING EXPERT SYSTEMS

The conditions in the THEN part of rules 3 and 4 are simply built from qualifiers. They are not choices. These qualifiers will be automatically invoked through backward chaining if the information is needed. We can now add two more rules to complete the sub-set: Rule 5 IF The item is a writing tool and The color is black THEN Pen - Confidence 10/10 Rule 6 IF The item is a writing tool and The color is white THEN Pencil - Confidence 10/10 Rule 7 IF The item is information storage media and The color is black THEN Floppy Disk - Confidence 10/10 Rule 8 IF The item is information storage media and The color is white THEN Paper - Confidence 10/10 The system now has 8 rules to express what could have been expressed in 5, but the problem is broken into smaller parts. The new Rule 6 is easier to understand than the old Rule 5. The system has fewer but more explanatory conditions. If we ask the program *HOW it knows the item is a writing tool, Rule 3 is automatically displayed since the information was obtained through backward chaining.

B - DEVELOPING EXPERT SYSTEMS

When we run the rules, however, if we input that the item does not make noise, the program asks if: The item is 1 a writing tool 2 information storage media We have only told the program how to determine if the item is a writing tool or media only for cases that do not make noise. Once we say it makes noise, rules 3 and 4 are false and the program cannot gain any information from them. Consequently, the program will ask us as end users the question about the "item." Suppose, though, that we do not wan the user asked this question. Several modifications to the system are available. First, another value can be added to the sub-goal qualifier: The 1 2 3 item is a writing tool information storage media machine

Now we have three options: 1. Add a rule: Rule 9 IF The item makes noise THEN The item is a machine This rule will provide the information, because now the program can determine data on the sub-goal even if the item makes noise. or 2. Add the THEN condition of Rule 9 to rules 1 and 2. Again, the program is able to get information on the sub-goal even if the item makes noise. or 3. Make value 3, machine, the default value for the qualifier. In this alternative, if the program cannot derive a value from the rules, the default value applies and the end user is not asked the question. Any one of the above solutions complete the rule sub-set.

B - DEVELOPING EXPERT SYSTEMS

10

Adding a sub-goal increased the number of rules from 6 to 9. In our example, the sub-goal was unnecessary, but if the sub-goal had 7 decision levels below it, specifying the decision tree only from that point would be useful. Sub-goals should always be used if the decision tree is very deep.

Working back from Conclusions


Many problems can be diagrammed as decision trees, but not all. Some systems that have confidence values associated with their solutions are difficult to diagram in a tree structure. In such a situation, an alternative is to work on only a small part of the problem at a time. If the problem is small, all aspects are more easily handled. To use this approach, start with the goals of the whole system and express them in the most general terms when that solution is appropriate. We will use the example of the items on the desk, but this time we will approach the problem without a tree diagram and start with the goals. First we will consider the PEN and PENCIL. We can distinguish them by color, so we will say: Rule 1 IF The item is a writing tool and The color is black THEN PEN - Confidence 10/10 Rule 2 IF The item is a writing tool and The color is white THEN PENCIL - Confidence 10/10 We will then make the same type of rules for the FLOPPY DISK and PAPER. Rule 3 IF The item is information storage media and The color is black THEN FLOPPY DISK - Confidence 10/10

B - DEVELOPING EXPERT SYSTEMS

11

Rule 4 IF The item is information storage media and The color is white THEN PAPER - Confidence 10/10 These rules are valid, but when we now run the rules, the program asks The item is 1 a writing tool 2 information storage media For our intended end users, this question is inappropriate. We want the system to provide this information, not the user. When using the technique of starting with the choices, this is expected. The goal is to work out the logic at the highest levels. Creating complete and logical descriptions of the decision is much more important than the questions asked of the user. Sets of rules can be written to handle the user interface after the logic is correct. Once we have the logic correct at the highest level, we will start working down to eliminate the inappropriate questions. To eliminate the question on writing tool versus media, we add these rules: Rule 5 IF The item does not make noise and The shape is cylindrical THEN The item is a writing tool Rule 6 IF The item does not make noise and The shape is flat THEN The item is information storage media

B - DEVELOPING EXPERT SYSTEMS

12

and another rule to allow the qualifier to get an answer even if the item makes noise: Rule 7 IF The item makes noise THEN The item is a machine Since we were this time only writing rules to derive a value for the specific qualifier, it was easier to see that a third rule would be needed, rather than in the tree approach above with sub-goals. The advantage of working back from the choices is that a small part of the problem can be in focus, while still maintaining a complete and logical set of rules. We now need to consider the rules for the TELPEHONE and COMPUTER choices. These rules are simple: Rule 8 IF The item makes noise and The color is black THEN TELEPHONE - Confidence=10/10 Rule 9 IF The item makes noise and The color is white THEN COMPUTER - Confidence=10/10 We end up with the same set of rules as above but in a different order. Since this system is backward chaining, the order of the rules does not matter. We produced the same results by very different logical approaches. For many problems, the approach used is purely a matter of personal taste. Both methods can produce equally good systems. However, if confidence factors are used extensively, the method of working backward from the choices seems easier to use. Professional displays the tree diagram of the rules we have input, allowing us to check for incomplete branches or other errors.

B - DEVELOPING EXPERT SYSTEMS

13

B4: Backward Chaining


Most expert-system problems should be divided into several subproblems which can often be divided yet again. Writing these small sets of rules to solve the smaller problems or define sub-goals is much easier. Then writing more general rules using the solutions to the smaller problems to solve the large problem can be written. EXSYS Professional tries to solve the larger problems by using the solutions to the smaller problems to derive the information it needs. Professional's ability to automatically invoke the rules needed to derive information is called "backward chaining." Backward chaining is one of the most powerful aspects of an expert system. Regardless of how the problem is approached, backward chaining will likely be used to obtain information from other rules. If programming languages are familiar, the implementation of backward chaining may seem strange because the program does so much of the work. The expert system does not have to be instructed that rules are available that allow the information to be derived or to tell the program which rules to use. If such rules exist, the program will find them and use them. Their order does not matter. If a new rule relevant to part of the decision process is needed, it can be added anywhere in the rule set. As described above, one approach to finding smaller problems is to ask how, in the broadest terms, does one solve the problem. The answer will probably be "If --- and --- then ----." Consider if the IF conditions could be made into questions to ask a user and reliably get a meaningful answer. If the IF condition is too complex to ask simply, consider how it could be broken down into questions that the intended user would understand and which could be used to derive the IF condition. The process may have to be repeated if these questions are still impractical to ask a user. Continue this process until the questions are ones the intended user can answer. The rules are simply the statements that express how the information is derived. The following example shows how a problem can be broken down into smaller parts.

B - DEVELOPING EXPERT SYSTEMS

14

Suppose we are developing an expert system to supply medical advice over the telephone when the doctor is out. Assume calls are answered by non-medical personnel who run the expert system and talk with the caller. Naturally, such an expert system would need to know that if someone is sick and calls after hours, he should take an aspirin and call back in the morning. This can be expressed in rule form as: Rule 1: IF The caller is sick and The hour is late THEN Aspirin - Probability= 10/10 and Call again in morning Confidence= 10/10 This rule will select the aspirin and call again choices. The problem has now been reduced to two smaller problems: determining if the caller is sick and determining if the hour is late. The program could ask the user for this information but the answers on "sick" or "late" would be subjective. If the program derives the information from other rules and asks the user precise questions, the results will be objective. When the program tests Rule 1, it checks the first condition, The caller is sick. The qualifier for this condition is The caller is. Before it asks the user, the program searches all its other rules to see if any can derive the value for the same qualifier in their THEN or ELSE parts. In this case, assume we have put in three rules to help the program determine if the caller is sick. All three rules have the qualifier The caller is in their THEN part. Rule 2: IF The voice sounds hoarse THEN The caller is sick Rule 3: IF The temperature is over 100 degrees THEN The caller is sick

B - DEVELOPING EXPERT SYSTEMS

15

Rule 4: IF The voice is not hoarse and The temperature is less than 100 degrees THEN The caller is well In this example, the program first tries to derive information about The caller is from Rule 2. Since no rules have The voice is in their THEN parts, the program asks the user about the voice. If the user selects "hoarse," then the IF condition in Rule 2 is true and the program knows The caller is sick. The developer has the option of directing the program to stop derivations after the first successful rule fires or to apply all appropriate rules (see Section C3.6 for more information.) If only the first successful rule in derivations was selected, the program would return to work on Rule 1 with the new piece of information that The caller is sick. If all applicable rules in derivations was selected, the program also tries to apply Rule 3. (In this example, the additional question would be unnecessary and using the first successful rule for derivations would be adequate.) If the caller answered that the voice was not hoarse, the program would reject Rule 2 as invalid and try Rule 3, since it is the next rule with the same qualifier, The caller is, in its THEN part. The program next asks about the caller's temperature. If the caller responded that the temperature was over 100 degrees, Rule 3 would determine the caller was sick; if the caller said the temperature was less than 100 degrees, Rule 4 would determine the caller was not sick. By using rules 2, 3, and 4, the program can derive whether the caller is sick or well, without directly asking about "sick" or "well." Had we not included Rule 4 and had the caller answered that the voice was not hoarse and the temperature was less than 100 degrees, the program would not have had any valid rules with The caller is in their THEN part. The program could not derive any information on The caller is and would have asked directly if the caller was sick or well. This is what we were trying to avoid, so Rule 4 was added. (Other ways to do this with default values are described in Section C3.6.) Any combination of answers to the questions about voice and temperature will result in at least one of the rules being found true. The program now knows the state of the caller's health. If the caller is well, Rule 1 is rejected. If the caller is sick, the first condition of Rule 1 is true and the program tests the second condition, The hour is late. Since "late" is subjective, we want rules to derive the information.
B - DEVELOPING EXPERT SYSTEMS

16

Rule 5: IF The day is Mon or Tues or Wed or Thurs and The time is between 4:00PM and 9:00AM THEN The hour is late Rule 6: IF The day is Fri and The time is between 2:00PM and 4:00PM or between 4:00PM and 9:00AM THEN The hour is late NOTE: The Doctor plays golf on Friday Rule 7: IF The day is Sat or Sun THEN The hour is late Rule 8: IF The day is not Sat or Sun and The time is between 9:00AM and 2:00PM THEN The hour is early Rule 9: IF The day is Mon or Tues or Wed or Thurs and The time is between 2:00PM and 4:00PM THEN The hour is early The program now only needs to ask easily answered questions about the day of the week and the time segment (9:00AM-2:00PM, 2:00PM-4:00PM, 4:00PM-9:00AM) to know if the hour is late. (The first condition in Rule 8 could have been written THE DAY IS MON or TUES or WED or THURS or FRI and produced exactly the same results. The form used is shorter and simpler.)
B - DEVELOPING EXPERT SYSTEMS
17

To summarize, we broke the problem into three parts: a general rule (Rule 1) based on two smaller problems (sickness and lateness) and two sets of rules to solve the smaller problems. Since in normal backward chaining, Professional will not fire rules unless it needs some piece of information in the THEN or ELSE part, the only time it should have rules do not that contain choices in their THEN/ELSE parts is if they are being used to derive information for other rules. Derivations can continue down many layers in complex expert systems; EXSYS can backward chain well over 100 layers of qualifiers. Other rules can be written using the qualifiers The caller is or The hour is and rules 2-9 are invoked to derive the needed information. Should we later decide that another way to determine if the caller is sick is required, we can simply add a single rule such as: Rule 10: IF The patient is sneezing THEN The caller is sick The new Rule 10 is automatically invoked by any rule that uses The caller is in its IF part. (In practice, we would need to modify Rule 4 so we do not have a patient that is both well and sick). Note: Once rules to solve the small parts of a problem are written, the more general rules are often easier to write. Remember that if the rules are created to derive information, they must be a complete set that accounts for all possible combination of input. If not, the program may ask the complex or ambiguous question that was being avoided. This is where ELSE conditions can be very useful. Rules can call each other to derive information recursively. For example, Rule 1 could use Rule 2 to derive information and Rule 2 could use Rule 1 to derive information causing Rule 1 to again call Rule 2, etc. The program recognizes the loop and breaks out to continue the problem. This type of error in logic will produce an error message. A rule can also have the same qualifier in both its IF and THEN parts. This is useful if, based on other input, a suspicion exists that the user may not have fully considered all of the values for the qualifier or if a value for the qualifier is forced regardless of the user input.
B - DEVELOPING EXPERT SYSTEMS
18

B5: Using Confidence Modes


One of the most powerful parts of an expert system is being able to create rules which state that an answer is probably, but not definitely, true. Definite yes/no answers are nice, but in practice the real world is rarely so cooperative. In most cases certain facts may imply one answer but are not definitive. Because of this EXSYS Professional has five confidence systems. Selecting the appropriate confidence mode for an expert system is very important. Changing to a different system later is difficult. (Changing can be done only through the Rule Compiler. The rules are printed, confidence values are changed to a new system with a text editor, and then they are recompiled.) The main rule of thumb to use when selecting a confidence mode for a system is - Use the simplest one that will do the job. If all data in a system is definite, use the "0 or 1" system. This is equivalent to YES/NO. This is good for selecting among groups of items that can be definitely identified. It is also appropriate for converting decision trees that do not involve probability. The 0-10 system is one of the best for most problems. It is recommended for all beginning systems. It allows values to be locked at YES or NO with a 0 or 10, but still provides a way of handling the confidence of intermediate answers. Many rule-based problems can be handled with this system and it should be used, unless some aspect of the problem requires the special capabilities of one of the other systems. The -100 to 100 system is similar to the 0-10 but offers more precision in the confidence values. In practice this precision may not be valid unless there is statistical data available. Few human experts can put a value to their intuitive knowledge that is precise to 2 digits. The increment/decrement system is another easy-to-use system. It allows intuitive knowledge about the chance of a solution being appropriate to be easily expressed in rules. This system has the major benefit that the answers are not bounded to a small range. The final confidence can be 10,000. This allows differentiating between solutions that might have the same value in other systems. The custom formula system is by far the most complicated and the most powerful. We do not recommend it for new developers or if one of the other techniques is adequate. This system allows assigning confidence values for qualifiers and variables in addition to choices. Usually this is not necessary, but in some cases it can be desirable. (See Section C3.3 for more detail on confidence modes and Section C40 for more information specifically on custom formula systems.)

B - DEVELOPING EXPERT SYSTEMS

19

Giving specific directions for which confidence system to use is difficult because the selection depends on the purpose of the expert system. Consider what the system will do and how confidence will be used in the rules. The following questions may help with making a selection.

How precise is the data?


If the data is from a human expert, accuracy is usually expressed with one digit. If the confidence data is statistical, two or more digits of accuracy may be possible.

Do solutions with a few rules assigning different values need to be differentiated from solutions with many rules assigning the same value?
If differentiation is needed, none of the systems which use averaging are appropriate. Instead "increment/decrement" or "-100 to 100" in the dependent or independent mode is good.

Do the users need to provide confidence values for their data?


Most systems do not need the user to input confidence values with his response. But if user confidence is necessary, the custom formula system is the best choice. For example, the program might ask the user The age of the antique chair is 1 less than 50 years 2 50 years or more In the custom formula mode, the program could then ask how definite is the answer. The user-supplied confidence for the qualifier would have to be in the range specified by the developer. The usual ones are 0-10, 0-100 or -1 to 1. This user-supplied confidence value for the qualifier could then be combined with the qualifier's value to determine the confidence for the choices. For example, the developer might decide to ignore the users' opinion of the age if their confidence is less than 5/10. Also, the user-supplied confidence values could help determine a final confidence value for a choice - lower user confidence in answers would lead to lower overall confidence in the choices. Clearly, asking the users to supply confidence values for their information assumes a higher level of end-user expertise than simply asking unambiguous multiple choice questions. Asking users to supply confidence values may be counterproductive to the expertsystem goal that provides problem-solving techniques to non-experts who may be unsure of their answers. Users' confidence in their answers may vary greatly between different users and even vary significantly with the same user answering at different times. Because of these variations, heavy reliance on the user-supplied confidence values is discouraged. Users' values can best be used to determine if data should be disregarded or to determine the level of the end-users' knowledge.

B - DEVELOPING EXPERT SYSTEMS

20

The confidence values for a qualifier or variable can also be derived from other rules. This approach is often better than asking the user for a numeric value. For example, the program could ask the question about the antique chair, and then ask Your opinion of the age of the chair is 1 definite 2 very probably correct 3 probably correct 4 somewhat uncertain Although the number of options for the user has been reduced, the answers still provide the data needed by the program. This method of questioning can be employed with all of the five confidence modes. The qualifier values about the degree of certainty can be used as they stand or can be converted to numeric values. This method produces highly consistent answers among a group of users.

Does the problem require a complex system for combining confidence factors?
The initial four systems in Professional have intentionally been kept easy to use. They are designed for the rapid construction of expert systems by people with domain expertise but not necessarily Artificial Intelligence training. Many very complex systems can be developed for combining confidence factors. These can be implemented by applying the custom formula system when required.

B - DEVELOPING EXPERT SYSTEMS

21

B6: Using the Command Language


The Command Language is the most complex part of building an expert system. EXSYS Professional defaults to a backward-chaining system. This is very easy to use and is adequate for most problems. Rule order or placement is not important; rules will be found and used if needed. However, if the developer wants the program to do something other than backward chaining, he can use the Command Language. The Command Language provides complete control, not only over the order of rule execution, but also chaining, setting of data, and looping. It is very powerful, but it requires more work by the developer. The Command Language is a programming language for procedural operations which, combined with the rules for logic control, allows more complex problems to be handled than with simple backward chaining. To experiment with the Command Language, first create a simple backward-chaining system. (Using one you create is better than using one of the demo systems because you will understand the system much better.) Add a .CMD file. Start with the following commands: :LOOP RULES ALL RESULTS /C:LOOP These directions are the same as backward chaining. Try changing the RULES command or adding some SET commands. Experiment and see how the commands effect the run of the rules. (See Chapter J for more information.)

B - DEVELOPING EXPERT SYSTEMS

22

B7: Using the Report Generator


The EXSYS Professional Report Generator can print reports, pass data to other programs, and format the conclusions of the run. The commands used in the Report Generator have default options of only one character, but these can have added options to produce more specific results. For example, the command C prints all choices, but the command C>6 prints only those choices which received a final score greater than 6, and the command C>6 /T prints only the text (no value) of those with a score greater than 6, and so forth. The report generator command language is easy to use, but it can produce very complex reports. Once a system is developed, one can experiment with the commands. A particularly easy form for testing the Command Language is to FILE XXX . commands . CLOSE DISPLAY XXX These commands create a report and then display it on the screen. Change the commands to see the effect on the report. The Report Generator is not needed in every expert system, but for systems that must format data for the user or communicate with other systems, it is very useful. (See Chapter F for more information on the Report Generator.)

B - DEVELOPING EXPERT SYSTEMS

23

B8: Creating Your First Expert System


Select a fairly small, well-defined problem on which you personally have expertise. (Attempting to extract rules from someone else while learning about EXSYS Professional makes the job much more difficult.) Select a problem appropriate to either the "0 or 1" or the "0-10" confidence systems. Avoid the more complicated confidence mode in your first system. If the problem can be diagrammed as a tree, diagram it as a guide for the rules. If it cannot be easily diagrammed, start with identifying the choices. Next, create rules. Enter some rules to solve the problem and then try to solve specific examples. If the system does not get the correct answer, check the rationale with the commands of WHY, HOW, and TRACE to find the error in logic. Often the error is due to unrealistic simplifications of the main problem. Once the specific error is identified, the appropriate rules can be added to more realistically address that area. Professional works these rules into the overall solution. This interactive testing and modification helps to convert intuitive knowledge and experience into rule form. Continue testing the knowledge base until you are confident it is working properly. It may take a while to perfect the rules. You can use the validation and the ability of EXSYS to diagram the logic of the rules to help you. Study the simple knowledge bases provided and develop several small ones before attempting a major problem. You may be surprised at how little practice is needed to separate seemingly complex problems into simpler parts, each requiring relatively few rules for solution. Building expert systems is like programming in a language that does much of the work for you. Professional finds the correct rules and answers questions. But, the developer must create the rules. As with programming, experience is the best teacher. Making mistakes and trying new approaches is the best way to learn EXSYS Professional. As more systems are built using more of Professional's features, the use of the features to enhance the power of each other become evident, i.e., use a report specification in the Command Language or use a Report to pass data to an external program. If you have problems getting a system to run, try running the HELP knowledge base that came with Professional. IF that does not solve the problem, call EXSYS Technical Support. They have heard almost every mistake that can be made many times. They will probably be able to help you past the problem to get a system running.
B - DEVELOPING EXPERT SYSTEMS
24

Training
To really get started fast, you may also want to consider classes using EXSYS Professional. Classes are available from many sources including college, universities, third party training and EXSYS Inc. Call EXSYS Inc. (505) 256-8356 for information on classes that are available.

B - DEVELOPING EXPERT SYSTEMS

25

Chapter C EXSYS Rule Editor


EXSYS expert systems are created and edited using the Rule Editor program, EDITXSP, which allows easy inputting, editing and testing of rules. This chapter includes directions for creating new rules as well as editing existing ones. Chapter D covers the commands to run the rules from either the Editor or Runtime program. Rules can also be developed using a text editor and EXSYS Professional's Rules Compiler, but it is better to learn the Rule Editor first. The Rule Editor can perform most operations faster and easier and, due to the menu driven structure, is easier to learn. There are certain types of editing operations which are easier to do with the Rule Compiler. These are discussed in Chapter K on the Rule Compiler.

C - RULE EDITOR

C1: Starting the Rule Editor


Click on the EDITXSP icon to start the program. In some GUI operating systems, you may also run the program with optional associated filename of the knowledge base file to run, and one or more configure commands: EDITXSP <filename> <configure_commands>

The configure_commands are described in Chapter E. EXSYS works with two main files for each knowledge base, filename.RUL and filename.TXT. Note: Both the .RUL and .TXT Files must be kept in the same Path/Directory (or Macintosh Folder) or the program will not work. EDITXSP does not load the .TXT file into memory. The .TXT file is accessed as needed from the disk, and if the file is on a floppy disk, it must remain in the disk drive while the program is running.

C - RULE EDITOR

C2: Opening an Existing Knowledge Base


File Edit Rule Options KBfiles Questions

New Open Save Save As Revert to Saved Print Exit About

If you select Open, a list of all of the files with a .rul extension will be displayed. Double click on the file you want to use, or select a file and click the Open button. On some operating systems, all files will be displayed, not only those with .RUL extensions. To open a knowledge base, select any of the files in the knowledge base that start with the same filename as the .RUL file. Once the knowledge base file is selected, the files will be read and the system title screen will be displayed. At that time, you can perform operations on the rules, run the rules, and perform a number of other options.

C - RULE EDITOR

C3: Starting a New Knowledge Base


File Edit Rule Options KBfiles Questions

New Open Save Save As Revert to Saved Print Exit About

Pull down the main menu bar item File and select New. If you select New, EXSYS will ask you for the name of the knowledge base you wish to create. Enter a file name, and if appropriate for your operating system, enter the optional drive or path. Whenever a new knowledge base is created, EXSYS asks you to define certain parameters for the new system. These steps are necessary only when a new expert system is created. All parameters, except for the confidence mode, can be edited later.

C3.1: Subject
Enter a short subject name for the system you are developing. EXSYS requires you to use a subject name which it will display on the system title screen. The text should be less than 200 characters. EXSYS will not continue past this screen unless you enter a subject name.

C3.2: Author
The program asks for the author's name. Like the subject name, EXSYS requires you to enter the author's name which must be less than 200 characters in length. The authors name is also used for the title screen. Like the subject, EXSYS will not continue past this screen unless an author is entered.

C - RULE EDITOR

Knowledge Base Parameters Subject: Author: Confidence Mode: Yes/No 0 -10 -100 to 100 Increment/Decrement Custom Formulas Derivation Mode: All Possible Rules First Successful Rule All Non-redundant Calculation Mode Average Dependent Prob. Independent Prob.

Starting Text Ending Text Ext. Prog.

Rule Display Mode: Display Rules Do NOT Display Lock DIsplay OFF Display Threshold:

Check New Rules for Consistency Yes No Init Choice Value

OK

C3.3: Confidence Mode


Select which of the five Confidence Modes to use in your new expert system. Click on the radio button next to the mode you wish to use. Because this parameter directly affects the structure of the rules, it can not be edited or changed later using the Rule Editor. (There is a way to change the Confidence Mode using the Rule Compiler.) When selecting a Confidence Mode, the most important rule to remember is: Use the simplest system that will do the job.

YES / NO System
If the system does not require any estimate of probability, the YES/NO (0-or-1) System is best. This confidence system is very easy to use since the first rule that fires for a choice sets the value to 1 for Yes or 0 for No. No intermediate values are assigned. This confidence system is good for selecting choices from a list, an automated questionnaire, or other systems which contain choices that can definitely be answered with a "yes" or "no".

C - RULE EDITOR

0-10 System
The 0-10 System provides confidence values on a scale of 0-10. This is often quite compatible with the intuitive knowledge used in the development of an expert system. An assignment of 0 locks the value for the choice at 0 (No), and an assignment of 10 locks the value at 10 (Yes). Confidence values between 0 and 10 are averaged to provide a relative likelihood. This system can positively select or reject a choice (with a value of 10 or 0) but can also allow intermediate values to indicate choices that may be appropriate. For example, suppose Choice 1 was in three rules which fired with assigned confidence values of 3, 7, 8; Choice 2 was in two rules with values of 7 and 10; and Choice 3 was in one rule with a value of 5. The final confidence values would be Choice 2: Choice 1: Choice 3: 10 (the selection of one 10 locks the value at ten) 6 (the average of 3, 7 and 8) 5

This allows the end user to see not only which choices were selected but also provides a means of relative ranking. When obtaining a human expert's intuitive confidence for confidence in an event, a 0-10 scale is often comfortable and easy to use. Unless valid statistical data is available, precision higher than 0-10 is difficult to obtain from intuitive knowledge. Despite its simplistic calculations, the 0-10 System is very useful for many expert systems, and it is easy to use. We recommended this mode for beginning systems.

-100 to 100 System


The -100 to 100 System is effective if statistical data accurate to two significant figures is available or if the nature of the problem requires that confidence factors be combined as dependent or independent probabilities. Values can be assigned to choices in the range of -100 to 100. This provides greater resolution than the 0-10 system. However, there is no value that locks the value at "yes" or "no. Values of 0, 100 and -100 are treated like any other value. Also, there are three methods of combining the confidence valuesaverage, dependent probabilities, or independent probabilities. These methods are described in section C3.4 on Calculation Mode. If the confidence factors are to be combined as dependent or independent probabilities, only the range 0-100 can be used because

C - RULE EDITOR

negative values have no meaning. If confidence factors are combined by averaging, the full -100 to 100 range can be used. This system is useful if you wish to use averages without locking values, if you have statistical data, or if you require independent probability.

Increment/Decrement System
This system is intuitive and easy to use. Values are added to or subtracted from the total points for a choice. A rule can add or subtract as much as 100 points from the total for a choice. At the end, the total value for a choice is displayed. This system differentiates among possible solutions that would provide similar or identical scores using other systems. For example, suppose Choice 1 received three values of 9 and Choice 2 received only one value of 9. In the 0-10 System, both Choices 1 and 2 would have the same final score of 9. But in the Increment/Decrement System, Choice 1 would have 27 and Choice 2 would have 9. Clearly, Choice 1 had been selected in more rules. Use this system if having multiple rules fire indicates a higher likelihood for a choice. If multiple rules do not indicate a higher confidence, the 0-10 system may be a better choice While locking a score is not possible using this system, a large number of points can be added or subtracted, thereby clearly pushing the value over or under the display threshold value. This system allows the end user to see a much wider point spread among selected solutions.

Custom Formula System


This is by far the most difficult of the systems to use and is not recommended for beginners. It should be used only when a problem cannot be solved using one of the other systems. In this system, the developer can write his own formulas for the combination of confidence values. This provides enormous flexibility. One method of combining confidence values can be used in one part of an expert system and another method in the rest of the system. Also, in addition to the confidence associated with a choice, this system allows both qualifiers and variables to have associated confidence values. The confidence values associated with qualifiers or variables can be asked of the user, set to default values, or derived from rules. The confidence of a choice can take into account the confidence of the qualifier or variables that indicated the choice. This flexibility allows very complex systems of confidence factors to be implemented. However, this system requires much more work by the developer of the expert system. Since the program does not have a default
C - RULE EDITOR
7

method of combining points assigned to choices, the formulas for handling the confidence scores must be part of the rules. This adds complexity and takes much more time than other systems. This system should be used only if you need to have the following elements in your system. 1. You require numeric confidence scores associated with qualifiers or variables. 2. You need to have user supplied confidence values for their answers that effect the final confidence values of choices. 3. Your require specialized formulas for combination of confidence values. In most cases, developing an expert system using one of the other Confidence Systems is faster and easier. However, the flexibility and power of the custom formula system can lead to solutions not found by the other systems. (See Section C40 for additional information.) Confidence System 0 or 1 When to Use

System does not require confidence factors. Choices can be positively selected or rejected in individual rules. Ranking of selected choices is not required.

0-10

Easy to usevery good for beginners. Allows confidence factors to be combined, without requiring complex formulas. Intuitive for most users to assign confidence factors. Most effective general purpose system.

-100 to 100

Provides finer resolution of confidence factors. Should be used only if statistical data is available with appropriate precision.
C - RULE EDITOR
8

Allows factors to be combined as dependent or independent probabilities. Increment/ Decrement Intuitiveeasy to use. Good for distinguishing between choices that would receive similar scores in other systems. Allows wide point spread in selected items. Custom Formulas Most flexible and powerful. Most complex and most difficult. Allows user supplied or derived confidence for qualifiers and variables. Allows any formula to be used to assign confidence values to a choice. Should only be used if none of the other systems can handle the problem.

C3.4: Calculation Mode


If the -100 to 100 Confidence Mode is select, the radio buttons for the Calculation Mode will be activated. (If any other Confidence Mode is selected, the Calculation Mode has no meaning and the radio buttons will be inactive.) The Calculation Mode selects how the values assigned to choices in the -100 to 100 mode will be combined. There are three options: Average, Dependent Probability and Independent Probability.

Average
The first is a simple average of all the individual values the choice received in the rules found to be true. This is the same as the 0-10 system, but no assigned values lock the final value. If this mode is selected, the full range of -100 to 100 can be used.

C - RULE EDITOR

Dependent Probabilities
The second combines the probabilities as if they were dependent probabilitiesthe probabilities are multiplied as percents. For example: if a choice appeared in two rules that were used, with values of 60/100 and 90/100, its final value would be (60% times 90% =54%) for a final value of 54/100. If this mode is selected, only the range of 0 to 100 can be used, since negative values have no meaning.

Independent Probabilities
The third way to combine the values is as if they were independent probabilities. In this system, the combination of the two probabilities is 1 minus the product of 1 minus the individual probabilities. 1-((1-Prob1) * (1-Prob2)) In the example above this would be 1-((1-60%) * (1-90%))=96% for a final value of 96. If this mode is selected, only the range of 0 to 100 can be used, since negative values have no meaning.

C3.5: Threshold Level For Display of Results


The threshold level determines which choices, based on their final values, are displayed in the final results screen. Only those choices with values greater than or equal to the threshold level are displayed as results. The default threshold is 1, which means all choices which receive a final value of 1 or greater are displayed in the program's results screen. In some cases, you may wish to show choices which receive a higher value. For example, if any choice which received a final value of less than 5 is too unlikely to be considered, setting the threshold to 5 would limit the display to only those choices which have a final value of 5 or more. This is especially useful in the -100 to 100 System in which choices with low values can be so unlikely that their display is not useful. The default value of 1 is a safe threshold to use while developing the system. This value can be easily changed later if you need to.

C - RULE EDITOR

10

C3.6: Derivation Mode


Next it is necessary to select which of the three options for deriving information from other rules should be used. EXSYS invokes appropriate rules in the expert system to derive the information as it is needed. The default option is to apply all possible relevant rules. This is a safe selection, but in some cases it can lead to unnecessary questioning of the end user. Therefore, EXSYS allows the developer to control the depth of search that will be made.

All Possible Rules


The "attempt to apply all possible rules" mode invokes all possible relevant rules that can derive needed information. Even if one rule is found to be true, the remaining rules are still tested. If, due to the logic of the rules, the additional rules do not provide more information, this may lead to unnecessary questions being asked of the end user. However, this is always a safe mode to use while developing the expert system. The mode can be easily changed later if you need to.

First Successful Rule


The "stop after first successful rule" mode does not invoke additional rules after the first relevant rule is found to be true. If all of the needed information about a qualifier can be provided by a single rule, this is the appropriate system. This also allows the program to run a little faster. This system is not appropriate if deriving information requires several rules to provide parts of the total information.

Non-redundant Rules
The "apply all non-redundant rules" mode is appropriate for most cases. A rule is redundant if it supplies no additional information, regardless of whether it is true or false. In this system, after one rule has been determined to be true and provided information, additional rules are invoked only if they add more information. Rules that would not add information, even if they were true, are not invoked. This system is appropriate unless l. Backward chaining is being used as a control mechanism to force rules to fire for procedural reasons. In this case, use "attempt to apply all possible rules." (It is better to use the command language for such procedural control. See Chapter J for more information.) 2 Information on the qualifier or variable is provided by a single rule firing. In this case, "stop after the first successful rule" may produce slightly better speed.

C - RULE EDITOR

11

The difference between the modes is easier to understand if you look at an example of how they work on different problems. For example: Rule 1: IF Wood is needed THEN The shipment includes wood Rule 2: IF Construction materials are needed THEN The shipment includes wood Rule 3: IF Plastic is needed THEN The shipment includes plastic If the program is attempting to derive information on "The Shipment" with the "attempt to apply all rules" option, it will test all rules that have some information on "The Shipment" in their THEN part. 1. The program will test Rule 1. 2. Even if Rule 1 is true, Rule 2 will be tested. 3. Even if Rule 2 is true, Rule 3 will be tested. Since each rule could provide information on "Shipment", each is tested. With the "stop after first successful rule" option: 1. The program will test Rule 1. 2. If Rule 1 is true, the program will successfully derive some information on the contents of "The Shipment" and rules 2 and 3 will not be tested.

C - RULE EDITOR

12

3. If Rule 1 is false, Rule 2 will be tested. If Rule 2 is true, the program will successfully derive some information on the contents of "The Shipment" and Rule 3 will not be tested. 4. If Rules 1 and 2 are false, the program will still not know anything about "The Shipment" and Rule 3 will be tested. If the shipment only includes one material, this might be a good mode to use since it minimizes the number of rules tested. With the "apply non-redundant rules" option: 1. The program will test Rule 1. 2. If Rule 1 is true, Rule 2 will be ignored because the program will already know "The Shipment" includes wood. Rule 2 can add no additional information and is therefore redundant. 3. The program will then test Rule 3 since it adds information (plastic) which is not redundant with existing information, even if rules 1 or 2 are already known to be true. Using the non-redundant option usually avoids unnecessary questions, while still allowing all information to be derived about a specific qualifier.

C3.7: Rule Display Mode


Select the mode to use for Rule Display while the system is running. Click on the appropriate radio button.

Display Rules
The Display rules as they are used means all rules are displayed immediately after they fire. This can be useful for many things, including development or providing information to the end user in rule notes. However, usually end users find this mode annoying and there are alternative ways to present the required data to the end user in a more convenient form (e.g. DISPLAY commands, report generator, custom screens)

Not Display Rules


This mode will not display rules when they fire, but will allow the end user to have rules displayed and to ask about rules with the HOW and WHY commands. This is the most commonly used system since it allows the end user to fully interrogate the expert system on the basis for the recommendations.
C - RULE EDITOR

13

Lock Display Off


The Lock Display Off mode prevents the end user from examining the rules at allthey are "locked out." The information in an expert system can represent very valuable knowledge. In some cases, the knowledge in the system should be protected, even though the problem-solving capability of the system must be disseminated. The Displays Off mode locks the rule display, so the end user cannot see the rules at all, even with the WHY or HOW commands. The end user cannot override the option. If the developer selects this option, he must also select the password option when storing the system. Locking the rules applies ONLY to the Runtime and has no effect on running the rules within the Rule Editor during development.

C3.8: Starting Text


EXSYS provides the option for the developer to write explanatory text which is displayed at the beginning when the knowledge base is run. This explanatory text is primarily for the end user. Using starting text, the developer can explain what the knowledge base does and what the end user might expect from the program. The text is optional, but its presence can make the system easier for the end user. This is a good place to provide comments to the user about what input is expected, what measurement units to use, who to contact with questions, or provide any other information the end user may need. To enter starting text, click the Starting Text button, and a window will appear. Enter the text you wish to appear on the screen, then click on the OK button. This text can be edited later if you need to.

C3.9: Ending Text


EXSYS also provides the option for the developer to write explanatory text which is displayed at the end of a run, just before the conclusions are displayed. This explanatory text is primarily for the end user. The developer can explain what the results mean, what thresholds are set or what actions should be taken next. The text is optional, but its presence can make the system easier for the end user. To enter ending text, click the Ending Text button, and a window will appear. Enter the text you want to appear on the screen, then click the OK button. This text can be edited later if you need to.
C - RULE EDITOR
14

C3.10: Starting External Program


The developer can require the call of an external program at the start of a run. An external program is any program that can be run from the operating system. It can be a database, spread sheet, graphics program, video disk driver, or custom user program written in any language including interpreted languages such as BASIC. In the MSWindows version, the program can be either a Windows based or non-Windows (DOS) program. To enter the name of the external program, click on the Ext. Prog. button and a window will appear. Enter the name of the program as it would be entered at an operating system prompt. Data can be, and usually is, passed back to EXSYS from the external program. This data would be used during the running of the expert system. (See Chapter H for more information on calls to external programs.) The external program specified at this point is always called at the start of a run and is not associated with any particular data elements in the expert system. The external program can provide all or part of the information needed by EXSYS to reach its conclusions. Embedded systems can easily be created using this technique. In such systems, all the information needed by the expert system is provided by the called program. The end user has little or no direct interface with the expert system. Embedding is a very powerful way to add expert system analysis capability to other programs. It works especially well with programs which contain a large amount of data but lack sophisticated ways to analyze that data. EXSYS has many other ways to call external programs which are discussed later in Chapter H.

C3.11: Initial Choice Value


If the Custom Formula Confidence Mode is selected, the buttons for the Initial Choice Value will be enabled. In this mode, all choices must be given an initial value. This value is then used in confidence formulas to arrive at the final value for the choice. For more detail on using custom formulas for confidence calculations, see section C40 on Confidence Formulas. To set the initial choice value, click the Init Choice Value button. Enter the value desired in the window that will be displayed, and click OK.

C - RULE EDITOR

15

C3.12: Finished Setting Parameters


This completes the description of parameters set at the start of a new expert system. These parameters need be set only when creating a new expert system. When the parameters are set, click the OK button. The Subject and Author fields must be completed before you can proceed. The other parameters are set to their normal default values. You will be able to change most of these parameters later by selecting the Parameters menu item from the Options menu. The confidence mode can not be changed once you start adding rules, so make sure your selection is correct. (It is possible to change the confidence mode of a system later, but it requires use of the EXSYS Rule Compiler and also usually requires substantial editing of the rule text file.).

C3.13: Entering Choices


You will next be asked to input the choices. These are the goals or options that the system will decide among. If the system were medical, it might be the diseases covered by the system. If it were a help desk, the choices would be the possible problems that the system could diagnose. When prompted, enter the first choice and click OK. You will be asked for another choice. Continue entering choices until all of the ones you think you will use are entered. You can always add more, or delete, choices later. If you wish to examine the choice already entered, click Cancel and a list of the choices will be displayed. To add more to the list, click on New Ch. and continue adding choices. When all choices have been added, click Cancel and then click OK in the choice list dialog box. A short cut is to just press the RETURN key when asked for a choice, and then the RETURN key again to select the default OK button.

C - RULE EDITOR

16

C4: Main System Title Screen


Once a new expert system has been created, or an existing system has been read, the system title screen is displayed.

Title

Author

C - RULE EDITOR

17

C5: Saving the Changes to a Knowledge Base


File Edit Rule Options KBfiles Questions New Open Save Save As Revert to Saved Print Exit About

It is a good idea to periodically save to disk the work done on the expert system. This is especially true when testing custom written external programs. EXSYS maintains most of the expert system in memory. If the system crashes, all work since the last save will be lost. Selecting Save from the File menu will save the knowledge base to disk. If any rule editing windows are open, you will be asked if you wish to save the changes made in those windows before the rules are saved to disk. If you attempt to exit EXSYS without saving your work, you will be prompted to save the rules before exiting.

Password Protection
EXSYS provides optional password protection for encryption of a knowledge base file. When the rules are saved, the program will ask if password protection is desired.
Use Passwords? NO YES

If the option of locking out rule display was selected, the password option must be used. Locking the rule display prevents someone with only the Runtime password from accessing or examining the rules with WHY or HOW. Once locked, the rules can be unlocked only with the Edit password. If password protection is used, the rule display locking option may be selected from the Options Menu selecting Parameters, then clicking Lock Display Off. Locking of

C - RULE EDITOR

18

rule display applies only to the Runtime program, not running the rules from within the Editor. If password protection is selected, the program prompts for an Edit password and a Runtime password. These should be alphanumeric strings of 6 or more characters in length. The program has two password access levels, requiring two different passwords. The Runtime password allows an end user to run the knowledge base with the Runtime Program but not to edit or change any of the rules. The Edit password allows access to the knowledge base with the Editor Program. The Edit password does not work with the Runtime program.

Edit Runtime Use Passwords? NO Show Current Passwords YES Hide typing OK Cancel

If password protection has already been selected, the default passwords will be the existing passwords. These can be displayed by clicking Show Current Passwords. Normally, when the passwords are typed, they will be displayed in the editing box. However, if the situation requires that the passwords not be echoed to the screen, click on the Hide Typing box. In this case, the passwords will not be echoed to the screen. Instead, after the passwords are entered, the program will ask you to input the passwords again to confirm the correct input. Use care when using this option since it is possible to make a typographical error both times, in which case the system will be encrypted and you will not know the password. If passwords are not used, EXSYS creates unencrypted knowledge base files.

C - RULE EDITOR

19

C6: Exiting the Editor


File Edit Rule Options KBfiles Questions

New Open Save Save As Revert to Saved Print Exit About

To exit the EXSYS Editor, go to the File menu on the menu bar and select Exit. If any edit rules are open and have been edited, you will be asked if you wish to save changes to those rules. If the knowledge base has been edited, you will be asked if you wish to save changes to the knowledge base. Macintosh Note: On the Mac, this menu entry is QUIT, not EXIT.

C - RULE EDITOR

20

C7: System Help


File Edit Rule Options KBfiles Questions

New Open Save Save As Revert to Saved Print Exit About

To get help in using EXSYS Professional, select About from the File menu. Macintosh Note: On the Mac, there is no About menu item, instead select the About EXSYS menu item under the Apple menu. This will bring up a dialog box with a HELP button.

EXSYS Professional Editor Version 5.0 1983-1996 EXSYS, Inc. Albuquerque, NM

Cancel

Help

Click on the help button. In Microsoft Windows, you can simply press the F1 key to get to the system help functions. Help is also available by selecting the Help item from the Options menu.

C - RULE EDITOR

21

A window will appear with a list of help topics.

Select help topic...

Help topics

Fresh Window

Cancel

Help

To get more information, either double click on a help topic, or select a help topic with a single click and then click on the Help button. A window will display information on the selected topic. If you wish to have the help information on the topic placed in a new help window, click the Fresh Window button.

Help Information

Cancel

Prev

Next

Topics

C - RULE EDITOR

22

Click the Prev button to see the information on the previous topic in the help topic list. Click Next to see the information on the next topic in the help topic list. Click Topic to bring the help topic list window to the front. Click Cancel when done. Clicking Cancel in either the Help Topic window or the Help Text window will close both windows. There is fairly extensive help information in the Help Topics, and many questions can be answered without referring to the manual. This is especially true for the syntax of the various commands in EXSYS, such as custom screen command, configure options, and report generator commands.

C - RULE EDITOR

23

C8: Copying Text from Other Applications


File Edit Rule Options KBfiles Questions

Cut Copy Paste

Text can be transferred from other applications and copied into EXSYS or cut from EXSYS in any place where text input is expected in a window. It is not possible to use these commands for input requested by dialog boxes, since the main menu bar is inactive when the dialog boxes are displayed.

C - RULE EDITOR

24

C9: Adding a New Rule to the Knowledge Base


File Edit Rule Options KBfiles Questions

Add Rule Edit Rule Delete Rule Move Rule Use Rule Names Qualifier List Variable List Choice List Condition Cut Condition Copy Condition Paste

To add a new rule, go to the Rule menu on the menu bar and select Add Rule from the pull down menu. The window that appears is similar to the one which is used for editing a rule, but the rule will be empty. EXSYS keeps track of the rule numbers internally, and will assign the number to the rule automatically. See the section below on Editing a rule for the details on adding conditions to the rule.

C - RULE EDITOR

25

C10: Editing a Rule in the Knowledge Base


File Edit Rule Options KBfiles Questions

Add Rule Edit Rule Delete Rule Move Rule Use Rule Names Qualifier List Variable List Choice List Condition Cut Condition Copy Condition Paste

To edit an existing rule, go to the Rule menu on the menu bar and select Edit Rule from the pull down menu. A dialog box appears which asks you to select the rule that you wish to edit.
Name: AA AB ABCD BBBB CCC DDDD EEEE FFFF Number: 1 2 3 Edit 4 5 Runtime 6 Use Passwords? NO 7 Show Current Passwords 8 YES Hide typing Last Cancel

Enter Rule Name or Number: OK

Cancel OK New Rule

C - RULE EDITOR

26

The name list box contains the names of all of the named rules in the system, arranged alphabetically. The Number listbox contains a list of the numbers of each rule in the system. To select a rule, either 1. Click a rule number and then click the OK button. 2. Click a rule name and then click the OK button. 3. Double click a rule name or number. 4. Enter a rule number or name in the edit field. When a rule name or number is selected, the corresponding number or name will be highlighted in the other list box. To start a new rule, click the New Rule button. To edit the last rule entered, click the Last button and click the OK button. Note: For large systems with many named rules, creating and alphabetizing the list of rule names can be a little slow. To disable the display of the rule names (but still allow a rule to be called by name in the edit field), go to the Rule menu on the main menu bar and select Use Rule Names. If this item is checked, rule names will be used, if it is not checked, rule names will not be displayed.

File

Edit

Rule

Options

KBfiles

Questions

Add Rule Edit Rule Delete Rule Move Rule Use Rule Names Qualifier List Variable List Choice List Condition Cut Condition Copy Condition Paste

C - RULE EDITOR

27

After a rule is selected, or a new rule is started, the main Rule window will be displayed. You can work on several rules at the same time and you can open up to 10 Rule windows simultaneously.

Rule Title and Number IF: Qualifier Var. / Math Choice Command Repeat IF Part THEN Part ELSE Part Insert AND OR New OR Change Delete And/Or Cancel Note Reference Name

OK

Prev

Next

Three main types of conditions can be added: qualifiers, choices and mathematical expressions.

C11: Building a Rule


A rule is built by creating conditions in the IF, THEN, and ELSE parts of the rule. All rules must contain an IF part. The IF conditions are statements that can be determined to be true or false. In a well written rule, the conditions are easily read text statements or mathematical expressions.

C11.1: Positioning of New Conditions


The location that the new condition will be added depends on the Insert status.

C - RULE EDITOR

28

When a new rule is started, the mode is set to add conditions to the end of the IF part. When the IF part is complete, click on the THEN Part radio button. To add a condition to the end of the IF, THEN or ELSE part 1. Click on the radio buttons labeled IF Part, THEN Part or ELSE Part. 2. Click on Qualifier, Variable, Choice or Command and build a condition, or select Condition Paste from the Rule menu. 3. The new condition will be added at the end of the section. To add a condition somewhere other than the end of a section: 1. Click the Insert box. This puts the rule in insert mode. 2. Highlight a condition in the rule by clicking it. 3. Click Qualifier, Variable, Choice or Command and build a condition, or select Condition Paste from the Rule menu. 4. The new condition will be added just before the highlighted condition. All subsequent conditions in the rule will have been moved down one. The selected condition will remain selected. (If no condition is selected, the new condition will be added to the end of the currently active section.) The "end of section" and insert modes can be mixed simply by clicking on the Insert box.. To return to the IF part after the THEN part has been started, simply click on the IF Part button.

C11.2: Adding a Qualifier Condition


Qualifiers are multiple choice lists. Many factors in a decision-making process are best expressed as multiple choice lists. To add a qualifier condition, click on the Qualifier button in the Rule window. A dialog box will appear for adding a qualifier condition.

C - RULE EDITOR

29

Qualifier Select qualifer by text or name: Find Find Again Name

QUALIFER LIST

ASSOCIATED VALUE LIST

Edit OK NOT Delete

New Qual. Cancel

The Qualifier List area will contain a list of all of the qualifiers known to the system. If you click on a qualifier, the list of values associated with that qualifier will be displayed in the lower window. The meaning of "qualifier" and "associated values" are explained below in the section on adding or editing a qualifier.

C - RULE EDITOR

30

C11.3: Adding / Editing a Qualifier


To add a new qualifier or edit an existing qualifier, select a qualifier from the qualifier list and click on the Edit button or click on the New Qual button. The Add/Edit Qualifier window will be displayed.
Add / Edit Qualifier Qualifier ## NEW QUALIFIER Name:

QUALIFER TEXT ASSOCIATED VALUE LIST

Edit

Replace

Cancel Edit

Add

Delete

VALUE WORK WINDOW


Display at end Limit input values to: Default Value: Conf. Options Data Acqu. Cancel

OK

Qualifier and their associated values are simply multiple choice lists. Typically, the qualifier is part of a sentence up to and including the verb. "Values" are the possible completions of the sentence that the user is able to select among. A qualifier can have a maximum of 30 associated values. The text of the qualifier is edited in the top edit region. The qualifier text can be directly edited. If this is a new qualifier, the word "Qualifier" will appear here. For new qualifiers, replace the word "Qualifier" with the actual text of the qualifier. To do this, drag across "Qualifier" or double click on it to highlight it. Then type the text of the qualifier. The bottom edit region also has the word Values. This is replaced with the actual values you wish to use. After the text of a value is entered, click on the Add button to add it to the list in the middle listbox. Notice that when text is entered in the "value" edit region, pressing <ENTER> (<RETURN> on some machines) will add the value to the list. For example, suppose we are creating an expert system to identify flowers and we want to create a condition dealing with the color of
C - RULE EDITOR
31

the flower. We would click on New Qual in the Qualifier window. The new qualifier window would be displayed. Replace the word "Qualifier" in the top edit region with THE COLOR OF THE FLOWER IS. Enter the list of values that the user may select among. In this example, the qualifier can have the values RED, BLUE, YELLOW and WHITE. Replace the word "Values" in the lower edit region with the first value "RED" and click the Add button or press <ENTER>. RED will appear in the middle list box as the first value. Enter "BLUE" in the lower edit region and click Add. BLUE will appear as the second item in the value list. Do the same for YELLOW and WHITE. The result will look like:
Add / Edit Qualifier Qualifier ## NEW QUALIFIER Name:

QUALIFER TEXT ASSOCIATED VALUE LIST

Edit

Replace

Cancel Edit

Add

Delete

VALUE WORK WINDOW


Display at end Limit input values to: Default Value: Conf. Options Data Acqu. Cancel

OK

C11.4: Editing an Existing Qualifier Value


The middle listbox contains a list of the possible values associated with the qualifier. These values can not be directly edited, but must be moved to the lower Value Work Window. To do this, select a value by clicking it and then click the Edit button. The value will appear in the work window, where it can be edited. When the changes are made, click the Replace button to replace the existing value with the edited value or Add to add a new value to the list.

C - RULE EDITOR

32

Note: When an edit to a value is accepted by pressing the Replace or Add button, it immediately takes effect. Pressing the Cancel button will not undo it. Pressing the Cancel before the value is accepted will cancel the edits made in the work window. Not all values for the qualifier may be able to be displayed at one time. If there are more values than can be displayed, the listbox will have a scroll bar on the right side.

C11.5: Deleting an Existing Qualifier Value


To delete a qualifier value, select the value and click the Delete button. EXSYS will check all the rules to determine if the selected value is in use in a rule. Values can be deleted only if they are not used. If the value is found to be in use, a list of the rules using the qualifier will be displayed. These rules must be modified to not use the value prior to deleting the value.

C11.6: Options for Each Qualifier


Each qualifier can have several parameters set that effect how the qualifier will behave or be referenced. The parameters set for a qualifier can be changed later. Each qualifier can have different parameters, giving the developer a great deal of flexibility. The parameters are set / edited from the Add / Edit Qualifier window.

C11.7: Qualifier Name


The first parameter is an optional name to associate with the qualifier. To add a name to the qualifier, enter a name in the edit field labeled "Name". This name can be used from the Command Language and some internal EXSYS commands. Referring to the qualifier by number is always available, but having a name is more convenient in some applications. The name of a qualifier is limited to 16 characters, including spaces. If the command language, CLEAR commands, or external programs are not used, naming the qualifier probably is not necessary.

C - RULE EDITOR

33

C11.8: Display of Qualifier Values with Results


The qualifier can be displayed in the Results Screen at the conclusion of the run. The usual selection is to not display the qualifier. However, if the qualifier provides some information that should be displayed to the user along with the conclusions, it can be done. Qualifiers that are derived from other rules or obtained from external programs are often displayed. To indicate that the qualifier should be displayed, click the check box labeled "Display at end".

C11.9: Maximum Number of Values


When the expert system is run, the user is able to select the value, or values, that are appropriate from the list associated with the qualifier. EXSYS normally allows the user to select multiple values or even all the values. In some cases, the developer may want to limit the user to the selection of one or only a few values from the list. This is useful when selecting several values is logically inconsistent. Being able to force the user to select only a single value makes the logical structure of the rules much less complicated. Otherwise, the system would have to account for logically inconsistent input in the rules. To limit the number of values that can be input, enter the maximum number of values that should be accepted in the edit field labeled Limit input values to. Using the flower color example from before, you may want the user to be able to select only one color for the flower. To do this, enter "1" in the edit field labeled Limit input values to. Now when the system is run, the user will be allowed to input only a single color for this qualifier. Usually, a qualifier will be limited to a single value or allowed to have all values selected. Limiting the user to only two or three values is possible but is often not logically necessary. Note: Even though a qualifier may only allow the end user to select a single value, the developer can still select multiple values when building the rule.

C11.10: Default Value


Normally, when information on a qualifier is needed, the system first tries to derive information from other rules. If the information is not available that way, the user is asked to provide the information by
C - RULE EDITOR
34

selecting from among the possible values of the qualifier. In some cases, the developer may not want a qualifier asked of the user. Perhaps the qualifier asks a more complex question than the user would be expected to answer. In such cases, setting a default value guarantees that the user will never be asked about the qualifier, regardless of other input. The default value should be used rarely, and only in very special cases. The default is a value to be used instead of asking the user for input. Once a default value is set, the user is never asked to provide input on that qualifier. However, if data on the qualifier can be derived from other rules or external sources, the default value will not used. To set a default value, enter the number of the value to use in the edit field labeled "Default Value". Only a single value can be selected as the default. For example, suppose we have a qualifier: The color is 1 red 2 white 3 blue 4 green We could set a default value of 3, blue. When the program needed to know the color, it would first check to see if any information was already available from external programs or other rules that had fired. It would then check the rules to see if any rules could provide information on the color. If any rules were found, they would be tested. If, after testing the appropriate rules, a value had been set for the qualifier, the default would not be used. However, if after testing the other rules, nothing was known about the qualifier, the default value of 3 would be set and the program would continue. The user would never be asked about the color. Note: Default values for qualifiers are different from initial values for variables. The initial value of a variable is always set at the start of a run. It is set regardless of other rules that provide information about the variable. Default values for a qualifier are used only if no other method provides the information. They are set only when needed.

C - RULE EDITOR

35

C11.11: Automatic Data Acquisition


Many external sources can be used to automatically set the qualifier's value, rather than asking the user for information. Data can be obtained directly from spreadsheets, databases, the blackboard, a frame, graphics and many other sources. To associate a data acquisition command with the qualifier, click on the Data Acqu. button. A list of the possible data acquisition commands will be displayed. A source for the data can be selected, and EXSYS will prompt the user for the information needed to build the data acquisition command. (See Chapter G for more information on data acquisition commands).

C11.12: Custom Formula Systems


If the confidence system using custom formulas was selected, other options for the qualifier relating to user-supplied confidence, default confidence values, and ranges are available. To set these options, click on the Conf Options button. (See Section C40 on using the Custom Formula system for more information on these options.)

C11.13: Finished Setting Qualifier Parameters and Values


When all values have been entered and parameters set, click the OK button to return to the Qualifier Window. The values and parameters can be changed later from the qualifier list window by clicking a qualifier to select it, then clicking the Edit button.

C - RULE EDITOR

36

C12: Selecting Qualifier Values to Build a Condition


Qualifier conditions are built from the Qualifier list window.
Qualifier Select qualifer by text or name: Find Find Again Name

QUALIFER LIST

ASSOCIATED VALUE LIST

OK

Edit NOT Delete

New Qual. Cancel

Click on the qualifier you wish to use. Once a qualifier is selected, its associated values will be displayed in the value listbox. To build a condition, click the values you wish to use. If you want to use more than 1 value, click several. All highlighted values will be used. If a value is selected, clicking it again will de-select it. Click the OK button when you are finished selecting your values. A double click on a value also indicates that the selection is complete. The qualifier condition you have selected will be added to the rule. In the IF part, you may also use NOT in association with values. To use NOT, click the box in front of NOT, and an X will appear in the box. This will build a condition of the form qualifier is NOT value, rather than the normal form of qualifier is value. After selecting NOT, select the values in the usual way. If the number of an already entered qualifier is unknown, do not create a new qualifier and list of values identical to the previous entry because the program does not know they are the same and therefore asks the user for the same information twice. Instead, use the existing qualifier. To FIND a qualifier with specific text in it, click on the FIND button. You will be asked for the text to find, and if the qualifier, values or names are to be searched. When you click

C - RULE EDITOR

37

Search, the first qualifier with the specified text will be displayed. To search for the next occurrence of the text, click on Find Again. To select a qualifier by name, click the Name button. A list of all of the qualifier names will be displayed. Click the name you wish to use. Using the previous example, suppose you want the IF condition to say THE COLOR OF THE FLOWER IS RED. The qualifier would be displayed as
Qualifier Select qualifer by text or name: Find Find Again Name

THE COLOR OF THE FLOWER IS THE FLOWER STEM IS THE CENTER OF THE FLOWER IS THE SIZE OF THE FLOWER IS 1 RED 2 BLUE 3 YELLOW 4 WHITE
Edit OK NOT Delete Cancel New Qual.

Since you want RED, you would click "1 RED", and click OK, or double click RED. If you want the condition THE COLOR OF THE FLOWER IS BLUE OR YELLOW, click "BLUE" to select it , then click YELLOW to that color as well. If you want THE COLOR OF THE FLOWER IS NOT WHITE, click NOT, then click WHITE. When the OK button is clicked, the condition will appear in the rule. If multiple values are selected for a qualifier in the THEN/ELSE part, they will be connected by "and" rather than or, as they were in the IF part. This is because in the IF part, if any of the values are true, the rule is true. The IF values are ORed. In the THEN part, all the values are true if the IF part is true, so the THEN values are ANDed. The form "NOT" plus value number(s) cannot be used in THEN/ELSE qualifiers. The conditions in the THEN part must be affirmative.

C - RULE EDITOR

38

C12.1: Adding a New Value


A new value can be added to the list by selecting the qualifier and clicking on the EDIT button. Enter the new value for the qualifier and click the ADD button (this is the same thing as entering values for the new qualifier). Up to the maximum of 30 values can be associated with a qualifier.

C12.2: Correcting Typographical Errors


If a typographical error was made in the text of the qualifier or any of its values, or if rephrasing is desired, select the qualifier and click the EDIT button. The qualifier text can be edited directly. To edit a value, select the value and click on the EDIT button. The value will appear in the lower edit window. Make the required changes and click the REPLACE button. Note: If a qualifier or value is changed, it is automatically changed in all rules where it appears.

Deleting a Qualifier
If a qualifier with all its values needs to be deleted, select the qualifier and click the Delete button. The program checks all the rules to see if the qualifier is used in any rule. If it is not used, it is deleted and the remaining qualifiers or values are renumbered accordingly. If the qualifier or value is found to be in use, it cannot be deleted. The program instead displays a list of the rules in which the value is used. The rules must be edited so the qualifier is not in use before it can be deleted. This prevents accidentally deleting a data element that is expected when the rules are run. To delete a single value from the qualifiers list, select the qualifier and click the EDIT button. Select the value to delete and click Delete. As with qualifiers, if the value is used in the rules, it cannot be deleted.

C12.3: Qualifier Conditions Combined with OR


Several qualifiers can be combined with OR to produce OR blocks in a rule. OR blocks can only be created in the IF part of a rule, and make sense only in the IF part.
C - RULE EDITOR
39

If any condition in an OR block is true, the entire block is true. Groups of OR blocks can be ANDed to make complex statements. For example: IF: AND AND The color is red Today is Monday The weather is hot

will be true only if all three conditions are true. On the other hand, IF: AND OR The color is red Today is Monday The weather is hot

will be true if "The color is red" and either the second or third condition is true. The "OR" at the start of the third condition indicates an OR block, which is ANDed with the first condition. IF: OR OR The color is red Today is Monday The weather is hot

will be true if any of the three conditions is true.

We could also create two OR blocks, such as: IF: The color is red OR Today is Monday AND The weather is hot OR The price is low Now either the first or second condition must be true, and either the third or fourth condition must be true. The AND in front of the third condition indicates two OR blocks ANDed together. When the rule is tested, the program asks the minimum number of questions. If any condition in an OR block is known to be true, the other conditions in the block are not tested.

C - RULE EDITOR

40

An OR block is created by starting a new rule. The AND radio button will be highlighted. To start an OR block, click the OR radio button and enter a qualifier condition. The OR button will stay highlighted, and multiple qualifier conditions can be entered which will all be part of the same OR block. To return to ANDing conditions, click on the AND button. To start a new OR block, which will be ANDed with the previous OR block, click on the New OR button.
Rule Title and Number IF: Qualifier Var. / Math Choice Command Repeat IF Part THEN Part ELSE Part Insert AND OR New OR Change Delete And/Or Cancel Note Reference Name

OK

Prev

Next

For example to build: IF: OR AND OR The color is red Today is Monday The weather is hot The price is low

Click the OR button and enter the condition "The color is red". Then enter the condition "Today is Monday". The OR button will still be selected and the two conditions will be part of the same OR block. To start the second OR block, click New OR and enter "The water is hot". EXSYS will automatically switch back to the OR button from the New OR button. Now enter "The price is low" and the IF part is complete.

C - RULE EDITOR

41

C13: To Change the AND / OR Blocks


To change the AND and OR blocks in a rule, press the AND/OR button in the rule window. You will be presented with each of the IF qualifier conditions in the rule sequentially.
Condition #1 / 5

Text of condition

AND Part of OR Block Last OR in Block Cancel OK

To AND with the previous qualifier, select AND and press the OK button To start a new OR block, or OR the qualifier with the previous qualifier, select Part of OR Block and press the OK button. To indicate the last OR in the block, select Last OR in Block and click the OK button. This is only necessary if you wish to immediately start another OR block. If subsequent conditions are ANDed, you can simply press AND for the next qualifier. The program will tell you if a condition is not a qualifier condition. It is not necessary to indicate the last OR in a block unless a new OR block is being started. The program will automatically mark the last OR in the block.

C - RULE EDITOR

42

C14: Using Qualifiers


When a qualifier is defined, you should consider the needs of your end userhaving consistent types of values makes EXSYS easier to use. For example, if a qualifier deals with an item, do not mix color descriptors (black, yellow, green) with shape descriptors (big, small) in the same qualifier. If a description of different features of the same item is necessary, the same qualifier text can be used more than once. The program keeps track of the qualifier by number, not text. A system could possibly have these two qualifiers: THE LEGS ARE YELLOW GREEN THE LEGS ARE SHORT LONG

However, using exactly the same qualifier may cause some confusion to the end user and definitely causes problems for the Rule Compiler. A better approach would be THE LEG COLOR IS ... AND THE LEG LENGTH IS... Occasionally you may want to use a condition such as A can be X or Y but not Z. This can be done by repeating a qualifier in the IF part. Suppose possible values for a bird's leg color are black, yellow, green, and red. A condition says leg color can be yellow or green but not black. This is accomplished by using two IF conditions: IF THE BIRD'S LEG COLOR IS YELLOW or GREEN AND THE BIRD'S LEG COLOR IS NOT BLACK Both statements must be true for the rule to be true. If the user inputs both yellow and black in answer to the program's query about leg color, the first condition would be true but the second would be false. When creating rules, all IF conditions and OR blocks in a rule must be true for the THEN conditions to be considered true. However, in a given condition that has multiple acceptable values for a qualifier, only one value need be true for the condition to be true. Since the program checks the conditions in a rule in the order they appear, the most general conditions should appear first. If the
C - RULE EDITOR

43

program determines that a frequently used condition is false, it may be able to eliminate a large number of rules without asking the user unnecessary questions. If the expert system is asking unnecessary questions, it may need more general conditions at the start of some rules. The ability to copy conditions from previous rules and reorder conditions makes it easy to add general conditions to rules.

C - RULE EDITOR

44

C15: Mathematical Expressions and Variables


Variables and mathematical expressions are used for a variety of functions in EXSYS . Mathematical expressions can be added in both the IF (to test a value) and in the THEN/ELSE parts (to assign a value). EXSYS supports mathematical expressions with boolean operators, trig functions and a variety of special functions to describe complex relationships.

C15.1: Variables
A variable is any string of alphanumeric characters, including spaces, enclosed in brackets [ ]. Only the first 18 characters are significant. Only letters, digits, and spaces can be used in variable names. Variable names should be descriptive of what they represent. The following would be valid variable names: [COST], [COST OF SYSTEM], or [X]. The following would not be valid because they include illegal characters: [X#], [X/Y] or [NAME 1.2]. These are not valid names because they all include characters other than letters, digits and spaces. EXSYS supports only three types of variablesnumeric, string and text-only. Numeric variables can be assigned a numeric value. String variables can be assigned a string value, and text-only variables take no value but are used to display special text to the user. As with qualifiers, when the system needs the value of a variable to evaluate an IF expression, backward chaining will invoke the rules that assign a value to the variable in the THEN/ELSE parts to determine the value.

C15.2: Math Expressions in the IF Part


In the IF part, variables are used to form an expression that can be evaluated to TRUE or FALSE. This requires the expression to contain a conditional operator to test the left and right side of the expression. For example, you might have the following expression: [X] > 0. It is important to remember that IF conditions are always expressions which can be determined to be TRUE or FALSE.

C - RULE EDITOR

45

Additional details on conditional operators and mathematical expression syntax are described below.

C15.3: Math Expressions in the THEN/ELSE part


Math expressions are expressed differently in the THEN/ELSE part. In the IF part, the expressions are tests for validity, while in the THEN part, the expressions are assignments of value to a variable. For example, in the IF part "[X] = 5" means "If the value of [X] is 5, the statement is true." In the THEN part, values are assigned to variables and the expression would be phrased "[X] IS GIVEN THE VALUE 5" which means, "assign the value 5 to the variable [X]."

C15.4: Building Math Conditions in a Rule


To add a mathematical expression to a rule, click the Var / Math button in the rule window.

IF Part
If you are adding a condition to the IF part of the rule, a window will appear for you to enter the expression you wish to add.
Add Formula Please enter a formula

OK

Display Variables

Cancel

Enter a formula that can be tested as a boolean expression (such as the formula [X] > 0). To see a list of the variables currently defined in the system, click the Display Variables button. The expression you enter can contain new variables. EXSYS will automatically check for new variables and ask you to set the parameters for them. If a new variable is found in the expression, EXSYS will display the Add/Edit Variable window which is described later.
C - RULE EDITOR
46

EXSYS will also perform a syntax check of the expression you have entered and warn you of any syntactical errors.

C15.5: THEN / ELSE Part


In the THEN/ELSE part, the condition will be an assignment of a value to a variable. In that case, you must first select the variable to assign the value to, then input the value or expression to assign to the variable. EXSYS first asks you to select the variable to assign the value to. This can be an existing variable, or a new variable. Since the assignment is usually made to an existing variable, the list of variables in the system is displayed. The variables are arranged alphabetically.
Variables

OK

VARIABLE LIST
Numeric String Text Only Edit Options New Variable

VARIABLE TEXT

Cancel

When a variable is selected from the list by clicking on it, its type is displayed by having the Numeric, String or Text Only button selected. The prompt text of the selected variable will be displayed at the bottom of the window. These variables can not be edited or changed from this window. They are presented for information only. To change the parameters for a variable, select a variable and click the Edit Options button. Either select a variable from the list to assign a value to, or click on New Variable to add a new variable to the system. If a variable is selected from the list, either click the variable and then click the OK button, or double click the variable you wish to use.

C - RULE EDITOR

47

If you have selected to either edit an existing variable or add a new variable, the Add /Edit Variable window will be displayed. If editing an existing variable is selected, the current parameters for the variable will be filled in.
Add / Edit Variable Name: Prompt:

Numeric String Text Only Display at end OK

Initialize: Upper Limit: Lower Limit

Data Acquisition Conf. Options

Cancel

C15.6: Variable Parameters


Each variable has a variety of parameters that can be set.

Variable Name
Each variable must have a unique name. The name can be up to 18 characters in length and can contain spaces. Try to make the name descriptive of what the variable represents. EXSYS requires you to use a name.

Variable Prompt
Each variable must have associated text that will be used when asking the user for the value of the variable or for displaying the value of the variable. Usually this text should describe what the variable represents (the exception to this is Text-Only Variables, described below). The variable name used in the formula should only be descriptive enough to identify what the variable means, but the text prompt can be very specific. For example, you might have a variable [LENGTH OF BEAM] which suggests what the variable means, but the text you associated with it could be "The length of the beam from the base to the first cross beam as measured in centimeters." This tells the user exactly what information is expected.

C - RULE EDITOR

48

Variable Type
EXSYS has two types of variablesnumeric and string variables. Numeric variables are stored as floating point numbers and are handled in algebraic expressions. String variables are text strings and can be used for string concatenation or comparison. Text-Only variables are used in the THEN / ELSE part of rules to display special messages. To set the variable type, click the appropriate radio button for Numeric, String or Text Only. Note: Once the variable type is set, and the variable has been used in an expression, changing the type may be prohibited.

Numeric Variables
If the variable is handled as a numeric, its value will be a floating point value. Numeric variables can be used in algebraic expression for testing or assignment. Only numeric variables can have initial values or upper and lower bounds assigned. The following would be valid expressions with numeric expressions: [X] < 1.56 [X] + [Z] >= [Z]/7.4 SIN([LENGTH]) <= [X]*[Z] [X] IS GIVEN THE VALUE [Z]/8.26 The following are not valid expressions if [X] is numeric: [X] > "ABCD" [X] IS GIVEN THE VALUE [X] + "ABCD"

since both combine numeric and string expression.

String Variables
If the variable is handled as a string, its value will be text and not a floating point value. This can be very useful for names or other text information. When the end user is asked for the value of a string variable, the text input will be taken as the string value of the variable. String variables can be used in the IF part in expressions comparing them to other string variables or text strings (for example, you may have text enclosed in double quotation marks). The standard comparison tests of <, >, =, <=, >=, and <> can be used. Validity of

C - RULE EDITOR

49

the comparison is based on alphabetical order. For example, if [S] and [T] are string variables, the following would be valid expressions: [S] [S] [T] [S] = "EXSYS" <= [T] <> "THIS IS A TEST" + [T] <= "THIS IS A TEST"

The first would be true if the string value of the variable [S] were the string EXSYS. The second would be true if the string value of [S] were alphabetically less or equal to the string value of [T]. The third would be true if the string value of [T] were not THIS IS A TEST. The fourth would concatenate [S] and [T] and then do the comparison. The following would not be valid string expressions: [S] > 4 [S] = EXSYS [S] + 3 > [T] The first compares a string variable with a numeric value. The second does not have the comparison string in quotes. The third attempts to add a numeric value to a string variable. String variables can also be used in the THEN or ELSE part of rules in assignment of value statements. This is done the same as a numeric variable, but the value assigned must be another string variable or a string enclosed in double quotes. The following would be valid: [S] [S] [S] IS GIVEN THE VALUE "EXSYS" IS GIVEN THE VALUE [T] IS GIVEN THE VALUE [T] + "ABC"

The following would not be valid: [S] [S] IS GIVEN THE VALUE 4 IS GIVEN THE VALUE EXSYS

The first assigns a numeric value to a string variable. The second does not have the text in quotes. Data for a string variable can also be passed in from external programs.

C - RULE EDITOR

50

Text Only Variables


In most cases, variables will have an associated value, since only variables that have associated values can be used in calculations or assignments. If a variable is defined to be a Text-Only variable, it will not have an associated value with the variable. Instead, the text associated with the variable will be displayed in the rule as a note. This can only be done in the THEN / ELSE part of the rule. If the rule fires, this note will be displayed with the final sorted list of choices at the end of the run. This allows text notes to be selected by rules for display with the results. If a variable does not have a value associated with it, the program will only display the prompt text associated with the variable in the rules and the results. This is the one case where the prompt text does not have to describe the variable. No calculations can be done with a Text Only variable. For example: We could have a variable [CAUTION 1] with the prompt text DO NOT ALLOW THE COMPOUND TO BE EXPOSED TO WATER. The first time this caution is appropriate in the THEN part of a rule, create a new variable named [CAUTION 1] and define it to be text only. The prompt text associated with [CAUTION 1] would be DO NOT ALLOW THE COMPOUND TO BE EXPOSED TO WATER. This text would be displayed as one of the rule's THEN conditions, and would be displayed with the results if the rule fired. To add the caution to another rule, all that would be needed is to select the variable [CAUTION 1] and the same text would appear. If any rule with [CAUTION 1] fired, the text "DO NOT ALLOW THE COMPOUND TO BE EXPOSED TO WATER" would appear with the results.

Display of Variable
A variable can be displayed at the end of a run in the result screen. Usually, only variables that are calculated by the program during the run would be flagged for display. However, in development, having the variables displayed may be useful for checking the expert system. To indicate that the variable should be displayed, click the Display at End box. This display can be switched on or off later.

Initialization of Numeric Variables


If the variable is numeric, the variable can be initialized to a value at the start of the run. If a variable is initialized, the program will not ask the user for its value. The initial value for the variable will always be set at the start of the run, before any rules are tested. Initializing a variable is most useful for running total variables (a variable that contains a partial value with amounts repeatedly added to it). We might have a variable [PRICE] that displays the total price of the equipment recommended by the expert system. Each rule that recommends a piece of equipment would include an expression that would add the cost of the equipment to the running total, [PRICE].
C - RULE EDITOR
51

For example, to add 10 to the running total for [PRICE], use [PRICE] IS GIVEN THE VALUE [PRICE] + 10

We do not want the program to ask the user for a starting value for [PRICE]. Instead, we want the program to start with a value of 0.0. This could be done in the command language, but it is easier to set the starting value to 0.0 by initializing the variable [PRICE] to a value of 0.0. Most variables should not be initialized. Variables that require end user response should never be initialized. Only numeric variables can be initialized. To indicate that the variable should be initialized and set the initial value, enter the value in the edit field labeled Initialize.

Range Limits
If the variable is numeric, the acceptable user input can be limited using pre-established upper and lower bounds. If limits are set, and the user's input is outside the acceptable range, the program will indicate that the data is out of range and asks, again, for input. An upper limit, lower limit, or both can be assigned. Range limits are very useful when the rules only make sense if the user provides input within a certain range. For example, you might have a rule that is valid only if [X] is greater than or equal to 0. If the end users input a negative value for [X], they will get invalid answers. By setting a lower limit of 0, you can guarantee that the value of [X] will be acceptable, and not have to handle unrealistic input in the rules. To set an upper or lower limit, enter the limit value in the edit field labeled Upper Limit or Lower Limit. The value selected as a limit will be an acceptable value. If the limit is set to 0, the user will be able to input a value of 0. Limits can only be applied to numeric variables. Limits are optional and are not required.

Automatic Data Acquisition


Many external sources can be used to automatically set a variable's value, rather than asking the user for additional information. Data can be obtained directly from spreadsheets, databases, the blackboard, a frame, graphics and many other sources. To associate a data acquisition command with the variable, click the Data Acqu. button. A list of the possible data acquisition commands will be displayed. A source for the data can be selected, and EXSYS will prompt the user for the information needed to build the data acquisition command. (See Chapter G for more information on data acquisition commands)
C - RULE EDITOR
52

If a data acquisition command has been associated with the qualifier, it will be displayed in the prompt. You can either directly edit the data acquisition command, or press the Data Acquisition button to build a new command.

Custom Formula Systems


If the confidence system using custom formulas was selected, other options for the variable relating to user-supplied confidence, default confidence values, and ranges are available. To set these options, click the Conf Options button. (See Section C40 on using the Custom Formula system for more information on these options.)

Finished Setting Variable Parameters and Values


When all parameters have been set, click on the OK button. The values and parameters can be changed later from the variable list window by clicking on a variable to select it and then clicking on the Edit button.

C15.7: Entering the Expression to Assign


After the variable to assign a value to has been selected, a window for entering the expression to assign will be displayed.
Add Formula Please enter a formula

OK

Display Variables

Cancel

This is the same window that appeared in the IF part for entering a conditional test, but in this case, enter just the expression to assign to the variable. The condition that will appear in the rule has the form: [VARIABLE] IS GIVEN THE VALUE expression
C - RULE EDITOR
53

The [VARIABLE] has already been selected. The "IS GIVEN THE VALUE" is supplied automatically by EXSYS, so only the expression is needed. When the expression is entered, click the OK button. The formula will be automatically checked for new variables. If any new variables are found, EXSYS will display the dialog box for setting the prompt and other parameters for the new variable. Once all the variables in the formula are defined, the condition will be added to the rule.

C15.8: Expressions
An EXSYS expression can range from any algebraic expression derived from a single number to complex expressions. Usually the expression contain EXSYS variables. Expressions can be simple or complex.

C15.9: Arithmetic Operators


The following arithmetic operators are recognized: * / + % ^ (multiplication) (division) (addition) (subtraction) (modulus operator) (exponential function- A^B is A raised to the B power)

Parentheses can group expressions in the order of calculation that you wish to use. Spaces can be included between operators to make the formula easier to read.

C15.10: Boolean Operators


The EXSYS expression evaluator supports boolean operators in expressions. This is especially useful in operations in the IF part of rules, since several expressions can be combined to make a more complex test expression. For example: IF [X]>0 OR [Y]<100 A formula with boolean operators is entered the same as any other formula, it just includes boolean operators.

C - RULE EDITOR

54

The boolean operators supported are: OR AND NOT || (same as OR) && (same as AND) ! (same as NOT) These operators can be used with parentheses to produce complex expressions. Remember, if the users ask WHY or HOW, they may not easily read and determine the validity of expressions with complex boolean operations. The result of a boolean operation is 0 if false or non-zero if true. Since the result of a boolean operation is a numeric value, it can be used with other numeric expressions. For example: 6 * (4=2) && 1 is acceptable. It would be evaluated as: (4=2) is a test expression returning 0, boolean FALSE. 6 * 0 is 0, a numeric variable. 0&&1 is 0, a boolean expression returning false, 0. While this expression is acceptable, it is somewhat unusual, and when it is entered in an expression, a warning message such as "Boolean where numeric expected" would appear. This is not necessarily an error. It is only a warning that the syntax is unusual and a numeric value is being used as a boolean operator. Note: Boolean true is not always 1, but it is guaranteed to be non-zero. It will not be 1 in cases where numerics other than 0 or 1 are used where booleans are expected. Non-zero numeric values combined with booleans will be taken as true, but the value will propagate through the expression. For example: (4=4) && 7 will return TRUE, but it will not be equal to 1. EXSYS will warn you if you use a boolean result as a numeric value. Even though it is allowable to use a boolean value where a numeric value is expected, it is unusualso unusual in practice that you probably have made an error. For example: 66<[X]<99 does not test if [X] is between 66 and 99. Instead, it tests the boolean result of: 66<[X]
C - RULE EDITOR

55

which will be true or false, (1 or 0) either of which is less than 99. Therefore, this example is always TRUE. What should have been entered is: 66<[X] and [X]<99 Another example which generates two warnings is: [X] = 32 or 64 or 91 This example does not test if [X] is an element of the set [32, 64, 91]. Instead it tests: [X] = 32 or TRUE or TRUE which is always equivalent to TRUE. What you should have entered was: [X]=32 or [X]=64 or [X]=91 If you receive an error about using a boolean as a numeric, or visaversa, carefully check the expression for a mistake similar to one listed above.

C15.11: ANSI Standard Order of Priority


The expression evaluator follows the ANSI standard for precedence and associativity of operators. The following are the Operators supported in EXSYS, arranged in order of precedence: OPERATOR (), unary+, unary-, NOT ^ %,/,* +,<>,<,>,<=,>=, ==, !=, +, ~= AND OR ?: Associativity right to left left to right left to right left to right left to right left to right left to right right to left

If you are not sure how an expression will be evaluated, add parenthesis to make it unambiguous.

C - RULE EDITOR

56

C15.12: Conditional Tests


The conditional tests supported are: = == < > <= >= != ~= test for equality test for equality less than greater than less than or equal greater than or equal not equal approximately equal

C15.13: Approximately Equal Operator


EXSYS maintains all numeric variables as double-precision floatingpoint numbers. When operations are performed on floating-point numbers, round off may lead to loss of accuracy in the least significant digit. Normally this is not a problem, but if an integer is expected, the round off can cause problems, especially in comparisons. For example, a calculation is supposed to give an answer of 2, but due to round-off, it gives 1.9999999999. If it is compared with 2, the answer is false because the value is not equal to 2. However, the value would be 2 if it had not been rounded off. To avoid this problem, the approximately equal operator: ~= is available. [X] ~= [Y] is TRUE if the difference between [X] and [Y] is less than 0.1% of [X]. ([X] - [Y]) / [X] < .001

If [X] values is equal to 0, this would produce a division-by-0 error. If [X] and [Y] are very small, [X] ~= [Y] will be TRUE if both values are within .000001 of 0.

C15.14: Syntax Checking


The EXSYS expression evaluator provides extensive syntax checking when a formula is entered in the editor and when it is run. Many types of errors are detected. The syntax check allows detection and correction of many errors when rules are being entered, rather than when they are run.

C - RULE EDITOR

57

If a formula contains embedded variables (variables in double square brackets, [[]], that will be replaced by their values before the formula is evaluated), the text of the formula is not known until Runtime, and will not be checked for syntax when it is entered . At Runtime, the double square bracket expressions will be replaced with their values and the expression's syntax will be checked. If a syntax error is found, it will be reported then. The syntax checker evaluates constant expressions and would not allow ([X]/(1-1)) because the program would determine that the expression would be a division-by-zero error.

C15.15: Conditional Operator


EXSYS supports a conditional operator similar to the one in the C programming language. This operator allows a conditional test to be used when assigning a value, independent of the conditional tests in the IF part of a rule. This can reduce the number of rules and simplify some problems. The syntax for the conditional operator is: <boolean expression> ? <expression 1>: <expression 2> The expression evaluates to a single value that can be used with other values or assigned. If the boolean expression is true, the first expression will be used. If the boolean expression is false, the second expression is used. For example: ([X] > 0) ? 5 : 10 will evaluate to 5 if [X] is greater than 0 or evaluate to 10 if [X] is less than or equal to 0. The expression evaluates to a single value, the value is not assigned to any variable in the boolean test expression. To use this form for assignment, use a form such as: [Y] IS GIVEN THE VALUE ([X] > 0) ? 5 : 10

where the value assigned to [Y] will be 5 or 10, based on the value of [X]. The conditional operator can be used with other expressions in tests: [Z] < (([X] > 0) ? ([X] + [Y]) : ([Y]/[X])) which tests if [X] is greater than 0. If it is, the test [Z] < [X]+[Y] is made. If it is not, the test [Z] < ([Y]/[X]) is made.
C - RULE EDITOR
58

The conditional operator is very useful and can reduce the number of rules in some cases The two rules: IF AND THEN Qualifier 1 is true [X] > 10 [Y] IS GIVEN THE VALUE IF AND THEN Could be replaced with: IF Qualifier 1 is true THEN [Y] IS GIVEN THE VALUE [X]>10?([X]+5):100 The conditional operator can also be used in cases where data could lead to a division-by-zero error. For example: [Y] IS GIVEN THE VALUE ([X] < > 0) ? (100/[X]) : 10000000 where [Y] is normally given 100/[X], but if [X] is equal to zero, instead of getting an error message, [Y] is assigned a large value, 10000000. Qualifier 1 is true [X] <= 10 [Y] IS GIVEN THE VALUE 100 [X] + 5

C15.16: Functions
The following functions are supported. SIN( ) COS( ) TAN( ) ASIN( ) ACOS( ) ATAN( ) EXP( ) LOG( ) LOG10( ) ABS( ) Sine in radians Cosine in radians Tangent in radians Arc sine in radians Arc cosine in radians Arc tangent in radians Exponential function base e Log base e Log base 10 Absolute value
C - RULE EDITOR
59

SQRT( ) Square root INT( ) Integer part (rounded down) MIN( ) Minimum MAX( ) Maximum TOPREC( ) Number of records in a dBase file QCHK( ) Qualifier status AGE( ) Time since value was set The functions evaluate the expression in parentheses and perform the appropriate function on the result. The parenthetical expression must immediately follow the function name without a space in between.

C - RULE EDITOR

60

C15.17: Special Functions


The following special functions are also available: QCHK(<qual #>, <value#>) or QCHK("qual name", <value #>) This function returns 1, TRUE, if the value <value #> is set for the qualifier specified by name or number. If the name form is used, the name must be in quotation marks ( ). This can be used as an alternative to qualifier conditions where boolean operators need to be combined with qualifiers, or in test expressions in the command language. Examples: QCHK(5, 1) Will return TRUE(1) if value 1 of qualifier 5 is set. Otherwise, it will return FALSE(0). QCHK("color", 3) Will return 1 if value 3 of the qualifier named "color" is set. Otherwise, it will return 0. QCHK(2,2) or QCHK(4,3) Will return 1 if value 2 of qualifier 2 or value 3 of qualifier 4 is set. Otherwise, it will return 0. MIN(x1, x2, x3 ...) Returns the argument with the minimum value. (The number of arguments is not limited.) The MIN and MAX functions can be used in the custom formula confidence mode for systems where the confidence of a choice is the minimum (or maximum) of the confidences of the IF conditions. Example: MIN([X],[Y],[Z]) Will return the value of either [X], [Y] or [Z], whichever is lowest.

C - RULE EDITOR

61

MAX(x1, x2, x3 ...) Returns the argument with the maximum value. (The number of arguments is not limited.) The MIN and MAX functions can be used in the custom formula confidence mode for systems where the confidence of a choice is the minimum (or maximum) of the confidences of the IF conditions. Example: MAX([X],[Y],[Z]) Will return the value of either [X], [Y] or [Z], whichever is highest. TOPREC("<filename>") Returns the number of records in the dBase III database file specified by the filename. This is most often used in the command language. Example: TOPREC("price.dbf") Will return the number of records in the dBase file "price.dbf." INSTR(STR1, STR2) Returns TRUE if STR1 is in STR2 or else it returns FALSE. If TRUE, the value is NOT 1, it returns the string offset where the sub-string was found. If FALSE, it returns 0. The test is case sensitive. Examples: INSTR("in", "incalculable") ==1 INSTR("able", "incalculable") ==9 INSTR("on", "incalculable") ==0 INSTR(STR, STR, BOOLEAN) Same as INSTR except it allows you to specify whether or not it is case sensitive. (If there is a third operator, EXSYS will automatically use this form.) Examples: INSTR("in","INCACULABLE",TRUE) ==0 INSTR("in","INCALCUABLE" ,FALSE) ==1
C - RULE EDITOR

62

GETENV(string) The string is the name of an environment variable. This function returns the value of the environment variable as a string. This function must be used as a string. Example: GETENV("EXSYS") will return the string value of the environment variable EXSYS. TOUPPER(string), TOLOWER(string) Converts the string to upper or lower case.

C - RULE EDITOR

63

C15.18: AGE Function


The AGE function is a special function for systems that are handling real-time data. The function returns the number of seconds since a value was set for a particular qualifier or variable. This is very useful for real-time systems automatically obtaining data on a changing process. The program can check on how old the data is and get new data if necessary. Syntax: AGE(Q#) AGE(Q "name") AGE(V#) AGE([var name]) Example: IF AGE([X]) > 300 THEN RUN(GETX) If the variable [X] has not had its value set within 300 seconds, the program GETX would be called to get a value. AGE can also be used in a command file: ASK Q 1 RULES "START*" IF (AGE(Q 1) > 60) ASK Q 1 RULES "END*" Qualifier 1 will be asked. The rules with names beginning with "START" will be run. The program will make sure that it has not been more than 60 seconds since Qualifier 1 was asked. If it has been more than 60 seconds, Qualifier 1 will be asked again. The rules with names beginning with "END" will then be run.

C - RULE EDITOR

64

C16: Adding a Choice Condition


Choices are the possible solutions to the problem that the expert system will decide among. Choices are usually found in the THEN/ELSE parts of the rule. Choices are the basis of all EXSYS expert systems since they are results that are displayed to the end user. Using the flower color example, you might have choices that include ROSE, DAISY and VIOLET . We might want a rule that says if the color is red, the violet and daisy are eliminated and the rose is the likely answer. IF THE COLOR OF THE FLOWER IS RED THEN ROSE: Confidence= 8 VIOLET: Confidence=0 DAISY: Confidence= 0 By combining the confidence set by one or many rules, the final confidence values for the various choices are set. These choices are then displayed as the results of the expert system. To add a choice, click the Choice button in the rule window.

C16.1: Choices in the THEN/ELSE Part


Usually choices are used in the THEN/ELSE part of a rule where they are assigned a value. Select a choice by clicking on a choice in the list of choices.

C - RULE EDITOR

65

Choices Select Choice Find Find Again

CHOICE LIST

Assign Value OK

Edit Delete

New Ch. Cancel

After selecting a choice, enter the confidence value that you wish to assign to the choice in the edit box. Depending on the Confidence System chosen at the start of the program, this is 0 or 1, 0-10, -100 to 100, increment/decrement value or a custom formula. (If a custom formula system is used, see Section C40 for more information.) Click the OK button and the text of the choice plus " - Confidence =" and a value will appear in the rule.

C16.2: Choices in the IF Part


Choices can be used in the IF part as well as the THEN or ELSE parts of rules. When a choice is used in the IF part, it is as a test of the choice's value in comparison to a fixed value or formula. For example, you might want to know if the final value of the choice "ROSE" received a value greater than 7. In the rule, this condition would be written as "ROSE: Conf > 7". When the rule is tested, the value of the choice ROSE will be evaluated and then used to determine if the condition is true or false. If the value of the choice passes the test, the condition is considered true. When a rule with a choice is tested in a backward chaining expert system, the final value of the choice will be evaluated before the rule is determined to be TRUE or FALSE.

C - RULE EDITOR

66

Choices Select Choice Find Find Again

CHOICE LIST

Test Type: Test Value: OK

>

>=

<

<=

!= Edit Delete New Ch. Cancel

Select a choice by clicking on a choice in the list of choices. Then select a test expression by clicking on the appropriate radio button in the Test Type section. The tests available are: <, >, =, <=, >=, or < >. Then enter the comparison value to test against. The program asks for the value with which to compare the choice's final score. This information is input as an integer. Then click the OK button and the full text of the condition will appear as part of the rule. (If you are using the custom formula mode, see Section C40 for special instructions on the comparison tests.) If the system finds no way to determine the value of a choice used in a rule's IF part, an error message is displayed when running the expert system. This can happen if no valid rules assign a value to the choice. This mode can be changed with system configuration options.

C16.3: Adding a New Choice


To add a choice, click the Add Ch button. A window will be displayed where the text of the new choice can be entered. Enter the text for the new choice and click the OK button. The new choice will be added to the Choice list and automatically selected as the choice to use for the condition.

C - RULE EDITOR

67

C16.4: Deleting a Choice


To delete a choice, select a choice and click on the Delete button. If the choice is not in use, it will be deleted. If the choice is in use, a list of the rules using the choice will be displayed. These rules must be edited to remove the choice before it can be deleted from the system.

C16.5: Editing a Choice


To edit a choice, select a choice by clicking it and then click the Edit button. The Choice editing window will be displayed with the text available for editing. You will then be able to edit the text for the choice. When you are finished editing your choice, click the OK button.

C - RULE EDITOR

68

C17: Adding a Command Condition


To add a command condition, click the Command button. A window will appear giving the options for adding commands. These are discussed in Chapter G on Data Acquisition Commands.

C - RULE EDITOR

69

C18: To Copy or Move a Condition


File Edit Rule Options KBfiles Questions

Condition Cut Condition Copy Condition Paste

1. Highlight a condition in a rule by clicking it. 2. On the menu line, pull down the Rule menu and select Condition Cut or Condition Copy. (Both of these commands copy the condition into a buffer, but Cut also deletes the condition.) 3. Select another rule, or another part of the same rule in Insert mode. 4. On the menu line, pull down the Rule menu and select Condition Paste. 5. If possible, the selected condition will be added to the rule in the same place as if it were a new condition. Some operations are logically impossible, for example in the THEN part, choices are assigned values, while in the IF part their value is tested. It would not make sense to move a THEN syntax choice condition to the IF part. EXSYS will check for such errors and will not allow you to perform such operations. If a condition is copied or cut from the IF part of a rule, it can only be pasted into the IF part of another rule. If a condition is copied or cut from the THEN or ELSE part of a rule, it can only be copied to the THEN or ELSE part of another rule.

C - RULE EDITOR

70

Note: To move conditions, use the Condition Cut, Condition Copy and Condition Paste commands. The standard Cut, Copy and Paste commands under the Edit menu are used in some places in EXSYS to move text, but they can not be used to move rule conditions. To the developer, conditions appear as text, but internally they are far more complex structures. Only the Condition Cut, Condition Copy and Condition Paste commands perform all of the required operations and checks.

C - RULE EDITOR

71

C19: To Delete a Condition


1. Highlight a condition by clicking it. 2. Click the Delete button

C20: To Change a Condition


1. Highlight a condition by clicking it. 2. Click the Change button. 3. You will be presented with the window for adding a condition of the same type (qualifier, variable or choice) as the selected condition. The new condition will replace the selected condition.

C21: To Scroll to the Previous or Next rule


Press the Prev or Next button. If there were any changes made to the rule, you will be asked if you wish to save these changes before scrolling.

C22: To Add / Edit the Note, Reference and Name


Each rule can have an associated Note, Reference and Name.

C22.1: Note
The note can supply some additional information to the user. The note has no effect on the program and is used only to provide information to the end user. Whenever the rule is displayed, the note will also be displayed.
C - RULE EDITOR
72

The notes associated with rules that fired can be easily incorporated in a report using the report generator command NOTE. This can create a text explanation of how the system reached its conclusions. To add a note, click the Note box. A edit box will be displayed with the existing note if there is one. Make any changes and click OK. If there is NOTE text, the Note box will be checked.

C22.2: Reference
A reference can also be associated with a rule. This, like the note, is optional. The reference usually contains the source of the knowledge represented in the rule. If users question the rule, they can refer to the reference. The reference, like the note, may also be used to provide more information to the user. Unlike the note, the reference is displayed only when the user requests it. References from rules which fired can also be incorporated in a report using the REFERENCE command. To add a reference, click the Reference box. An edit box will be displayed with the existing reference, if there is one. Make any changes that you think are necessary, then click OK. If there is reference text, the Reference box will be checked.

C22.3: Name
A name can also be associated with a rule. The name is optional, but is very useful when referencing the rule from the command language or report generator. Names allow the knowledge base to be divided into sections when it is run or referenced. Names also allow rules to be moved with the knowledge base without affecting numeric referencing from the command language or report generator. For example, the command language command RULES 1-20 will run the rules numbered 1 to 20. However, if the rules are moved or another rule is added, the Command Language command would have to be corrected. If, instead, each of the relevant rules had a name that started with the letter 'A', we could just use the Command Language command RULES A*. This would run all rules that have names that start with 'A'. This is not affected by position or re-numbering. Rule names are also useful when editing rules since the rule edit selection dialog box displays all the rules by name as well as number. Adding a meaningful name can make the rule much easier to find later.

C - RULE EDITOR

73

To add a name, click the Name box. An edit box will be displayed with the existing name, if there is one. Make any changes that you think are necessary, then click OK. If there is name text, the Name box will be checked.

C - RULE EDITOR

74

C23: To Repeat a Condition from the Previous Rule


Having the same first few conditions at the start of several rules is often quite useful. This enables a false condition to rapidly eliminate large blocks of rules so the user is not asked unnecessary questions. To repeat a condition from the numerically previous rule, click the Repeat button. The Editor copies the condition that was used in the previous rule. If Repeat is selected as the first entry, the program/editor copies condition 1 from the numerically previous rule. If the first condition is input by number and then Repeat is clicked, the editor copies the second condition of the previous rule. If the previous rule does not have enough conditions to match, EXSYS lets you know this. If you want to copy something from some source other than the numerically previous rule, use the cut and past condition commands.

C - RULE EDITOR

75

C24: Consistency Checking of New Rules


When a new rule is entered in the system, it is automatically checked for consistency with the existing rules. This is done by the system, assuming that the new rule's IF and THEN parts are true. It then checks to see what other rules would also be true based on this data. Due to the complexities of simultaneous conditional math expressions, all mathematical expressions are ignored during this check. The program displays any rules it finds and asks if the new rule should be changed. The fact that other rules are found is not necessarily an errorthe Editor is merely ensuring that the developer is aware of them. For example, the new rule is: IF THE COLOR OF THE FLOWER IS RED THEN CHOICE 1: Probability = 3/10 If, in checking the existing rules, the program found another rule that said IF THE COLOR OF THE FLOWER IS RED THEN CHOICE 4: Probability = 6/10 the program would display the rule, since clearly if the new rule were true, this rule would also be true. Likewise, if the program found the rule: IF THE COLOR OF THE FLOWER IS NOT BLUE THEN CHOICE 6 : Probability = 0/10

C - RULE EDITOR

76

it would also display the rule, since the IF condition in the new rule implies that the IF condition in this rule would be true. When checking rules, the program does not consider the effect of having an IF condition false to add ELSE conditions. When possibly conflicting rules are found, the program will be display a list of the possibly conflicting rules:
If Rule 75 were true, the listed rules could also apply

2 7 23 34

Accept New Rule

Edit / Examine Rule

Clicking Accept New Rule will add the new rule to the knowledge base. Selecting a rule from the list and clicking Edit / Examine Rule will display the selected rule. Both the new rule and the selected rule will be displayed for editing. Switching Off Rule Checking The program supplies the option of switching off the rule-checking function. Checking can be canceled by selecting the Parameters item from the Options menu, and checking the No button marked Check New Rules for Consistency. Turning rule checking off is a good idea when mathematical expressions are used because the rule checker does not check the validity of those expressions.

C - RULE EDITOR

77

For example: IF AND THEN THIS IS VALUE 1 [X] < 20 CHOICE 1 : Probability = 3/10 The rule checker might display the following rule, that had already been entered, as also possibly true: IF AND THEN THIS IS VALUE 1 [X] > 20 CHOICE 2 : Probability 5/10 This program will not recognize that [X] <20 and [X]>20 cannot both be true. Mathematical expressions are ignored when checking rules for consistency. This approach was used because, for complex equations, determining if two or more equations can be simultaneously true is difficult, especially when variables are involved.

C - RULE EDITOR

78

C25: Deleting a Rule


File Edit Rule Options KBfiles Questions

Add Rule Edit Rule Delete Rule Move Rule Use Rule Names Qualifier List Variable List Choice List Condition Cut Condition Copy Condition Paste

To delete a rule, go to the main menu bar and pull down the Rule menu. Select Delete Rule. A window will be displayed, allowing you to select the rule to delete either by name or number. Select a rule and click the OK button. The rule you have selected will be displayed along with a window asking you to confirm that this rule is to be deleted. If you click YES, the rule will be deleted and all other rules will be re-numbered accordingly. Any rule windows open for editing will also be re-numbered.

C - RULE EDITOR

79

C26: Moving a Block of Rules


File Edit Rule Options KBfiles Questions

Add Rule Edit Rule Delete Rule Move Rule Use Rule Names Qualifier List Variable List Choice List Condition Cut Condition Copy Condition Paste

Rules are tested in the order that they occur. Forward chaining systems are particularly sensitive to rule order, but even backward chaining systems will test the rules in order. Sometimes you may want to move a block of rules to a particular place in the system. To move a block of rules, go to the main menu bar and pull down the Rule menu. Select Move Rule. A window will be displayed, allowing you to select the block of rules and destination either by name or number.

C - RULE EDITOR

80

Name:

Number: 1 2 3 4 5 6 7 8 Last

aaa bbb ccccc dddd

Move from rule: to Rule: Before rule: To end

OK

Cancel

To select the start of the block, click Move from rule and select a rule. To select the end of the block, click to Rule and select a rule. To select the destination for the rules, click Before rule and select a rule. To move the block to the end of the rule list, click the To end button. When you click on the OK button, the block of rules will be moved and all rules will be re-numbered accordingly. Any rule windows open for editing will also be re-numbered if necessary.

C - RULE EDITOR

81

C27: Printing a Knowledge Base


File Edit Rule Options KBfiles Questions New Open Save Save As Revert to Saved Print Exit About

Selecting Print from the File menu allows you to print the knowledge base to a disk file or to a printer, in several different forms.

Print to PRINTER Print to FILE Standard Output Format Rule Compiler Format C Code Replacement for Rules

Rules Qualifiers / Variables Cross Reference List Formulas One Per Page Continuous Small Font Cancel OK

Having a print-out of the rules, qualifiers, variables, and choices is sometimes useful while developing an expert system. Printing in the rule compiler or C code formats allows special editing operations or embedding of the rules.
C - RULE EDITOR
82

To send something to a printer or file, click the Print to Printer or Print to File button. Normally, only the Standard Output Format would be sent to a printer. If a file is selected, enter the name of the file. Important Note: When selecting a filename, do not give it the same name as one of the existing expert system filenames or the expert system will be destroyed. Select a format for the output. The Standard Output Format is a readable form without any special syntactical characters. In the Standard Output format, you can select which parts of the knowledge base you wish to print. The Rule Compiler Format adds the special syntactical control characters and format needed by the EXSYS Rule Compiler. Text in this format can be edited with a text editor and then recompiled using the Rule Compiler. (See Chapter K for more information on the Rule Compiler.) If this format is chosen, the output should be sent to a disk file. The C Code Format outputs a C Code replacement for the rules which can be used with EXSYS Linkable Object modules to embed the rules in a single executable file. The C Code is only useful when used with EXSYS Linkable. If this format is chosen, the output should be to a disk file. The Small Font box should be selected to print the rules to a printer using a small font. The default font is too large on some printers and a smaller font may work better for your needs. However, be aware that not all printers support a small font.

C - RULE EDITOR

83

C28: Displaying the Qualifiers, Variables or Choices


File Edit Rule Options KBfiles Questions

Qualifier List Variable List Choice List

To display the list of qualifiers, go to the main menu bar and pull down the Rule menu. Select Qualifier List. The qualifier window will be displayed. This is the same window as adding a qualifier condition to a rule. Once a qualifier is selected, it can be edited by clicking the Edit button or it can be deleted by clicking the Delete button. A new qualifier can be added to the list by pressing the New Qual button. The new qualifier window is the same as adding a new qualifier during the editing of a rule. To display the list of variables, go to the main menu bar and pull down the Rule menu. Select Variable List. A window will be displayed, allowing you to select a variable. This is the same as selecting a variable when adding a math condition to a rule. All the options for editing the variable are active. To display the list of choices, go to the main menu bar and pull down the Rule menu. Select Choice List. A window will be displayed, allowing you to select a choice. This is the same as selecting a choice condition to a rule. All the options for editing the choices are active.

C - RULE EDITOR

84

C29: Running the Rules


File Edit Rule Options Run Cancel Run Parameters Validation Examine Tree Diagram Notebook Help KBfiles Questions

To run the rules, go to the main menu and pull down Options. Select Run. The rules will run as if they were being run from the Runtime. (See Chapter D on the Runtime for details.)

C - RULE EDITOR

85

C30: Canceling a Run


File Edit Rule Options Run Cancel Run Parameters Validation Examine Tree Diagram Notebook Help KBfiles Questions

To return to the Edit mode during a run, select Cancel Run from the Options menu. The run will be terminated and EXSYS will return to the edit mode.

C - RULE EDITOR

86

C31: Changing the Knowledge Base Parameters


File Edit Rule Options Run Cancel Run Parameters Validation Examine Tree Diagram Notebook Help KBfiles Questions

To Change the general parameters of the knowledge base (rule display, derivation mode, starting and ending text, etc.), select Parameters from the Options menu. The same window as seen at the start of a new knowledge base will be displayed. Some items which can only be set at the creation of a new knowledge base (Confidence mode) will be disabled. Make any desired changes and click the OK button.

C - RULE EDITOR

87

C32: Automatic Validation / Tree Diagrams


File Edit Rule Options Run Cancel Run Parameters Validation Examine Tree Diagram Notebook Help KBfiles Questions

C32.1: Introduction
Validating an expert system should be a major part of any expert system development project. It is important to make sure that end users will receive valid answers to any input. The EXSYS automatic validation function greatly simplifies and automates this process. EXSYS supports two methods of validation testingsystematic and random. Systematic testing allows all possible combinations of input to be tested for a variety of possible errors. If the expert system is large, and systematic testing the entire system would take too long, systematic testing of portions of the system or random testing of the entire system can be performed. Three files are producedtwo types of tree diagrams, and an error report file. The tree diagram shows all the possible combinations of input and the resulting output of the system. Regardless of the complexity of the logic of the system, the input and output can always be diagrammed as a tree. The trees can be examined with a special display routine in EXSYS that enables you to scroll through the tree diagram. The nodes on the diagram are written in an abbreviated form (something like, Q3:2 which represents qualifier number 3 value 2). When the tree diagram is displayed, clicking the node expands the abbreviated form to the full text form of the qualifier or variable. The two types of tree diagrams produced are linear and branched tree diagrams. These two diagrams are equivalent in information

C - RULE EDITOR

88

content, but are diagrammed differently. The branched tree diagram graphically shows the branching in the system. For example:

Q7:1

[X]:30

Q4:1 >>> C3:7 C2:1 Q4:2 >>> C3:5 Q4:3 >>> C1:2 C4:8 Q4:1 >>> ERROR: Q6 could not be derived Q4:2 >>> C5:7 Q4:3 >>> C6:6 Q9:2 Q11:1 Q11:2 Q11:3 Q11:4 >>>C4:6 >>>ERROR: Variable out of >>>C5:2 >>>C5:7

[X]:35

[X]:40

Q7:2

Q11:1 Q11:2 Q11:3 Q11:4

>>>Error: No choices set >>>ERROR: Q4 loop error >>> C6:3 C5:1 >>> C3:4

A branched tree diagram is convenient for seeing the overall structure, but if a particular set of input produces an error, it may take some scrolling to read all the information on the input. In a linear tree diagram, all the node values for a branch are displayed on a single line. If you took the same information from the above diagram and assembled it into a linear tree diagram, it would be displayed as:
Q7:1 Q7:1 Q7:1 Q7:1 Q7:1 Q7:1 Q7:1 Q7:1 Q7:1 Q7:1 - [X]:30 - Q4:1 >>>C3:7 C2:1 - [X]:30 - Q4:2 >>>C3:5 - [X]:30 - Q4:3 >>>C1:2 C4:8 - [X]:35 - Q4:1 >>>ERROR:Q6 could not be derived - [X]:35 - Q4:2 >>>C5:7 - [X]:35 - Q4:3 >>>C6:6 - [X]:40 - Q11:1 >>>C4:6 - [X]:40 - Q11:2 >>>ERROR: Variable out of .. - [X]:40 - Q11:3 >>>C5:2 - [X]:40 - Q11:4 >>>C5:7

In the linear tree, it is easier to follow the data that lead to the conclusion, especially in large trees. However, it is not as easy to see the overall structure. When random testing is selected, only a linear diagram will be created. Due to the random nature of the testing, the data will not be tree structured. The error file contains reports of any detected errors and the input which produced the error. In the random mode, only the error file is produced.

C - RULE EDITOR

89

The validation function will detect and report combinations of input that 1. Produced no conclusions. 2. Failed to derive needed qualifiers or variables that should be derived. 3. Created loop errors. 4. Assigned a variable a value which is outside of the limits specified for the variable. 5. Assigned more values to a qualifier than the maximum number allowed for that qualifier. 6. Special custom tests designed with the report generator. Only the combinations of input that might actually be supplied by an end user are considered. This usually reduces the number of tests that must be run to much less than the total number of possible combinations of data.

C32.2: Running in Validation Mode


To build the validation file, select Validation from the Options menu.

Validation Test Mode:

System. Random Cancel

A menu is displayed. Select either: 1. Test the system systematically 2. Test the system randomly

C - RULE EDITOR

90

A systematic test will consider all possible combinations of input within the ranges specified. This is the best type of validation, however the size of the file may get large very quickly. If the number of combinations becomes impractically large, limit the scope of the systematic test or use random testing. Random testing will consider random sets of input. This may not cover all possible input, but for large systems or systems with many numeric variables, it will allow testing of many possible inputs.

C32.3: Setting the Test Parameters


Both systematic and random test modes are initialized in a similar manner. Parameters are defined for each qualifier and variable on ranges of values to use, which elements should be derived and what values should be locked. These parameters can be saved to disk for future use. If either systematic or random testing is selected, a list of all of the qualifiers in the system will be displayed. Qualifiers can be handled in one of three possible ways during the validation testing: 1. Values will be set automatically, and all possible qualifier values will be used. When a value is needed for the qualifier, the validation function will automatically provide a value from the list of possible values. This value will be used for the subsequent processing of the rules. 2. Values will be set automatically, but only one value, or a few values, from the list are to be used. When data on the qualifier is needed, the validation system will automatically supply a value, but the selected value will be restricted to only specified values, rather than considering all possible values for the qualifier. Limiting the number of values limits the scope of the test, while still allowing systematic testing of other parts of the system. For large systems, locking a few key qualifiers to single values can greatly reduce the time required to test part of the system. 3. Values will be derived from rules. A value must be derived by the rules in the system, or an error will result. This is used to mark the qualifiers which should be derived (never asked) from other data. The system will not automatically assign values to these qualifiers. This option should be used for qualifiers that are not supposed to be asked of the end user. If data on the qualifier can not be derived, and the qualifier is needed in the execution of the rules, it will result in an error message in the error file.

C - RULE EDITOR

91

Select qualifier by text or name:

Find

Find Again

Name

List of Qualifiers

List of Qualifier Values

Derive All Values OK Limited Test

Set ALL Qual. to ALL Values Save to File Read from File Cancel

Each of the qualifiers in the list will be preceded by a 'D'. This indicates that the qualifier should be derived from other data in the system. Failure to derive a value would be considered an error. All of the qualifiers that are intended to be asked of the end user (and assigned values by the validation function) must be marked. If a qualifier is not to be derived, the test can include all or only some of the qualifiers values. Limiting the number of tested values will reduce the time to perform the test. To mark all qualifiers to use all values, click the Set ALL Qual to ALL values button. All of the qualifiers will now be preceded by an 'A', indicating that all their values are to be used. Individual qualifiers can be set by selecting the qualifier in the Qualifier list. The values associated with the qualifier will be displayed in the Values list window. The current state of the qualifier will be indicated. To mark the qualifier to be derived, select the qualifier and click the Derive button. To mark the qualifier to use all values, select the qualifier and click the All Values button. To mark the qualifier to use only some values, select the qualifier and click the individual values to be used. The Limited Test button will automatically be selected.
C - RULE EDITOR
92

To save the parameters set to a file, click the Save to File button. You will be asked for the name of the file in which you wish to save data. This is useful when there is a complex set of parameters for the qualifiers. To read the parameters back from a file, click the Read from File button. You will be asked to select the file containing the parameter data. If the knowledge base has been modified since the data was saved, EXSYS will notify of this. The parameter data will be read back from the file and displayed in the window for additional editing. When the parameters are set correctly, click the OK button. After the qualifiers are set, the variables must also be set.

Variable List

Derive Single Value Range of Values Lower: Upper: Step: Save to File

Numeric String Text Only

Read from File

Return to Qualifiers Cancel

Text of variable

OK

At the start, each of the variables will be preceded by a 'D', indicating that they must be derived. To have EXSYS automatically test each of the variables, it must be marked to have a single value or a range of values. If it has a single value, only that value will be used. In the systematic validation case, the program will ask for an upper and lower bounds and an increment. The validation test will automatically consider variable values from the lower bound to the upper bound by increasing the value by the specified increment. This

C - RULE EDITOR

93

data will be combined with the selected qualifiers, so be careful when you choose an increment. If there are 10 increments between the lower and upper bounds, it will take 10 test cases every time the variable is tested. If there are multiple variables, the number of possible test cases can get quite large. Therefore, it is better to use the Random testing mode with multiple variables. For random validation, the program will only ask for upper and lower bounds. The value will be randomly chosen at any point between these boundsnot on specific increments. Select a variable by clicking on it. The text of the variable will be displayed at the bottom of the window. To mark the variable to be derived, select the variable and click on the Derive button. To mark the variable to be given only a single value, select the variable and click on the Single Value button. You will then be asked for the value you want to use. To test the variable over a range of values, select the variable and click the Range of Values button. You will then be asked for the lower, upper, and (if systematic testing) the incremental step. The type of variable is indicated by the Numeric, String and Text Only buttons. You can not change the type of variables, this in only for your information. Text- only variables can only be derived. This is because they can only be used in the THEN/ELSE part of rules and will never be asked anyway. String variables can only be derived, or given a single value. To save the parameters set (plus the parameters set for the qualifiers) to a file, click the Save to File button. You will be asked for the name of the file in which you want to save the data. To read parameters saved to a file, click the Read from File button. You will be asked to select the file to read. Remember, the file read may also set the qualifier parameters to new values. To return to edit the qualifier parameters, click the Return to Qualifiers button. When the variable parameters are set correctly, click the OK button. If random testing was selected, you will now be asked how many random tests you wish to run. EXSYS will now start the automatic validation process. A window will be displayed indicating that automatic validation is being used and giving the option to cancel the test.
C - RULE EDITOR
94

In the random mode, after the 5th test is run, the system will start to calculate the approximate time to completion based on the average time spent on the tests run thus far. In the systematic mode, the number of the test will be displayed, but until the rules are actually run, the system has no way to tell how many tests actually must be run. Because only possible combinations of input that might be supplied by a user are considered, the number of tests is usually far smaller than the total number of possible combinations of data. You can stop the run at any time by pressing a key and waiting for the current record to finish. When the system finishes the tests, the diagram of the test results will be displayed.

RUNNING IN VALIDATE / TREE MODE: #

Stop Validation Tests

If you click on the Stop Validation Tests button before the tests are completed, you will cancel the remaining tests and be able to examine results of the tests run to that point. If you let the test run to completion, you will be able to examine all the results.

C32.4: Validation Results


The validation tests will produce several files:

Error File
All errors are written to the file name <knowledge base name>.ERR. It will show all cases where the input 1. Produced no conclusions 2. Failed to derive needed qualifiers or variables that should be derived 3. Created loop errors 4. Assigned a value to variable which is outside the limits specified for the variable. 5. Assigned more values to a qualifier than the maximum number allowed for that qualifier

C - RULE EDITOR

95

The report includes the error and the data which produced the error. Since after detecting an error the system continues testing, the error file may contain multiple error reports.

Tree Files
In addition to the error file, two tree files will be created. (The random mode produces only an error file and a linear file.) If you do not want the tree files created, and only want the error file, use the configure option ERROR_FILE_ONLY. Usually is only done if you suspect your available disk space is insufficient for the tree files. The file <knowledge base name>.TR1 will contain a list of all of the data for all the runs. If the validation is systematic, the data will be arranged as a tree, but each line will contain all the input data. In systematic test mode, a second file will be created, <knowledge base name>.TR2. This is a branched tree diagram showing the possible user input and resulting output. Both of these files are ASCII files and can be examined or printed with a text editor. They can also be examined with a special display routine in EXSYS. In the random testing mode, the <knowledge base name>.TR1 file will contain data and results from all the random test cases that were run. The values are selected randomly, so they can not be converted to a branched tree diagram. The tree diagram shows how user input relates to the expert system's results. In a systematic test, all possible combinations of input will be diagrammed. If the tree is too large, you can reduce the scope of the tree by limiting some qualifiers to one, or a few, values. For a systematic test, you will be asked if you wish to examine the branched or linear tree diagram. For Random tests, only the linear diagram is available.

Validation Tree to Examine:

Branched Cancel Linear

If you select the Branched diagram, a window will be opened with the tree diagram.

C - RULE EDITOR

96

Q1:1

Q2:1 Q2:2

>>> Q3:1 Q3:2

C1:5 >>> >>> >>> >>> Error: No Results C2:4 C2:7 C2:1

Q2:3

Q3:1 Q3:2

Q1:2 Q1:3

>>> Q3:1 Q3:2

Error: Variable 1 could not be derived >>> C3:6 >>> C1:8

OK

Click on a node or more informatio

The tree diagram displays the structure of the knowledge base by diagramming the input and output. Even very complex and non-tree structured systems can be diagrammed this way. The diagram uses a shortened notation for the qualifier and variable values. For example Q1:2 means the second value of qualifier 1. To see the full text of the qualifier and variable for the condition described at the node, click on the node. A window will open with the full text of the qualifier, variable or choice. The tree diagram can be resized using the resize control on the window. You can scroll horizontally or vertically in the window. When you are finished examining the diagram, click the OK button. The information from the tree diagram is stored in the files <knowledge base name>.TR1 - Linear diagram <knowledge base name>.TR2 - Tree Diagram <knowledge base name>.ERR - Error data and rule use

C32.5: Custom Reports


For customized reports, you can associate a report generator command file with the expert system. This enables you to create reports of specific tests you wish to make. The optional report generator file <knowledge base name>.OUT will be called at the end of each run automatically.
C - RULE EDITOR
97

If a report generator file is used, be sure to use the /A option in the FILE command to append each record of data to the report file. For example suppose you wish to know all cases where two specific choices are simultaneously given a high value. The following will list all cases of input which resulted in the value of choice 5 and choice 7 both being greater than 8. FILE CHK.RES /A C5 <=8 /G:end C7 <=8 /G:end "*******************************" "Choices:" C " " "Input:" INPUT :end close If the value of choice 5 is less than or equal to 8, the /G option will cause it to go to the end of the report file. If choice 5 is greater than 8, choice 7 will be tested. If choice 7 is less than or equal to 8, the report file will also go to the end. If both values are greater than 8, the data output commands will be used and the choices and input data will be written to the file. This technique can be used to produce customized tests that are systematically applied to all possible combinations of input.

C32.6: Validation Testing to Compare Versions of a Knowledge Base


The validation function allows systematic testing and also allows testing of the effect of modification of the rules. At times, knowledge bases get modified in ways that are not supposed to effect the final results (as in the case of new modules or new external programs). A systematic validation file can be created before and after a change. The resulting tree files can then be compared. They should be identical if there were no changes in the results produced by the system. If there are differences, comparison of the result files will show the input which lead to the different results.

C - RULE EDITOR

98

C32.7: External Program Problems


The validation function is designed to run without any user input. However, EXSYS can only control interaction internal to EXSYS. Applications which call external programs that require user interaction, or force user interaction through the command language will have to be modified before the validation testing can run unattended. To do this, make a copy of the expert system and remove the portions that force user interaction through RUN() or DISPLAY() commands or other external program calls. This is often easiest to do with the rule compiler. Set the parameters for the qualifiers and variables that would be obtained from external sources to be automatically assigned, instead of asking the user. If an external program does not require user interaction (such as ones which only process data or automatically obtain data) it can be used in the automatic validation mode.. DATALIST should not be used to set data. Instead, remove the datalist command and emulate the datalist by setting the validation parameters for the qualifiers and variables. Command files can be used with the validation mode.

C - RULE EDITOR

99

C33: Examining Existing Tree Diagram Files


File Edit Rule Options Run Cancel Run Parameters Validation Examine Tree Diagram Notebook Help KBfiles Questions

To examine an existing tree or linear diagram file, select Examine Tree Diagram from the Options menu. You will be asked which type of diagram you want to examine. The diagram will be displayed in the same way as it is after a validation test run.

C - RULE EDITOR

100

C34: Notebook
File Edit Rule Options Run Cancel Run Parameters Validation Examine Tree Diagram Notebook Help KBfiles Questions

EXSYS maintains a system notebook file for each expert system. Notes can be added in this file by the developer or end user on various aspects of the system. This can be a way to get end user feed-back on a fielded system, or suggestions for enhancements. The file is named <knowledge base name>.NBK. To make a note in the knowledge base notebook file, go to the main menu and pull down Options and select Notebook. You will have the option to Write, Read or change the notebook file name.

Notebook Option Notebook Functions: Write to Notebook Read from Notebook Change Notebook File CANCEL READ WRITE

Notebook File:

To write, click Write and enter the note that you want to add. The text you enter will be added to the notebook and then will be date stamped with the current date and time. To read, click Read and the notebook file will be displayed. To change the name of the notebook file to be used, edit the file name displayed at the bottom of the window.
C - RULE EDITOR
101

C35: Asking for Help


File Edit Rule Options Run Cancel Run Parameters Validation Examine Tree Diagram Notebook Help KBfiles Questions

To display the system help windows, select Help from the Options Menu. This is the same help system described previously.

C - RULE EDITOR

102

C36: Editing the Knowledge Base Text Files


File Edit Rule Options KBfiles Configure Command Report Screen Help Other Questions

In addition to the .rul and .txt files created by the EXSYS Rule Editor, there are also several associated files which can be created and edited with a text editor. To make it easy to modify these files from within EXSYS, a small text editor is available. The details of commands available in each of these files is discussed in the appropriate section of this manual. Select the file to edit, and an edit window will appear, allowing you to enter or edit the text. If Other is selected, you will be asked for the name of the file to edit.

C - RULE EDITOR

103

C37: The Questions Menu


File Edit Rule Options KBfiles Questions Known Data Why? Display Rule Display Choices Explain Question Undo Prev. Answer Save Input Recover Input Trace Window

Almost all the items in the Questions menu are identical to those in the Questions menu of the Runtime program, and are discussed in Chapter D on the Runtime. The one exception is the Trace Window selection which is only found in the Editor.

C - RULE EDITOR

104

C38: Trace the History of the Run


File Edit Rule Options KBfiles Questions Known Data Why? Display Rule Display Choices Explain Question Undo Prev. Answer Save Input Recover Input Trace Window

When developing an expert system, it is often useful to trace what rules are firing, where variables are being set, and a variety of other actions. This is especially true when tracking down a bug in the rules. There are two ways to create a history of a run. The first is to use the configure option TRACE=file. This will create a history of the run in the file specified. The use of TRACE= is covered in Chapter E on Configure Options. The second way is to create a trace window. This is done by selecting Trace Window from the Questions menu. A trace window will be created. All user or external program input will be written to the window. Also, as each rule fires and adds data to the system, the information will be added to the window.

C - RULE EDITOR

105

Trace Text

OK

Find

Find Again

As the expert system executes, a history of the execution will be written to the trace window. The trace window can be brought to the front at any time by clicking in it. To check on a specific data item, click the Find button. Enter the name of the data item that you want to find and the trace window will scroll to the item. Click the Find Again button to see the next occurrence of the item in the file. To scroll the text in the window, use the scroll bar. When you are finished with the trace window, click the OK button.

C - RULE EDITOR

106

C39: Hypertext
EXSYS supports hypertext to provide information on key words used in the expert system. To designate a word as a hypertext key word, it is preceded and followed by ^^. For example, to make EXSYS a hypertext keyword, it would be entered as ^^EXSYS^^. This makes it easy to add hypertext help to an expert system. Virtually all windows in EXSYS support hypertext during the running of the system, including the screens to ask for qualifiers or variables, display results, display known data or rules, and other actions. Hypertext is not supported in the edit mode. In the GUI versions of EXSYS, hypertext keywords are highlighted in blue. A click on a hypertext keyword will bring up the screen associated with that word. For detailed information on using hypertext, see Chapter I. The hypertext custom screens are stored in the file: <knowledge base name>.SCR and are marked in the screen file with ~~keyword. See the Chapter I on the GUI Custom Screen Language for details on creating the hypertext screens.

C - RULE EDITOR

107

C40: Custom Formula Confidence


The Custom Confidence mode allows you to write your own formulas to combine confidence factors. This mode is rarely needed for system development, but it is very powerful and flexible. If this mode is selected, a few additional features are available to you.

C40.1: Using Custom Formulas Confidence System


EXSYS provides five systems for handling confidence values. 1. 2. 3. 4. 5. 0 or 1 0 to 10 -100 to 100 Increment/Decrement Custom Formulas

The first four systems all function similarly in terms of user input and interface. However, the fifth system (custom formulas) has significant differences. The custom formula confidence system in EXSYS allows developers to supply their own formulas for the combination of confidence factors. This is by far the most complex of all the confidence systems available in EXSYS and should be used only by advanced users who need the special flexibility this approach offers. In this system, the end users can be asked to supply a confidence value for the data they provide about qualifiers or variables. This user-supplied confidence rating may be used to calculate the confidence in the choices or in backward chaining to calculate the confidence of other qualifiers or variables. A backward chain may not only determine a value for a variable or qualifier but may also determine the confidence in that qualifier or variable. This confidence value can be displayed to the user at the end of a run.

C - RULE EDITOR

108

C40.2: Confidence Variables


The custom formula system uses confidence variables for qualifiers, variables and choices. These behave just like standard numeric variables but are automatically defined to be confidence values. Confidence variables are indicated by starting the variable with a %, followed by the type (qualifier, variable or choice) and number of the qualifier, variable or choice. Also, they can be referred to by name or unique text. This ability makes the confidence variables independent of reorganizations of the expert system. [%Q#] [%Q"abcd"] [%V#] [%%[X]] [%C#] [%C"abcd"] is the confidence in qualifier # is the confidence in the qualifier with the associated name "abcd" is the confidence in variable # is the confidence in variable [X] is the confidence in choice # is the confidence in the choice that contains the text "abcd" anywhere in the text of the choice

Confidence variables are maintained as double precision floating point values, so the confidence values are not limited to integers. The confidence variables can be used in combination with other variables in formulas for derivation of confidence values for other qualifiers, variables or choices. When a new variable or qualifier is used in a knowledge base, the program asks the developer a series of questions to determine the options that are to be used. The options include a button labeled Conf Options. If the Custom Formula Confidence mode was selected, this button will be active. Clicking this button allows you to set parameters for how the confidence of the qualifiers and variables will be handled.

C - RULE EDITOR

109

Display Confidence Value Ask User for Confidence Value Minimum Maximum Initialize Confidence Value Initial Value

o.oo
Cancel

OK

Display Value
If the variable or qualifier is to be displayed, the confidence value assigned to it also can be displayed or not, as desired. If the confidence has been derived, it may be best to display it. If no derived confidence is associated with the variable, it may be better to simply display the qualifier without a confidence value. To display the confidence value, click the Display Confidence Value box.

Qualifier / Variable Confidence


There are two options for assigning a confidence value to a qualifier or variable. The confidence value can be asked of the end user or assigned by the system automatically. The default is for the system to assign a value of 0.0. To have the system assign a value, click the Initialize Confidence Value radio button and enter the value in the edit-field labeled Initial Value. To have the end user asked to supply a confidence value, click the radio button labeled Ask User for Confidence Value and enter the minimum and maximum values that will be accepted. If the user is asked for a value, minimum and maximum values must be entered.

Initial Choice Confidence


All choices in the system will have their initial value set to an initial value. In most cases, several rules will provide confidence data for the choice, therefore the formulas that assign a value to the choice will perform some operation on the current value. The choice must start with some initial value. The default is 0. However, depending on the formulas being used, a value other than 0 may be desirable. To change the value, select Parameters from the Options menu, click the Init Choice Value button and enter the new value. This value will be the initial value of each choice at the start of the run.

C - RULE EDITOR

110

For example, you could have: Choice 1 Confidence = [%C1]+[%C2] where Choice 1 is given a value equal to its current value plus the final value of Choice 2. This is the type of operation the custom formula system can do easily but which is very difficult to do in other confidence systems.

C40.3: Assigning a Confidence Formula


When the user selects a choice to assign a confidence to, EXSYS will ask for a formula to use when calculating the value of the choice. The formula can contain confidence variables or numeric variables. The formula is entered just as if it were being assigned to a typical variable. In these examples, only part of the expression that comes after the equals sign (=) is entered. Choice 1 - Confidence = ([%[X]] + [%Q 3]) / 2 means the confidence in Choice 1 is the average of the confidence in variable [X] and Qualifier Number 3. We could also use other numeric variables or choice confidence values. For example, Choice 2 - Confidence= [%C 1] + [X] + [%[X]] means Choice 2 is assigned the confidence of Choice 1 plus the value of variable [X] plus the confidence in variable [X]. A formula like this would probably not be realistic, but flexibility of the system allows any expression to be used. Formulas can also contain the value for the choice confidence that is being assigned. For example, Choice 2 - Confidence = ([%C 2] + [%[X]]) / 2 which means the confidence in Choice 2 is given the value of the current confidence in Choice 2 averaged with the confidence of variable [X]. If choices are used in the IF part of the rules, the test is against a formula which can include other confidence variables or numeric variables. For example, IF Choice 1- Confidence > [%C 2] + 10 THEN .... which means if the confidence in Choice 1 is greater than the confidence in Choice 2 plus 10, the rule is true.
C - RULE EDITOR
111

C40.4: User-Supplied Confidence Ratings


The confidence factors for qualifiers and variables can come from three sources. When the custom-formula system is used, the developer will be asked a series of questions on each new variable or qualifier that determines how the confidence for that qualifier or variable will be obtained and displayed. One of these questions is if the user should be asked to supply a confidence value when asked about the qualifier or variable. If user input of the confidence value is selected, the program asks for the range limits on the user-supplied confidence. Depending on the formulas being used, these limits may be 0 to 100, -1 to 1 or any other range that is appropriate. After the user is asked for the value of the variable or qualifier, the acceptable range of values will be displayed and the users will be asked for their confidence in the preceding answer. The user-supplied value will be assigned to the confidence variable associated with the qualifier or variable. If the developer selects not to have the user provide confidence for the data, the confidence value for the qualifiers or variables will be automatically set at a value. This initial value for each qualifier and variable can be set independently and can be modified by other rules. Typically, the initial value is either 0, 1, or 100 depending upon the system used. Regardless of the initial source for the value of the confidence variable, the values can be modified by formulas in the rules. Confidence variables can be assigned a value just like any other variable. For example, IF ...... THEN [%[X]] is given the value [%[Y]] + 20 means that, if the rule fires, the confidence in variable [X] is given the value of the confidence in variable [Y] plus 20. Note: Asking users to supply confidence ratings of their answers may presume a higher level of expertise than may be reasonable. Consider the end user before implementing user-supplied confidence values. If precise data on which to base the confidence is available, user-supplied confidence values may be valid. However, if the confidence ratings will be purely subjective, and may vary widely depending upon user and mood, they may invalidate the entire expert system.

C - RULE EDITOR

112

In many systems, it is often better to ask the user questions such as, The color was seen 1 very well 2 well 3 poorly which the end user is more likely to answer consistently, and then convert these to numeric values internally with rules like, IF The color was seen very well THEN [%[COLOR]] is given the value 90 IF The color was seen well THEN [%[COLOR]] is given the value 50 IF The color was seen poorly THEN [%[Color]] is given the value 20

C - RULE EDITOR

113

C41: Custom Help Screens


EXSYS supports custom screens associated with the qualifiers and variables to provide additional instruction on what a question means, where to get data, or any other information the user might need. These screens are described in Chapter I. These screens are kept in the file <knowledge base name>.HLP However, these screens must be built using the GUI version of the Custom Screen Definition Language. If a screen is associated with a qualifier or variable, the Explain Question item of the Questions menu will be active. If the user selects that item, the screen will be displayed. See Chapter I for information on creating custom screens.

C - RULE EDITOR

114

C42: Loop Error Messages


EXSYS Professional will display an error message when it detects rule loops that prevent full derivation of needed information. Such loops force EXSYS to ignore certain values in some cases and should be corrected by the user, even if the correct answer is achieved.
POSSIBLE LOGIC ERROR: Loop involving [var name] in rule # POSSIBLE LOGIC ERROR: Loop involving Qualifier # in rule #

For example, if you had the following rule, IF ....... THEN [X] IS GIVEN THE VALUE [A] + 1 [A] IS GIVEN THE VALUE 12 you would not expect the program to fire the second THEN condition to establish a value for [A], even though it is relevant to the calculation in the first condition. The "[A] is given the value 12" is ignored when assigning the value to [X]. This is a very simple, and easy to avoid example (simply reverse the THEN conditions). However, the same effect can happen in a more complex way. Consider the following rules: Rule 1 IF [B] > 0 THEN .......... Rule 2 IF ........... THEN [X] is given the value [A] + 1 [B] is given the value ........... Rule 3 IF ................ THEN [A] is given the value [B] + 1

C - RULE EDITOR

115

When Rule 1 is tested, the program determines it needs the value of [B]. It invokes rule 2 to determine a value for [B] (We will assume rules 2 and 3 are true). The first condition in the THEN part of rule 2 is applied. It requires that the value for [A] be known. To determine the value for [A], rule 3 is invoked. It also requires a value for [B]. Since the program has already used rule 2 (even though it has not completed the adding of the THEN parts), it cannot again invoke rule 2. The program must find another way to determine [B]it would use other rules or ask the user, but it would not use the second THEN condition in rule 2 when calculating [A]. The program would then finish adding the first THEN condition in rule 2 and would move on to the second. [B] would be assigned a value after it had been used to assign a value to [A] in rule 3. This may result in [A] having an incorrect value. EXSYS will detect this error of logic and warn the user. If the situation described above occurs, you will get the error message POSSIBLE LOGIC ERROR: Loop in ([variable name] or Qualifier number) in Rule #. This error message means the variable or qualifier cannot be fully derived because of the problem described above. That variable or qualifier should be placed, with any preceding conditions it needs, into a second rule with the same IF conditions. This could be prevented by not having the THEN part of rule 2 include assignments to two variables that are derived from one another in other rules. If Rule 2 were broken into two rules, one for [X] and one for [B], the value of [B] would be fully calculated before being used to calculate [A]. Here is an example: IF ........... THEN [X] is given the value [A] + 1 and IF ........... THEN [B] is given the value ........... It is not practical to force the program to apply the second condition in the THEN part of 2 prior to the first, since the first condition could have some effect on the value of the second, resulting in the same problem in a slightly different set of rules.

C - RULE EDITOR

116

Chapter D EXSYS Runtime

D1: Starting the RUNTIME


Click on the RUNTIME icon to start the program. In some GUI operating systems, you may also run the program with an optional associated filename of the knowledge base file, and one or more configure commands: EXSYSP filename configure_commands For example, in Microsoft Windows, selecting the RUN item from the FILE menu of the Program Manager allows you to enter a command line. It is also possible in Microsoft Windows to associate command parameters with an icon, but this would normally be done only for the EXSYS Runtime.

D - RUNTIME

D2: Opening an Existing Knowledge Base


File Edit Rule Options KBfiles Questions

New Open Save Save As Revert to Saved Print Exit About

When you select Open, a list of all of the files with a .rul extension is displayed. Double click on the desired file, or select a file and click on the Open button. Note: For the Macintosh, all files will be displayed. The extension past the period in the name is ignored. Select any of knowledge base files (.RUL, .TXT, .CMD, .SCR, .HYT, .HLP, etc.).

Passwords
If the developer selected password protection, the program asks for the users Runtime password. When correct password is entered, the system continues. If the password is not known, click on the EXIT button to exit the system.

D - RUNTIME

D3: System Help


File Edit Rule Options KBfiles Questions

New Open Save Save As Revert to Saved Print Exit About

To get help in using EXSYS: In Microsoft Windows, select About from the File menu, or press the F1 key. On the Macintosh, select About EXSYSP in the Apple menu. In all operating systems, select the Help item from the Options menu. This will go directly to the Help Topics dialog box.

File

Edit

Rule

Options Run Cancel Run Parameters

KBfiles

Questions

Validation Examine Tree Diagram Notebook Help

D - RUNTIME

This will bring up the following dialog box. Click on the HELP button.
EXSYS Professional Editor Version 5.0 1083-1996 EXSYS, Inc. Albuquerque, NM

Cancel Help

In all operating systems an alternative is to select the Help item from the Options menu. This will go directly to the Help Topics dialog box.

Select help topic...

Help topics

Fresh Window

Cancel

Help

Either double click on a help topic, or select a help topic with a single click and then click on the Help button. A window will display information on the selected topic. If you wish to have the help information on the topic placed in a new help window, click on the Fresh Window button.

D - RUNTIME

Help Information

Cancel

Prev

Next

Topics

Click on the Prev button to see the information on the previous topic in the help topic list. Click on Next to see the information on the next topic in the help topic list. Click on Topic to bring the help topic list window to the front. Click on Cancel when done. Clicking on Cancel in either the Help Topic window or the Help Text window will close both windows.

D - RUNTIME

D4: Notebook
File Edit Rule Options Run Cancel Run Parameters Validation Examine Tree Diagram Notebook Help KBfiles Questions

To make a note in the knowledge base notebook file, go to the main menu and pull down Options and select Notebook. You will have the option to Write, Read or change the notebook file name.
Notebook Option Notebook Functions: Write to Notebook Read from Notebook Change Notebook File CANCEL READ WRITE

Notebook File:

To write, click on Write and enter the note to add. The text entered will be added to the notebook and stamped with the current date and time. To read, click on Read and the notebook file will be displayed. To change the name of the notebook file to be displayed, edit the file name displayed at the bottom of the window.

D - RUNTIME

D5: Display of Rules During Runtime


EXSYS allows the developer to limit options available to the end user. This chapter describes what the end user sees, both if the developer sets no limits and if limitations were set. 1. The developer may have selected to have all rules displayed during Runtime. In which case, each rule is displayed as it fires. 2. The developer may have switched off display of rules but not locked out the rule display. Even though the rules are not automatically displayed during Runtime, the user can examine the rules by selecting Why in the Questions menu. 3. The developer may have locked out the rule display entirely, in which case asking Why is not possible. This mode can only be active when password protection has been selected.

D - RUNTIME

D6: Title Screen


When you choose to run an expert system, the first screen you see is.

Title

Author

Run Expert System

To start the expert system, click on the Run Expert System button.

D - RUNTIME

D7: Starting Text


When you run an expert system, you may see a screen which includes a description of the program or give you information that you need to know to run the program.

Text

Continue

After reading the screen, click on the Continue button.

D - RUNTIME

D8: User Interaction


The expert system takes data from various sources and uses the rules in the system to arrive at conclusions. The degree of user interaction for data input varies depending on the system design. However, most systems ask the user for some data input. There are two types of questions that can be asked - multiple choice selection, and a request for a value for a variable. EXSYS has a default format for asking these questions. In addition, there is a custom screen language that allows the developer to completely modify and customize these screens. The default screens are discussed first.

D8.1: Asking for a Qualifier Value


When EXSYS needs the value of a qualifier, it uses the following default screen format:
EXSYS Professional Select one or more values:

QUALIFIER TEXT QUALIFIER VALUE LIST

OK

Select values from the Qualifier Value List by clicking on them. A click on a value will highlight the value. Some screens allow only a single value, others may allow multiple values. If the screen only allows a single value, clicking on another value will de-select the first value and select the second. If the screen allows multiple values, clicking on several will highlight each of them. To de-select a highlighted value, click on it again.
D - RUNTIME
10

As you select values, their respective numbers will appear in the box at the bottom of the screen. If you wish, you can type the numbers of the desired values desired into this box. When the correct values have been highlighted, click on the OK button. There is no Cancel button for a qualifier question. The expert system requires this information to continue processing. If you do not wish to continue, select Exit from the File menu. It is also possible to save the input already entered prior to exiting by using the Quit and Recover options. To ask Why the question is being asked, Undo a previous answer, get more information on the question, or display the current status, use the items on the Questions menu discussed later.

D - RUNTIME

11

D8.2: Asking for a Variable Value


When EXSYS needs the value of a variable, it uses the following default screen format:
EXSYS Professional Please input a value for the varia ble:

VARIABLE PROMPT TEXT

OK

Enter a value to answer the question in the box at the bottom of the window. When the correct value has been entered, click on the OK button or press the Enter key. The value can be numeric or a string value depending on the nature of the question asked. For numeric values, the string can contain commas. The commas will be ignored in converting the value. There is no Cancel button for a variable question. The expert system requires this information to continue processing. If you do not wish to continue, select Exit from the File menu. It is also possible to save the input already entered prior to exiting by using the Quit and Recover options. To ask why the question is being asked, UNDO a previous answer, get more information on the question, or display the current status, use the items on the Questions menu discussed below.

D - RUNTIME

12

D9: External Program Input


The developer may have called external programs to obtain information. An external program is any program, including applications such as data bases, graphics programs, spreadsheets or custom programs written in any language; in other words, anything that can be run on the computer. This external program might present graphical information, ask fill-in-the-blank type questions, or integrate the expert system into other programs.

D10: Custom Screens


Custom screens are easily created, the developer may have redesigned the default screens used by EXSYS. The redesigned screens may include buttons, sliders, mouse regions. The flexible EXSYS Custom Screen Language allows the screens to be redesigned in limitless ways. In all cases, it will be clear and easy for the end user to understand the question and select an answer. Some custom screens may ask for multiple data items on a single screen. The custom screens will look different than the default screen, but the program will still ask the end user to select from a multiple choice list or to enter a value, either numeric or text.

D - RUNTIME

13

D11: Asking Why a Question is Being Asked


File Edit Rule Options KBfiles Questions Known Data Why? Display Rule Display Choices Explain Question Undo Prev. Answer Save Input Recover Input Trace Window

To ask why a particular qualifier or variable question is being asked, select Why from the Questions menu. EXSYS will explain why the data is needed. Usually this results in the display of the rule that is currently being tested. If the data is needed because of backward chaining, there may be a series of rules displayed. There may also be some other explanation of why the question was asked. Here's an example: 1. The program may respond that the end user supplied the information. 2. The program may display a rule or rules that allowed it to derive the information. A rule used for derivation will have information about the condition being queried in its THEN or ELSE part. The rule used to derive the information will have already fired, providing the needed information. (EXSYS automatically calls all possible rules to derive needed information, rather than ask the user.) The end user could continue asking how the program knew the rules IF conditions were true. When a rule is displayed, there are a variety of options available to get more information about the rule. For more information, see Displaying a Rule. 3. The program may respond that it does not yet know whether the condition is true or not. This can occur when the user asks the program WHY in response to a question. The rule displayed will not have been fully tested yet. Such conditions will be displayed in blue.

D - RUNTIME

14

4. If the information came from an external program, the program will indicate which external program returned the data. 5. The program may indicate that particular statement is false and display the source of the information that determined the statement was false. In such a situation, the condition is displayed in red. 6. If a formula is questioned, the program displays a list of the values of all of the variables used in the formula. Clicking on any of the variables in the list will display information on the source of that value. With well written rules, tracing the logic of the knowledge base back through the rules which were used to derive information is easy. After displaying a rule, the program may either repeat the question originally asked or it may display another rule. Another rule is displayed if the first rule was only used to derive information needed by the second rule, and the second is the rule actually being tested. (One of the THEN or ELSE conditions in the first rule will be in the second rules IF conditions - this is backward chaining.) All of the questions asking for information about the rule are available. The program will continue showing the rules it is using to derive information until it reaches the base rule it is trying to test. Clicking on OK continues the programs run. If more than one rule was displayed, each time OK is selected, the program goes up one rule on the list being used in the derivation. Eventually, the program repeats the question originally asked.

D - RUNTIME

15

D12: Asking for More Information on a Question


File Edit Rule Options KBfiles Questions Known Data Why? Display Rule Display Choices Explain Question Undo Prev. Answer Save Input Recover Input Trace Window

In some expert systems, the developer may have included additional information on what a question means, or where to find the answer to a question. This information is optional and may not have been necessary, or included. If there is additional information on the question being asked, Explain Question from the Questions menu will be active. If there is no information, this item will be inactive and can not be selected. To ask for more information, select Explain Question. A window will appear which explains the question in more detail. This explanation screen is designed by the developer with the custom screen language and may be of any form, but it should have a button labeled OK (or something similar) which allows you to exit the screen and return to the question. See Section I-12 for details on builing Custom Help screens.

D - RUNTIME

16

D13: UNDO a Previous Answer


File Edit Rule Options KBfiles Questions Known Data Why? Display Rule Display Choices Explain Question Undo Prev. Answer Save Input Recover Input Trace Window

Sometimes, during the running of a system, an end user may realize that their answer to a previous question was incorrect. In EXSYS, it is possible to backup and correct the previous answer. The exact number of questions that can be undone is set by the developer. Most developers allow the user to correct between 3 and 10 previous answers. To undo a previous answer, select Undo Prev Answer from the Questions menu. You will be asked the previous question. If you wish to backup farther, select Undo Prev Answer again. You may continue backing up as long as Undo Prev Answer is active. When you reach the question which was incorrectly answered, enter the correct answer and processing will continue.

D - RUNTIME

17

D14: Save Input


File Edit Rule Options KBfiles Questions Known Data Why? Display Rule Display Choices Explain Question Undo Prev. Answer Save Input Recover Input Trace Window

EXSYS provides the option of storing input data, exiting before completing the program, and returning to the same point later. This option can be useful if the user needs to look up information for the program or must leave the program but does not want to lose the data already input. To save the input entered to a disk file, select Save Input from the Questions menu. You will be asked for the name of the file in which to save the data. The file may be any legal filename, except the name of the Knowledge Base. If a file with the same name already exists, it will be erased and replaced with the new data. After saving the input, you may wish to exit the run. Data saved can be read back into the system with the Recover configure option, or by selecting Recover Input from the Questions menu.

D - RUNTIME

18

D15: Recover Input


File Edit Rule Options KBfiles Questions Known Data Why? Display Rule Display Choices Explain Question Undo Prev. Answer Save Input Recover Input Trace Window

Input saved with a Save Input command, or the SAVE command language command, can be recovered only at the start of another run. To indicate that data is to be recovered, use the configure option RECOVER or RECOVER=file. Alternatively, you may select Recover Input from the Questions menu when the expert system title screen is displayed. The only immediate effect of this will be to put a check mark beside Recover Input. This indicates that the recover mode is active. If there is already a check mark, selecting Recover Input will de-active it. If the configure option RECOVER has been used, Recover Input will be checked automatically. If recover mode is active at the start of a run, EXSYS will ask if you wish to recover data from a file. If you answer "YES", you will be asked for the name of the file. The data will be read in and processing will continue. To have the data read automatically without asking for user interaction, use the RECOVER=file configure option.

D - RUNTIME

19

D16: Displaying the Known Data


File Edit Rule Options KBfiles Questions Known Data Why? Display Rule Display Choices Explain Question Undo Prev. Answer Save Input Recover Input Trace Window

To display all of the data known to the system, select Known Data from the Questions menu. This will create a Known Data window. It lists all of the data known. If you wish to know the source of any of the data displayed, select an item by clicking on it and click on the How button, or double click on the item. The source for the information will be displayed. The display may also include the rules if they are the source of the data.
KNOWN DATA

Known Data

OK

HOW

If the Known Data window is kept active while the system is running, each new item of data will be added to the window as it is asked of the user or derived from rules.
D - RUNTIME
20

D - RUNTIME

21

D17: Displaying the Status of the Choices


File Edit Rule Options KBfiles Questions Known Data Why? Display Rule Display Choices Explain Question Undo Prev. Answer Save Input Recover Input Trace Window

To display the current status of the choices in the system, select Display Choices from the Questions menu. This will create a Choice Data window. It lists the status of each choice. If you wish to know the source of any of the data displayed, select an item by clicking on it and click on the How button, or double click on the item. The source for the information will be displayed. Usually, the display is the rules that set the value for the choice.
CHOICE DATA

Choice Data

OK

HOW

ALL

The Choice Data window displays the choice and the value set. Initially, only choices with values over the threshold for choice display
D - RUNTIME
22

are shown. To see all of the choices, click on the All button. If a choice has a value of "None", that means no rules have fired assigning any value to the choice. A value of "None" is not the same as a value of 0, which means something has assigned a value of 0 to the choice. After the All button is clicked, the button label will change to > #, where # is the threshold value. To return the display to only those choices over the threshold, click on the ># button, which will return the button label to All. If the Choice Data window is kept active while the system is running, each new choice value will be added to the window as it is derived from rules.

D - RUNTIME

23

D18: Displaying a Rule


File Edit Rule Options KBfiles Questions Known Data Why? Display Rule Display Choices Explain Question Undo Prev. Answer Save Input Recover Input Trace Window

Rules can be displayed in EXSYS in many ways. Often asking for the source of a piece of data, or asking Why a question is being asked will result in the display of a rule. It is also possible to ask to see a specific rule by selecting Display Rule from the Questions menu. Select the rule to display by either name or number. The rule display is color coded. A condition displayed in RED is false, a condition displayed in BLACK is true and a condition displayed in BLUE is unknown. In addition, the status of the rule (TRUE, FALSE or NOT TESTED) appears on the top line of the window. (Note: "Not tested" may appear for a rule that is definitely true or false, it only indicates that the rule has not yet been used by the expert system.). Also the background color for the window indicates its status. A RED background indicates a FALSE rule, a GREEN background a TRUE rule and a BLUE background an untested rule. The color coding for the rules is updated as each new piece of data is added. If a rule is displayed during a run, it is easy to notice the color change from BLUE to GREEN indicating the point at which it fired. The menu bar also displays if the rule is true, false or unknown.

D - RUNTIME

24

Rule #: IF: If conditions THEN: Then conditions ELSE: Else conditions

FALSE

Optional Note text

OK

Source

PREV

NEXT

Jump

Reference

Color Coding of Rules Condition TRUE BLACK Condition FALSE RED Condition UNKNOWN BLUE Rule TRUE Rule FALSE Rule UNKNOWN GREEN background RED background BLUE background

To examine the source of the information for any of the IF conditions, click on the IF condition to select it and click on the Source button, or double click on the item. To examine the numerically previous or next rule, click on the Prev or Next button respectively. To jump to another more distant rule, click on the Jump button, and select the rule to jump. It is possible to have multiple rule windows open on the screen. However, as the number of rules becomes large, processing may slow due to the need to update each rule as new data is added.

D - RUNTIME

25

A rule may have a note associated with it. Notes are used to provide additional information or to explain a complex rule in simpler terms. The note has no effect on the running of the rule. If there is a note associated with the rule, it will automatically be displayed. Rules often also have a reference for the source of the fact represented in the rule (e.g., personal observation, book, article). To examine the reference for the rule, click on the Reference button. The reference will be displayed. If no reference is available, the button will be inactive.

D - RUNTIME

26

D19: Ending Text


The author of the expert system may have decided to include a ending explanation of what the expert system results mean. If so, a screen with this information will be displayed just before the Results. If the author did not include such a screen, the expert system will display Results at the end of the run.

Text

Continue

After reading the screen, click on the Continue button.

D - RUNTIME

27

D20: Displaying Results


At the end of a run, the results will be displayed. Each choice has a probability value which is the final score obtained by combining the points that each choice received. A comparison of the scores displayed indicates the relative likelihood of the choices. For example, if the first choice gets a 9 and the second an 8, both are almost equally likely. On the other hand, if the first choice got a 9 and the second a 3, the first is much more likely than the second. Text statements with no associated numeric value may be displayed. These are text messages to the user that were marked for display. They are not choices and always appear after the list of choices. Numeric values calculated by the program or other statements of fact that were derived by the program may also be displayed. Like the text statement described above, the display of this data always comes after the list of choices regardless of confidence system used. In the Custom Formula System, these statements of fact may have a confidence factor associated with them.

D20.1: Confidence Modes


The developer chose one of five possible Confidence Modes when building the knowledge base. The selection made by the developer determines what the end user sees on the screen and the way EXSYS manipulates the data. This section describes the different Confidence Modes, the kind of responses expected from the end user, and the effects of those responses.

0/1
If the developer selected the 0-1 System, the user sees a confidence values of 0 or 1 . A value of 0 means "absolutely no" and a value of 1 is equivalent to "absolutely yes". This mode has no real probability, only yes or no.

0/10
If the developer selected the 0 to 10 System, the user sees a confidence value between 0 and 10. In the rules this is displayed as a ratio with a denominator of 10. This mode is often encountered. In this mode, 0 is equivalent to "absolutely no". (A single rule assigning a value of 0 locks the value at 0 regardless of any other value the choice may have received from other rules.) A value of 10 is equivalent to "absolutely yes" and also locks the value for the choice at 10 regardless of any other values the choice may have received.

D - RUNTIME

28

Values of 1 to 9 represent degrees of certainty ranging from "very probably no" to "very probably yes". The values from 1 to 9 do not lock the value but are averaged to give the final value for a choice. For example: if the same choice appears in the three rules that had true IF parts with values of 3/10, 8/10, and 4/10, the final value for the choice will be the average - 5/10. If the values found were 3/10, 9/10 and 0/10, the 0/10 would prevail and the result in a final value of 0/10 despite the other values. If the values were 1/10, 3/10, and 10/10, the 10/10 would lock the value at 10/10 regardless of the other values. Values of 1 through 9 are averaged to a final value only if not over-ridden by a 0/10 or 10/10. The first 0/10 or 10/10 prevails and will not be changed even by another 10/10 or 0/10.

-100/+100
If the developer selected the -100 to +100 System, the values will be between -100 and 100. (In the rules this will displayed as a ratio with a denominator of 100.). In this system, values of 0 to 100 can be assigned but the values of 0 and 100 do not lock the value. The final value can be computed as an average of the probabilities or can be combined as dependent or independent probabilities. The first is a simple average of all of the individual values the choice received in the rules found to be true. The second combines the probabilities as if they were dependent probabilities. That is, the probabilities are multiplied as percents. For example, if choice appeared in two rules that were used, with values of 60/100 and 90/100, its final value would be 60% times 90% =54% for a final value of 54/100. The third way to combine the values is to treat them as independent probabilities. In this system, the combination of the two probabilities is 1 minus the product of 1 minus the individual probabilities. In the example above, this would be 1-((1-60%) * (1-90%))=96% for a final value of 96/100. If negative values are used only the average mode can be used.

Increment/Decrement
If the developer has chosen the Increment/Decrement Mode, points are added or subtracted from the total points for a particular choice. Final values may be between -10,000 to 10,000. In the rules, there will not be any ratios for the confidence values. For example, we might have "Choice 1 - Confidence=5". This means that if the rule fires, Choice 1 will get 5 points added to its total. At the end of the run, the total number of points is displayed. All choices getting values higher than a threshold will be displayed with the results. No values lock a choice, but giving a choice a large number of points can push it over the threshold value.

D - RUNTIME

29

Custom Formula
If the developer selected the Custom Formula Mode, the confidence statements for the choices have formulas in them. This mode allows developers to write their own formulas for the combination of confidence values. User-supplied confidence, derived confidence on variables or qualifiers, and numeric variables can be included in complex formulas to determine the confidence for a choice. This is a much more complex system to use and it is described in greater detail in Section C3.3.

Results

Results

OK

HOW

Change/Rerun

All

In most systems, the results of the run will be displayed at the end of a run. This includes all choices which received confidence values over the threshold value, and all qualifiers and variables which were flagged to be displayed with the results. Some systems may also display intermediate results, or may simply output the results to a file or pass data to another program to take some action. To ask the source for any of the items, select the item by clicking on it, and then click on the How button; or double click on the item. Initially only choices with values over the threshold for choice display are shown. To see all of the choices, click on the All button. If a choice has a value of "None", that means no rules have fired which assign any value to the choice. A value of "None" is not the same as a value of 0, which means value of 0 was assigned to the choice. After the All button is clicked, it will change to >#, where # is the threshold value. To display only those choices over the threshold, click on the ># button, which will return the button label to All.

D - RUNTIME

30

D21: Change and Rerun


EXSYS provides a very easy way to test what effect altering some of the input will have on the conclusions. One or more answers can be changed, the remainder held constant, the data rerun, and the effect of the changes on the final results seen. The initial values for the choices can be saved for comparison with the new scores. This is similar to changing a number in a spreadsheet to see what effect it has on other numbers. To activate Change and Rerun, click on the Change/Rerun button. A window will display all of the data provided by the user.

Change / Rerun Data

Data

RUN

Change

Cancel

Original Data

To change a data item, click on it to select it and click on the Change button, or simply double click on the data item. You will be asked the data item that you are testing. Select a new answer. The window will display the selected item highlighted and then display the new value. You may change as many data items as you wish. When you have finished modifying the data, click on the Run button. The data will run, possibly asking additional questions if the modifications lead to new rules firing, and then it will present the results. However, this time the results screen will have two columns of data, the original values and the values obtained as a result of the modified data. This allows side by side comparison of the effects of making the changes.

D - RUNTIME

31

The ability to change and rerun the data allows expert system models to be built and tested to see if an answer is vital to the final outcome or really has little effect. Experiment with Change and Rerun; it is a very powerful feature. If several changes to the input data were made, and the user wants to return to the original input, click on the Original Data button. The data will return to the original input values. To Cancel the change and rerun, click on the Cancel button.

D22: Custom Results Screens


Custom results screens can be created with the Report Generator and Display commands. If there is no .CMD file, and there is a .OUT report generator file, the report generator file will be executed before displaying the results. (To prevent the normal results screen from overlaying the DISPLAY window, use the /N option on the DISPLAY command.) The report generator file can include an ending DISPLAY( ) command to display the results in customized format, and can even use the Custom Screen language for highly customized screens.

D - RUNTIME

32

D23: Exiting the Runtime


File Edit Rule Options KBfiles Questions New Open Save Save As Revert to Saved Print Exit About

To exit the EXSYS Runtime, go to the File menu on the menu bar and select Exit.

D - RUNTIME

33

Chapter E Configuration Options

There are a variety of command line options available in EXSYS Professional. Command line options are given when the program is called from the operating system. For example: EDITXSP <filename> <command line options> or EXSYSP <filename> <command line options> The command line options must follow the file name and can only be used in the command line if you have specified a file name. Since EXSYS Professional has a large number of command line options, some with fairly long commands; it can be inconvenient to enter all these options each time an expert system is called. Also, you may wish to always use the same options for all your expert systems or for each time a particular expert system is run. Configure files can be defined containing the same command line options. The configure file will be read each time the system is run. The configure files are much more convenient, especially for final distribution of an expert system to end users.

E1: Editor/Runtime Configure Files


EXSYS Professional has two types of configure files. The first is associated with the EXSYS Professional programs, EXSYSP.EXE and EDITXSP.EXE. Each time the EXSYS Professional editor or runtime is called, the configure file associated with the program will be used. The configure files associated with the EXSYS Programs are: EDITXSP.CFG and EXSYSP.CFG

E - CONFIGURATION OPTIONS

You can create the file EDITXSP.CFG with a text editor and list as many command line options as you wish. Each time the EXSYS Professional Editor program, EDITXSP.EXE is called, it will check for this configure file and use any options you have specified. Likewise, the file EXSYSP.CFG applies to the runtime program EXSYSP.EXE. NOTE: The editor configure file has no effect on the runtime and visa versa. If you have developed an expert system in the editor, and it behaves differently when you run it with the runtime, make sure the configure options are identical.

E2: Knowledge Base Configure Files


Sometimes certain configure options will be needed for a particular expert system, but not for all the systems you work on. In that case, you can have a configure file associated with that particular knowledge base. The configure files for a knowledge base <FILENAME> would be <filename>.CFG The files EDITXSP.CFG and EXSYSP.CFG are automatically called by EDITXSP and EXSYSP, and should contain any configuration information needed by all your knowledge bases. The <filename>.CFG file should contain the special configure information needed only by the knowledge base specified by the <filename>. The configure files are optional, and configure information can still be entered in the command line. In case of conflicting commands, the last one read takes precedence. EXSYS Professional first reads the command line arguments; then reads the file EXSYSP.CFG or EDITXSP.CFG; then reads the configure file associated with the knowledge base.

E - CONFIGURATION OPTIONS

E3: Creating Configure Files


When the .CFG files are used, they should contain one command per line with a carriage return following each command. For example, if we always wanted EXSYSP to switch off color display and allow the option to recover saved data, we would have a file EXSYSP.CFG with NOCOLOR RECOVER If, in addition, we had a knowledge base named LOANS which we wanted to run with the FORWARD and NOBACKWARD options, we would create a file LOANS.CFG with FORWARD NOBACKWARD The file EXSYSP.CFG or EDITXSP.CFG must be on the same drive and in the same path/directory as the files EXSYSP.EXE or EDITXSP.EXE respectively. The file <filename>.CFG must be on the same drive and path/directory as the <filename>.RUL file. There are a large number of command options. Most are set by the author of the knowledge base and should not be changed by another user. Many of these options are related to features covered in other sections on creating expert systems. NOTE: Remember, the commands in the .CFG file are automatically read in. If EXSYS seems to be behaving in a non-standard way, check the configure files for changes to the standard defaults. Use caution when adding the files EXSYSP.CFG and EDITXSP.CFG. It is easy to forget that these files are on a disk, but they will effect all the expert systems you run!

E - CONFIGURATION OPTIONS

Command Line or .CFG Option

Change Connector Words AND=<and word> OR=<or word> NOT=<not word>

These three commands allow the user to change the connector words used in EXSYS qualifier conditions from and/or/not to other words. This makes it easier to use EXSYS Professional in languages other than English. For example, to change the AND connector to the German word UND, you can use AND=UND in the command line or configure file. In all rules and statements where EXSYS Professional uses qualifier conditions, the "AND", "OR" or "NOT" will be replaced by the text specified in the command. This will not change the "AND" or "OR" used to build rules.

E - CONFIGURATION OPTIONS

Command Line or .CFG Option

Asks for Specified Data at the Start of a Run ASK


You may sometimes wish to ask the user the same sequence of questions at the start of every run, regardless of what the users may input. The order in which the questions are asked can be forced by writing a rule that is always true. However, this is a technique that can confuse users if they ask WHY. Instead, an ASK command can be added to the knowledge base .CFG file. The questions will then be asked in the same order they are specified in the .CFG file. To ask a qualifier, enter ASK Q # or ASK Q "name" where # is the number of the qualifier to ask, and "name" is the name associated with the qualifier. If the name form is used, the name must be in quotation marks ( ). To ask a variable enter ASK V # or ASK [var name] where # is the variable number and var name is the name of the variable. If the name form is used, the name must be in brackets ( [ ] ). For example, if the <filename>.CFG file contained ..... ..... ASK Q 11 ASK Q "color" ASK V 7 ASK [X] ..... ..... The program would ask qualifier 11, the qualifier named "COLOR", variable 7 and variable [X] at the start of the run, before any other questions were asked. (Also see the ASK command in the Command Language.)

E - CONFIGURATION OPTIONS

Command Line or .CFG Option

Calling an External Program After Change and Rerun Commands


Two command line options control the running of an external program called at the start of a run during a "change and rerun" operation. If the knowledge base has a starting external program, the EXSYS Professional default is to ask if you wish to rerun the external program during a change and rerun. In some cases, asking this question can be undesirable, since the answer is always the same and the end user should not be asked the question. The command line or .CFG option: CHANGE_NOEP doesnt allow Professional to run the starting external program and it also stops the program from asking the users if they want to run the program. CHANGE_RUNEP causes Professional to run the starting external program without asking the user.

E - CONFIGURATION OPTIONS

Command Line or .CFG Option

Change the Name of the Configure File Used. CFG=<file name>

Normally EXSYS Professional uses the file <knowledge base name>.CFG to set configure options. This can be changed by using the command line option CFG=filename. The specified file will be used instead of the normal file. The files EDITXSP.CFG or EXSYSP.CFG will still be read, as will any other command line arguments. Note: This can only be used in the command line, EDITXSP.CFG or EXSYSP.CFG. Using this command in the file <knowledge base name>.CFG will have no effect.

E - CONFIGURATION OPTIONS

Command Line or .CFG Option

Allow Data from External Programs to be Modified During Change and Rerun CHANGE_EXT

The CHANGE_EXT option allows data from external programs to be displayed for modification during a change and rerun. Data from external programs is not normally displayed. Displaying this information is particularly useful for data that was returned from a program called with a /M option to allow multiple items of data to be returned.

E - CONFIGURATION OPTIONS

Command Line or .CFG Option

Change the Name of the Command File Executed. COMMAND=<file name>

EXSYS Professional supports command files. A command file is an optional file which contains commands that override the usual operations of EXSYS. The default mode for EXSYS is backward chaining, using all rules with results displayed at the end. The command file can completely change the way in which rules are used. See chapter J for information on the command language. If there is no command language file present, EXSYS will use its default modes of operation. However, if the command file is present, EXSYS will use it. The default command file which EXSYS looks for is <knowledge base name>.CMD. For example, if the knowledge base was named ACCTS, EXSYS Professional would look for the default command file ACCTS.CMD. The default command file name can be changed with the command line or .CFG option COMMAND=<filename> in which case <filename> will be used as the command file. If the COMMAND= option is used, Professional will not look for <knowledge base name>.CMD.

E - CONFIGURATION OPTIONS

Command Line or .CFG Option

Control of Runtime Menu Options


This series of commands allows the developer of an expert system to control the options that are available to the end user. There are times when you may want to prevent the end user from doing a number of functions such as displaying rules, quitting/saving, asking for change/rerun, and so on. The following command line options allow various menu options to be turned on or off individually. WHYOFF ?OFF Disables WHY when asking for a qualifier or variable. Disables ? when asking for a qualifier or variable (automatic if no .HLP file is available). Disables QUIT/SAVE when asking for a qualifier or variable and when the final results are displayed . Disables HELP during the run. Prevents the end user from changing the threshold limit value for displaying choices. Disables printing results from the final conclusion screen. Prevents the end user from changing sort type in -100 to +100 mode. Disables change and rerun. Disables asking how a conclusion was reached from the final conclusion screen.

QUITOFF

HELPOFF LIMITOFF

PRINTOFF SORTOFF CHANGEOFF HOWOFF

The end use can circumvent the options that prevent rule display by editing the .CFG file. However, to ensure that your end user will not have access to the rule display, use the rule locking options with password protection.

E - CONFIGURATION OPTIONS

10

Command Line or .CFG Option

Automatically Reads a Series of Records of Data and Executes the Rules DATALIST DATALIST=<filename>

The DATALIST command tells EXSYS that there is a list of data in the file RETURN.DAT which needs to be read. The list can contain multiple sets of data for batch mode analysis. The program will behave as if an external program had already been called that wrote the data to this file. This has two advantages. 1. The structure of the data in a DATALIST allows a series of records to be separated by the END statement. EXSYS Professional will read the first set of data, analyze it, write its report on that data, then read the next set of data, analyze it, and continue with this process until it is finished. This is a very powerful technique that allows an expert system to analyze large amounts of data in a batch mode. This process is described in Section H14 on analyzing data base reports. 2. It allows you to run a very large program to create the return data. An external program must fit into memory at the same time as EXSYS. The memory used by EXSYS reduces the available memory and may prevent some external programs from running. With the DATALIST command, a batch file can be written to call a program and have it create the RETURN.DAT file, then when that program exits, the batch file calls EXSYS. This way both programs do not have to be resident in memory at the same time.

E - CONFIGURATION OPTIONS

11

The DATALIST command can also be used with a filename DATALIST=<filename> In this case, EXSYS will read the file <filename> rather than RETURN.DAT for the data used in the datalist. However, there could be a problem if a datalist call and an external program call are wanted at the same time. This could create problems because both the datalist file and the external program would try to use RETURN.DAT for data. The form DATALIST=<filename> avoids this problem. For example, the command DATALIST=ZZZ.DAT will cause Professional to read DATALIST data from ZZZ.DAT, leaving RETURN.DAT available for external program calls. See chapter H on external program calls and Section H14 on analysis of lists of data for more information on the use of DATALIST.

E - CONFIGURATION OPTIONS

12

Command Line or .CFG Option

Change the Standard Ending Message if No Choices are Set ENDMSG=text

This command option will replace the standard ending text message if no choices fire. The specified text will then be used as the new ending text. The default ending message if no choices fire is NO CHOICES RECEIVED A VALUE GREATER THAN THE THRESHOLD VALUE ___ In some cases it may be confusing or inappropriate to display this message to an end user. It may be better to provide some specific instruction if no choices fire, such as informing the end use that he should contact the author of the expert system for further instruction. For example, you might have the program say ENDMSG=ERROR: Call (911)555-1234 for assistance. This replaces the standard ending message with instructions on how to get assistance. If you choose the replace the standard ending message, your new text must be at least one character long and must be on a single line.

E - CONFIGURATION OPTIONS

13

Command Line or .CFG Option

External Program Flag File Control EP_FLAG_FILE=file EP_TIME_INC=#

These command options control the flag files necesary for calling external programs in MS Windows and Macintosh. See Sections H3 and H4 for details of using these commands.

Add Extra Space When Printing Rules EXTRA_SPACE=#

This command option adds extra space between lines when printing rules to a printer. This is helpful if you want to add space in the printout for changes, notes, or some other form of additional comment. If you dont invoke the command option EXTRA_SPACE=#, then EXSYS will automatically calculate the space between the lines. The # parameter is a numeric value in pixels. In general, a character is 12-15 pixels, so to add an extra character width between lines use EXTRA_SPACE=15

E - CONFIGURATION OPTIONS

14

Command Line or .CFG Option

Stops Execution When Any Choice Has a Final Value Set Greater Than 0 FIRSTONLY

The FIRSTONLY command tells EXSYS to stop execution after any choice receives a value of 1 in the 0/1 system, or a value of 10 in the 0-10 system of probability. This is useful for expert systems that are designed to pick only one solution to a problem. Once the single solution has been found, the FIRSTONLY command will cause the execution to stop and display the results. The FIRSTONLY command does all this without asking the user unnecessary questions related to the other choices.

E - CONFIGURATION OPTIONS

15

Command Line or .CFG Option

Forward Chaining Options FORWARD NOBACKWARD FINALPASS

FINALPASS This command makes EXSYS do a final forward chaining pass through the rules after it has finished the backward chaining. Backward chaining will invoke a rule only if it is relevant to a choice. This option allows a final pass to test all ruleseven if not relevant to a choiceto see if they are valid. It can be used with the RUN command to execute external programs that are not referenced in rules related to choices. FORWARD This command line option keeps EXSYS from performing a backward chain on each of the choices. Instead, the FORWARD command makes EXSYS examine each rule in the knowledge base, in order of occurrence. Backward chaining is still used to derive information needed in testing the IF conditions of a rule. The FORWARD command can result in much faster execution than backward chaining of the choices. NOBACKWARD This command line option prevents EXSYS from performing a backward chain function to derive information. However, EXSYS will still examine the choices in order. Note: All rules that derive information must occur in the knowledge base prior to the need for the derived information. This command is usually used in conjunction with the FORWARD command.

E - CONFIGURATION OPTIONS

16

The effect of FORWARD, BACKWARD and FINALPASS can be seen in a simple example. Consider the following set of rules:
RULE 1: IF Y IS TRUE THEN CHOICE 2 - Probability 3/10 8/10 RULE 4: IF X IS TRUE THEN CHOICE 1 - Probability

RULE IF z THEN Y ELSE Y

2: IS TRUE IS TRUE IS FALSE

RULE 5: IF z IS TRUE THEN W IS TRUE

RULE 3: IF X IS TRUE THEN CHOICE 2 - Probability 7/10

Normal Backward Chaining


EXSYS normally tests rules by looking for the first rule with choice 1 in its THEN or ELSE part. EXSYS then tests the IF conditions of that rule. If any information on the IF conditions can be derived from other rules, those rules are invoked through backward chaining. The program then looks for the next rule relevant to each following choice until it has gone through all of the rules. The process is then repeated for those rules relevant to choice 2, choice 3, and so on, until the list of choices is completely tested. If a rule is not relevant to any choice, or does not assign values to a variable whose value is displayed at the end of a run, it will not be used. With no command line options, the set of 5 rules listed above would execute in the following manner: 1. First the program would look for rules that contain CHOICE 1. The first, and only place it finds CHOICE 1 is in Rule 4. The program then looks to see if there is any way to derive information about the IF condition in this rule. Since X is not in the THEN or ELSE part of any other rule, EXSYS would then ask the user for the value of X. The user input would determine if Rule 4 is valid or not.
E - CONFIGURATION OPTIONS
17

2. The program would then look for the rules that contain CHOICE 2. EXSYS finds the first mention of CHOICE 2 in Rule 1. Since the IF condition of this rule can be derived from Rule 2, the program invokes Rule 2 through backward chaining to derive information. Since there are no rules that would aid in determining if the IF condition in Rule 2 (Z IS TRUE) is valid, EXSYS asks the user about Z. 3. EXSYS will then look for the next rule with CHOICE 2 in itRule 3. Since the program already knows the status of X, this rule can be tested and, if it is found to be valid, EXSYS will use it. 4. When all the choices have been tested, the program stops and displays the results. Notice that rule 5 has not been used. This is because it does not have a choice in it and W is not needed in any rule relevant to a choice. Irrelevant rules are not used. The order of operations would be: Test Rule 4Used for Choice 1 Ask X Test rule 1Used for Choice 2 Test Rule 2Invoked by backward chaining from Rule 1 Ask Z Test Rule 3Used for Choice 2

With the FINALPASS Option


The FINALPASS option causes a final pass through the rules, testing any unused rules. In the example above, the rules would execute as described above, however there would be a final pass to test all rules that had not been used previously. In this case, Rule 5 would be tested and, if valid, it would be used. The order of operations would be: Test Rule 4Used for Choice 1 Ask X Test rule 1Used for Choice 2 Test Rule 2Invoked by backward chaining from Rule 1 Ask Z Test Rule 3Used for Choice 2 Test Rule 5Checked in Final Pass

E - CONFIGURATION OPTIONS

18

Using the FORWARD Option


With the FORWARD command line option, EXSYS tests the rules in the order they occur, using backward chaining to derive any addition information that EXSYS needs. With this option chosen, this is how the rules would run: 1. Rule 1 is tested. Since the IF condition needs information on Y, backward chaining invokes Rule 2 to derive information. The user is then asked for information on Z. 2. Since Rule 2 has already been tested, the program moves on to rule 3 and asks the user about X. 3. The program then tests rule 4. Since X is already known, the user is not asked any information. 4. The program then tests Rule 5, even though it is not relevant to any of the choices. The order of operations would be: Test Rule 1 Test Rule 2Invoked by backward chaining from Rule 1 Ask Z Test Rule 3 Ask X Test Rule 4 Test Rule 5

Using the NOBACKWARD Option


The NOBACKWARD option keeps EXSYS from using backward chaining to derive information. However, rules are checked in the order that the choices occur. 1. First the program looks for the first rule that contains Choice 1. Rule 4. To test Rule 4, EXSYS asks the user for information on X. 2. The program then looks for the first rule with Choice 2 in it Rule 1. Previously, when rule 1 was tested, backward chaining invoked rule 2 to derive information about Y. Since backward chaining has been switched off, the user is asked about Y. The program has not needed to ask about Y previously. 3. The program then looks for the next rule with Choice 2Rule 3. Since information is already known about X, the program doesnt ask the user for additional information.
E - CONFIGURATION OPTIONS
19

4. In this case, both rules 2 and 5 are not used. The order of operations would be: Test Rule 4Used for Choice 1 Ask X Test Rule 1Used for Choice 2 Ask Y Test Rule 3

With BOTH the NOBACKWARD and FORWARD Options


Using both of these options allows a purely forward chaining run and allows for substantial improvement in speed. In this case, there is a single pass through the rules with no backward chaining. Note: All rules that derive information must occur in the knowledge base prior to the need for the derived information. In our example, Rule 2 derives information that is needed for Rule 1. To correct this, move Rule 2 to be the new Rule 1.
RULE 1: IF z IS TRUE THEN Y IS TRUE ELSE Y IS FALSE RULE 4: IF X IS TRUE THEN CHOICE 1 - Probability 8/10 RULE 5: IF z IS TRUE THEN W IS TRUE

RULE 2: IF Y IS TRUE THEN CHOICE 2 - Probability 3/10 RULE 3: IF X IS TRUE THEN CHOICE 2 - Probability 7/10

E - CONFIGURATION OPTIONS

20

1. The program tests Rule 1 and asks the user about Z. 2. The program tests Rule 2. Rule 1 has established the state of Y, so no additional information is needed from the user. 3. The program then tests Rule 3. The program asks the user about X. 4. The program then tests Rule 4. 5. The program then tests Rule 5. The order of operations would be: Test Rule 1 Ask Z Test Rule 2 Test Rule 3 Ask X Test Rule 4 Test Rule 5

The options on order of rule execution can greatly improve the speed of large expert systems through the use of the FORWARD NOBACKWARD option. The use of the FORWARD NOBACKWARD option can improve execution speed by a documented factor of 20 to 50 for large systems. If the knowledge base is structured so all the rules used to derive information can be placed in the rule list prior to the point where the derived information is needed, the rules can be run with the FORWARD option. Unless the rules have complex derivation paths that require backward chaining, the NOBACKWARD option can also be used. To be certain that the rules can be run in the forward mode, use the print command to print a cross-reference list on the qualifiers, choices and variables. The list will show what rules each qualifier and variable is used in and if it is used in the IF, THEN or ELSE part. Make sure each qualifier, variable and choice is not used in a THEN or ELSE part after it is used in an IF part. In other words, all uses in the THEN or ELSE part of the rules must occur numerically before the uses in the IF part. Remember, using FASTERP rearranges rules and can have an effect on the use of forward chaining.

E - CONFIGURATION OPTIONS

21

Command Line or .CFG Option

Sets an Alternate Knowledge Base Help File HELP=file

EXSYS Professional usually expects to find the custom help for the knowledge base in <knowledge base name>.HLP. If you wish to change to the use of another help file, use the command HELP=. For example, HELP=TEST.ABC would use this file as the custom help file for the system. This can be useful if there are different help files for different users who need help aimed at differing knowledge levels. This can also be used to assign a help file in a different language to a system without duplicating the rules. This does not change the system help. See the command EXSYS_HELP= for information on how to assign a path to the system help file EXSYSP.HLP

E - CONFIGURATION OPTIONS

22

Command Line or .CFG Option

Limits Options Available to User of Runtime LIMITOPTIONS

This command causes the EXSYS Runtime to limit the options available to a user. 1. When asking questions: QUIT is eliminated from the menus and ignored. 2. In the display of rules: the options to see what is known, examine choices, scroll and jump to other rules are eliminated from the menus and ignored. 3. In the display of the results: the options to display all, display greater than, print, change sort method and quit are all eliminated from the menu and inactive. This option is useful when creating expert systems for users that might be confused by more advanced options and where you wish to only have the minimum functions available. LIMITOPTIONS applies only to the Runtime and has no effect on the editor. For more information, see the Control of Runtime Menu Options Command Line Options.

E - CONFIGURATION OPTIONS

23

Command Line or .CFG Option

Turns Off Loop Error Checking NOCHECK


This command prevents EXSYS from performing loop error checking during a run. This slightly increases speed, but is definitely not recommended for use during development since loop errors are difficult to detect without error checking and can lead to incorrect conclusions. Loop errors should be found and corrected in a knowledge base. The lock on error checking is intended for use only when the knowledge base has been fully developed and is free of loop errors.

Displays Choices Without Sorting by Value NO_CH_SORT

This option doesnt allow EXSYS to display the choices sorted in order of their final, assigned confidence. Instead, the choices are displayed in the numeric order of the choices themselves. Only choices over the threshold value will be displayed. For example, suppose the first choice, CHOICE1, has a value of 3 and the second choice, CHOICE2, has a value of 5. Normally, CHOICE2 would be displayed before CHOICE1 in the list because its final confidence value is higher. However, with the NO_CH_SORT option, CHOICE1 will be displayed first because it is the first choice in the list over the threshold value. This is useful when the numeric order of the choices is significant.

E - CONFIGURATION OPTIONS

24

Command Line or .CFG Option

Switches Off Color Display NOCOLOR

This command switches color off and forces the program to run in monochrome. This command is not needed if you are using a monitor attached to the IBM monochrome display card, but it may be necessary if you are using a monochrome monitor attached to a color display card. Some monochrome monitors are unreadable when color text is sent to them. This command also should be used when running on the Macintosh Powerbook.

Prevents Deletion of RETURN.DAT After Reading NODELETE

After EXSYS reads the data returned from an external program, it erases the file that returned the data. This prevents EXSYS from inadvertently reading the file again the next time an external program call does not return data. If you do not want to automatically delete the file returning the data, use the configure option NODELETE. This applies to RETURN.DAT or another file name if the RETURN= command has been used.

E - CONFIGURATION OPTIONS

25

Command Line or .CFG Option

Prevents Display of Results at Any Time NO_DISPLAY

This option prevents EXSYS from displaying results at any time. The screen will immediately go to the "RUN AGAIN?" question. This should be used with the RERUN=Y or RERUN=N configure option described below. This option can be used to force restarting without showing results. Otherwise, a .OUT or .CMD file would be needed to do this.

Disables Option to Use Passwords NO_PASSWORD

If the NO_PASSWORD option is used, EXSYS will not ask for a password when saving rules. All rules will be saved unencrypted. If you never use passwords, put the NO_PASSWORD command in the EDITXSP.CFG file.

E - CONFIGURATION OPTIONS

26

Command Line or .CFG Option

Eliminates Starting Questions NOQUESTIONS

This option prevents the Runtime program from asking users if they wish information on running EXSYS, or if they want to have the rules displayed. The program simply displays the splash screen, then begins executing rules. This command has no function in the Editor.

Do Not Display the Title and Author NOTITLE

EXSYS Professional normally displays the title and author of a system before the program is run. Adding the NOTITLE command suppresses this display and the system immediately starts running.

E - CONFIGURATION OPTIONS

27

Command Line or .CFG Option

Prevents Display of Values Assigned to Choices NO_VALUES

This command does not allow EXSYS to display any values for choices in the final result screen. Only the values for qualifiers and variables will be displayed. This is useful if all you need to know is which choices were selected, not the values assigned to them. In some cases, the display of these values may actually confuse endusers. However, the end-user still has all the options for asking HOW.

E - CONFIGURATION OPTIONS

28

Command Line or .CFG Option

Prevents Backward Chaining on Simple Expressions NOVARCHAIN

This command doesnt allow EXSYS to backward chain expressions of the type [X] is given the value [X] + n [X] is given the value [X] - n [X] is given the value [X] * n [X] is given the value [X] / n (where n can be any constant). Backward chaining on large numbers in expressions similar to the one displayed above, can result in very long chains that use up the available stack space. Note: This option should be used with care since [X] must have a value assigned to it prior to encountering this expression through initialization or any other assignment.

E - CONFIGURATION OPTIONS

29

Command Line or .CFG Option

Allows Choices with No Value Set to Test False. NULLCHOICE

When a choice is used in the IF part of a rule, EXSYS attempts to determine a value for the choice to test if the condition is true. If no value for the choice can be derived, EXSYS issues an error message because the condition is indeterminate. This is a good idea in general, but there are some systems that operate on the principle that choices which dont receive values are assumed to be false. This can be a valid way to approach some problems. However, it is better to not rely on undefined choices in the IF part. The NULLCHOICE option turns off error messages if condition choices have no values. Such choices set the condition to FALSE. Note: This option should be used with caution, since it disables error messages and can result in actual errors remaining undetected.

E - CONFIGURATION OPTIONS

30

Command Line or .CFG Option

Changes the Name of the File Used to Pass Data to External Programs PASS=filename

This option changes the name of the file that is used to pass data to external programs from EXSYSP or EDITXSP. When an external program is called, data can be passed to the program in a file. The default name of the file is PASS.DAT. If it you want to change the name of this file, use the PASS= command. Once the name is changed, it applies for the entire run and must be used in all calls to external programs that pass data. For example, passing data on a RAM disk is much faster than passing it on a conventional disk. For example, if you want to pass data on a RAM disk labeled drive D, but still want to use the name PASS.DAT., use the command PASS=D:PASS.DAT. If you redefine the file in which data is passed, be sure to modify the called program so it knows where to look for the data that is being sent.

E - CONFIGURATION OPTIONS

31

Command Line or .CFG Option

Load Password from Command Line or .CFG File PASSWORD=key

The PASSWORD= command allows a password to be passed into a file. This tends to defeat the purpose of a password, but is useful when several expert systems will be called sequentially from a batch file. The password can be entered when the batch file is called. The password is then passed to each expert system as a replaceable parameter. For example, the following DOS batch file would call three expert systems with the same password. EXSYSP SYSTEM1 PASSWORD=%1 EXSYSP SYSTEM2 PASSWORD=%1 EXSYSP SYSTEM3 PASSWORD=%1 The %1 in the batch file would be replaced with the parameter entered after the batch file name. For more information on replaceable parameters in batch files, see your DOS manual. The PASSWORD= command can also be used when calling EXSYS from another program. This enables you to have an encrypted file with the password supplied by the other program. This prevents the knowledge base from being run by any source other than your starting program.

E - CONFIGURATION OPTIONS

32

Command Line or .CFG Option

Reads Custom Help File when Rules are Read READHELP

This command is used with custom help files. (See Section I12 for information on custom help files). When a user inputs ? in response to a request for information, EXSYS checks to see if information on the qualifier or variable is in the custom help file <knowledge base name>.HLP. The file is rapidly examined and only read once since file pointers are set during the read. While this process is rapid, it does take about 1 or 2 seconds per 10k of custom help file to reach the end of the file. In some cases you may want to have the examination of the .HLP file and the setting of pointers be performed when the rules are read in. The READHELP command tells EXSYS to read the .HLP file when the rules are read and it also sets the file pointers at the same time. Calls to the custom help file are then almost instantaneous. When this command is used with the Editor, EDITXSP.EXE, the .HLP file is examined and the file pointers are set whenever the RUN option is selected. This allows modification of the .HLP file between runs by using the <Ctrl-X> command to go to the operating system to modify the .HLP file and then return to EDITXSP.

E - CONFIGURATION OPTIONS

33

Command Line or .CFG Option

Recovers Data Saved Previously with QUIT RECOVER RECOVER=<filename>

This option tells EXSYS that you may wish to recover data saved with the QUIT command during an earlier run. If the RECOVER command is used, the menu option Recover Input under the Questions menu will be checked. At the start of a run you will then be asked for the filename of the file that contains the saved data. The program will read in the data and, after displaying the starting title screens, return to where you left off. The RECOVER command can also be used with the filename RECOVER=<filename>. In this case, without asking the user, the program automatically recovers the input saved in the file <filename> and begins the run immediately where it left off earlier under the QUIT command. In the Editor, the recover option can be selected by selecting the menu option Recover Input under the Questions menu prior to a run. The RECOVER command is REQUIRED to recover data in the Runtime.

E - CONFIGURATION OPTIONS

34

Command Line or .CFG Option

Turns Off DISPLAY Command During "Change and Rerun" REDISPOFF


When the CHANGE AND RERUN command is selected at the end of a run, all the rules that are used during the rerunning of the knowledge base and all valid rules fire. If those rules have DISPLAY( ) commands in them, the text will be displayed on the screen. In some expert systems, you may want to turn off the DISPLAY( ) commands during CHANGE AND RERUN operations. The REDISPOFF command prevents EXSYS from running DISPLAY commands encountered in the rules during a CHANGE AND RERUN. This is useful if only the final conclusion is important and the DISPLAY commands are not directly relevant to the conclusions being tested. If this command is not used, the default is to run the DISPLAY commands in change and rerun.

E - CONFIGURATION OPTIONS

35

Command Line or .CFG Option

Releases Memory Used for String Variables RELEASE_STRINGS

When EXSYS assigns values to string variables there is a small portion of memory that is not released and is lost. This is due to the way certain operations (CHANGE AND RERUN and UNDO) are performed and the need for data in other operations. Normally, the amount of memory lost per cycle is about the size of the strings being assigned and is inconsequential. However, if a system makes extensive use of string variables and will cycle hundreds or thousands of times, the memory loss can become significant. This is very rarely a problem, but the RELEASE_STRINGS command prevents this small amount of memory from disappearing. Unfortunately, RELEASE_STRINGS prevents UNDO and CHANGE AND RERUN from working since they both require that the earlier data be available. The RELEASE_STRINGS option allocates memory only once for all string variables. The memory is released when the run finishes. CHANGE AND RERUN and UNDO cannot be used with this option. The default maximum string length is 256 characters. If this needs to be changed use RELEASE_STRINGS=<max length>. For example, RELEASE_STRINGS=1000 would allow 1000 character strings. Strings longer than the maximum are truncated and null terminated. Remember, each string variable will have this much memory allocated for it, so try to use the minimum. If you have 50 string variables, but the longest string that will be input is 20 characters, RELEASE_STRINGS=20 will use only 1k of memory, while just RELEASE_STRINGS will use over 12k (50 * 256). The release strings options should rarely be needed. If it is not used, the minimum amount of memory will be used by EXSYS. Note: The RELEASE_STRINGS option disables the CHANGE AND RERUN and UNDO functions that require the memory not be released.

E - CONFIGURATION OPTIONS

36

Command Line or .CFG Option

Changes the Name of the Report Specification To Be Used REPORT=<filename>

The default report generator specification associated with a knowledge base is <knowledge base filename> .OUT. The REPORT= command allows a different report specification file be assigned to a knowledge base. If there is a knowledge base named TEST, the default report specification would be in the file TEST.OUT. You could assign a different report specification named OTHER.RPT with REPORT=OTHER.RPT in the command line or configure file. Note: This command effects only the report produced at the end of a run. It does not effect reports produced as a result of rules firing.

E - CONFIGURATION OPTIONS

37

Command Line or .CFG Option

Turns off Report Generator During "Change and Rerun" RERPTOFF

When the CHANGE AND RERUN command is selected in EXSYS, the report generator will be called at the end of the run if a report specification file is present. In some expert systems, you many to not run the report generator during CHANGE AND RERUN operations since it might overwrite the original data. When used in the command line or a .CFG file, this command prevents EXSYS from running the report generator during a change and rerun operation. This is useful in allowing a user to experiment with CHANGE AND RERUN without affecting the file originally produced by the report generator. If this command is not used, the default is to run the Report Generator in CHANGE AND RERUN.

E - CONFIGURATION OPTIONS

38

Command Line or .CFG Option

Changes the Default to Rerun Rules at End RERUN

When EXSYS finishes a run, the user is asked if he wishes to rerun the rules. The default for this option is NO. In some cases the system may be designed to rerun the rules many times. The RERUN command changes the default to YES. The user can still override the default value of YES.

RERUN=Y
This prevents Professional from asking the user if he wishes to run the system again. ESXYS instead assumes an answer of YES and automatically restarts after the results screen.

RERUN=N
This doesnt allow EXSYS to ask the user if he wants to run the system again. EXSYS instead assumes an answer of NO and automatically exits (runtime) or returns to edit mode (editor) after the results screen.

E - CONFIGURATION OPTIONS

39

Command Line or .CFG Option

Changes the Name of the File Used to Return Data from External Programs RETURN=filename

This option changes the name of the file used to return data to EXSYS from an external program. The default name that will be used if this option is not selected is RETURN.DAT. If you are calling a program that supplies its own file extension or if for some reason you want to return data in a file with another name, use the RETURN= command to define the new default name. Only one name can be used in an expert system. If you change the file name, that file must be used for returning data from all external program calls. The RETURN= command can also be used to change the default drive that data is passed on. It is often desirable to pass data on a RAM disk for maximum speed. For example, if you have a RAM disk defined as drive D, and you want to pass data on D in a file TRANS.DAT use the command RETURN=D:TRANS.DAT in either the command line or a configure file. Note: Make sure that the external program called by EXSYS writes its data to this same file.

E - CONFIGURATION OPTIONS

40

Command Line or .CFG Option

Changes How Rounding is Handled in Calculations ROUND

EXSYS can be made to calculate the final value of a choice slightly differently than older versions of EXSYS. Older versions of EXSYS use truncation of fractions. For example, if you are using the 0-10 confidence system and you assign it values 4, 6 and 7, the exact average would be 5.66666... EXSYS would display a final value of 5 (truncated value) while 6 would be the rounded value. ROUND causes rounding rather than truncating of the choice values. The default mode for EXSYS is truncation which provides compatibility with earlier versions. The command ROUND causes EXSYS to use the rounding mode. Important Note: If you use ROUND with some expert systems that rely on truncation, especially if you are testing on choice values, you could get different results when you use the new version of EXSYS on programs designed under an older version of EXSYS. If the ROUND option is not used, both the new version of EXSYS and all its previous versions will provide the same results.

E - CONFIGURATION OPTIONS

41

Command Line or .CFG Option

Writes a File of Information on Rule Execution, Data and Other Functions. TRACE TRACE = filename

When a knowledge base is run, you can turn on a trace (TRACE) of the execution of the rules as they fire. This can be very useful when trying to debug a knowledge base. The trace file can be created on disk or sent to the printer. The trace feature is turned on by entering TRACE=filename in the command line or a .CFG file. For example, if you start by entering EDITXSP TEST TRACE=XXX.TRC it will cause EDITXSP to write information to the file XXX.TRC when the rules are run. This command option allows you to collect information on which rules fired, when the rules fired, what values were set, and a wide selection of other information. The trace file this creates is an ASCII file that can be printed or examined with an ASCII editor. The TRACE from each run of the rules is appended to the trace file until you restart the editor. If a variable [X] is finishing with a different value than you believe it should have, you can search the trace file for [X] to see where the value of [X] is being set and why it is different from what you thought it should be. Using TRACE greatly simplifies checking for logic errors in your rules.

E - CONFIGURATION OPTIONS

42

Command Line or .CFG Option

Sets the Number of Times UNDO Can be Called. UNDO=#

EXSYS allows a user to change his mind and undo previous answers. This is particularly useful when a user running a system makes a typographical error. The default is to allow the user to backup a maximum of 3 steps. The command line option UNDO allows this maximum to be changed to anything from 0 to 10. The command UNDO=0 will disable the UNDO function. When UNDO is active, and there is some data to undo, the menu asking for input will include the item UNDO-<Ctrl-U>. Pressing the Ctrl and U keys simultaneously will cause the program to back up one question. Doing the same thing again will back up another question, until the program no longer displays the UNDO menu option. The default value of 3 is usually appropriate, but there are times when it might be desirable to change it. First, if an error in input is not likely to be detected until more than 3 questions later, the limit should be raised. Second, if memory is very limited, you may want to reduce the number of steps the user can back up, or disable the function with UNDO=0. The UNDO option does have some memory overhead, which can become significant for large systems close to the memory limitations. UNDO can only work within a single knowledge base. If an earlier answer leads to exiting one module and starting another, EXSYS will not be able to step back. Likewise, if the rules are being run from the command language, it can only back up within a single RULES command.

E - CONFIGURATION OPTIONS

43

Command Line or .CFG Option

Sets WORKING Screen Color WKG_COLOR=color

The screen which displays the WORKING message has a cyan background. If several external programs are called that have different backgrounds, you may want to change the background color of the WORKING screen. The color parameter is the name of the color to use. color: RED GREEN BLUE CYAN MAGENTA YELLOW BLACK DKGRAY GRAY LTGRAY WHITE

E - CONFIGURATION OPTIONS

44

Command Line or .CFG Option

Sets Printer Width WIDTH=#

This option causes the EXSYS Professional report generator to do word wrap on a line whose width is specified by # in characters per line. The default value is 80. This is useful when printing reports on wide paper.

E - CONFIGURATION OPTIONS

45

Chapter F Report Generator


EXSYS Professional has a built-in report generator. This enables the user to control what data is output to a disk file or printer. The report specifications can include (among many other things) the commands to print notes, choice, value or qualifier values, restart the program and exit to the operating system. The report output specification is an ASCII file with the same file name as the expert system with an .OUT extension. For example, if you have an expert system named ENGINES, you would have two files on your disk ENGINES.RUL and ENGINES.TXT. A report generator specification would be put in a file called ENGINES.OUT. The .OUT file is an ASCII file created with a text editor or a word processor that can create ASCII files without additional control characters. By having the .OUT file created and modifiable by text editors, the end user (who has only the runtime program) will be able to make modifications to the generated report. The EXSYS Professional Editor is not used to modify the output specification.

F1: Commands
The report specification is made up of a series of commands, each of which may cause one or more lines to be printed to the output file or cause some other operation to be performed. Many commands can have several basic forms. These are listed in order of complexity. Most report specification commands have a variety of options controlled by "/" followed by a letter. The following list of commands gives the basic command first, followed by the available options. If options are selected, they follow the basic command on the same line. Special Note to UNIX users: In the UNIX version of EXSYS, replace the / in all commands with -. For example, /D would become -D. This prevents confusion with UNIX path names.
F - REPORT GENERATOR
1

Report Generator Command

Make a Beep Noise BEEP

The BEEP command causes EXSYS to make a beep noise to alert a user.

F - REPORT GENERATOR

Report Generator Command

Print Data on Choices


C C <choice #> C <choice #> <test exp> C <choice #> <test exp> <2nd test exp> C "choice text">C "choice text" <test exp> C "choice text"<test exp> <2nd test exp> C <test exp> C <test exp> <2nd test exp>

choice #the number of the choice to be output. choice texta text string unique to a single choice. The string must be in quotes. test exp.the first test you should use to determine if the choice should be output. The available tests are <,>,=,>=,<=, and <>. The type of test is followed by the integer value to test the choice against (e.g. =10, <5, >9). If no test expression is specified, >0 is assumed. 2nd test exp.an optional second test you should use to determine if the choice should be output. The available tests are <,>,=,>=,<=, and <>. The type of test is followed by the integer value against which EXSYS will test its choice. The second test expression can be used to select choices only in a specific range. For example, C >5 <8 would display those choices with final values of 6 or 7. There must be a space between the first and second tests. The choice commands print data on the final values provided to the choices at the end of the run. The data is output to the current file that has been opened with the FILE command. There are several forms of the choice command that allow specification of what choice and under what conditions information will be output. A variety of options allows printing of other information when the choice meets the test criteria.

F - REPORT GENERATOR

1. The simplest form of the command is just C. This outputs to the file (one choice per line) the choice text and final value of all choices that received a value greater than 0. 2. The second form of the command, C <choice #> allows specification of a particular choice for output if the value received is greater than 0. Only that particular choice will be output. The choice text and value will be output. 3. The third form of the command, C <choice #> <test exp> or C <test exp> outputs the text and value of the choice only if the final value meets the test condition. If the choice number is omitted, all choices are tested against the test expression and all those passing the test will be printed. 4. The fourth form of the command, C <choice #> C <test exp> <2nd test exp> or <test exp> <2nd test exp>

outputs the text and value of the choice only if the final received value meets both the first and second test conditions. If the choice number is omitted, all choices are tested against the test expressions and all choices passing the test will be printed.

Options:
/T /V /L /S Output the text of the choice only. The value is not output. Output the value of the choice only. The text of the choice is not output. Add an extra blank line following the output if the test is true. Causes EXSYS to suppress the line feed at the end of the line.

F - REPORT GENERATOR

/"string" If the test(s) on the choice value is true, do not output the choice text or value but instead output the text in the string. The string must be enclosed in double quotes and the first quotation mark must immediately follow the /. /[var#] If the test(s) on the choice value is true, do not output the choice text or value, instead output the value of variable var#. The number of the variable must be in brackets ( [ ] ), and the left bracket ( [ ) must immediately follow the / without any spaces in between. /[var name] If the test(s) on the choice value is true, do not output the choice text or value, instead output the value of the variable named in the brackets ( [ ] ). The name of the variable must be in brackets, and the left bracket ( [ ) must immediately follow the / without any spaces in between. /Q Forces the program to terminate and exit to the operating system if the test condition was met. If the command also causes output, the output will be written before exiting. Goto a specified line if the conditional test is met. See the GOTO command in this section for more information on branching. Print the choice only if it had no value assigned (no rules fired which assigned a value to the choice). This automatically does a /T, since there is no value to output. This can be combined with other options such as /".

/G

/U

Examples:
C C2 = 10 will cause the text and final value of all choices with values greater than 0 to be sent to the output file. will cause the text and value of choice 2 to be sent to the output file if the final value of choice 2 is 10.

C "Part 1234" will cause the text and value of the choice whose text contains "Part 1234" to be sent to the output file.

F - REPORT GENERATOR

C4 >7 /[9] will output the value of variable 9, either numeric, string or text, if choice 4 received a value greater than 7. C4 >7 /[X] will output the value of variable [X], either numeric, string or text, if choice 4 received a value greater than 7. C >=5 <=8 /T will cause only the text (not the value) of all choices that receive values greater than or equal to 5, but less than or equal to 8, to be sent to the output file. C4 >9 "THE DATA IS GOOD" /L will cause the text "THE DATA IS GOOD" to be sent to the output file if choice 4 has a final value greater than or equal to 9 and then an extra blank line will be added. C5 /V will cause the final value of only choice 5 to be sent to the output file.

F - REPORT GENERATOR

Report Generator Command

Close a File for Display CLOSE


This command closes an open file without opening a new one. This command is only needed with the DISPLAY command which requires that the file be closed. The FILE command or the end of the report specification will also close an open file. With the CLOSE command, a file can be created, closed and displayed without having to create extra files. For example, FILE XXX commands.... CLOSE DISPLAY XXX WARNING: Do not execute report generator commands other than DISPLAY after a CLOSE command without first executing another FILE command to open a file.

F - REPORT GENERATOR

Report Generator Command

Display a File in a Window


DISPLAY <filename> <options> DISPLAY [string variable] <options>
filenamethe name of the file to display. string variable a string variable which has a value that is the name of the file to display.

Options
/C - File to display uses GUI Custom Screen Commands The /C option should be used if the file to display contains Custom Screen Commands. See chapter I for a discussion of the GUI Custom Screen Language. /N - No wait after screen is displayed The /N option allows the DISPLAY command to display the requested file in a window and immediately continue processing. This can be useful for report files that are created and displayed. By using the /N option, several report data windows can be simultaneously active. /S - Small text The /S option causes the DISPLAY command to display a text file using a small font. The default is to use a larger font. This option only applies to ASCII files. /F - Fixed size font The /F option causes the DISPLAY command to display a text file using a fixed size font. This is useful for aligning columns of data. The /S and default fonts are proportionally spaced and aligning data can be difficult. This option only applies to ASCII files. The DISPLAY command displays the contents of an ASCII file or Custom Screen Language Command file on the screen. Users can go forward or backward in the file as they examine it. When they are finished reading the file, the report generator function continues. 1. The first form DISPLAY <filename> allows the name of the displayed file to be explicitly specified.
F - REPORT GENERATOR
8

2. The second form DISPLAY [string variable name] allows a variable to set the name of the file to display. In this way, the knowledge base can set the name of the file to be displayed. The DISPLAY command is very useful for displaying the report produced by the report generator to the user. Important note: When displaying the file produced by the report generator, close the file before displaying it.

Examples:
DISPLAY INFO1.T displays the contents of the ASCII file INFO.T for the user to read. FILE F1 . . (report generator commands) . CLOSE DISPLAY F1 creates a file F1 containing output from the report generator commands. The file F1 would be closed by the CLOSE command. The DISPLAY command would then display the contents of the recently created report on the screen or terminal. The CLOSE command must be used to close F1 before it is displayed. DISPLAY SCR1.SCR /C

displays the file SCR1.SCR which contains Custom Screen Commands.

F - REPORT GENERATOR

Report Generator Command

Exit to the Operating System EXIT


The EXIT command forces EXSYS to close the output file and exit to the operating system. This is useful when EXSYS is used in a batch mode with other programs. The EXIT command makes it easy to run EXSYS, send the results to a file, exit EXSYS and then use the batch file to call other programs which will use the data file.

F - REPORT GENERATOR

10

Report Generator Command

Select the Output File FILE <filename>


This command should be the first one in a report specification. It tells the program which file it should direct its output toward. If the FILE command appears again in the report specification, the first file will be closed and all subsequent output will be to the new file. The current contents of the existing file to be opened are lost unless you use the /A option. The file name can contain a drive designator and path. To send output to a printer attached to a PC, make the file name LPT1. Any open output files will be closed when the end of the report specification is reached. It is not necessary to have a final FILE command to close files. The <filename> may be any legal filename or logical device name. For PC machines using MS-DOS, names such as LPT1, PRN, CON, COM1:, AUX are legal. Depending on the version of DOS you are using, you may or may not need to add a colon ( : ) after device names.

Options:
/A opens the file for output with the data appended to the existing contents of the file. If the file does not exist, the file will be created. If /A is not added, the contents of the existing file will be lost and replaced by the new data.

Example:
FILE B:REPORT.A . . (output commands) . FILE C:\DATA\LIST.RPT /A . . (output commands) . FILE LPT1 . . (output commands) .
F - REPORT GENERATOR
11

would open the file B: REPORT.A, deleting any previous data in this file. All data would be sent to this file until the second FILE command is reached. This second FILE command would close the file B: REPORT.A and open the file C:\DATA\LIST. RPT. Since the second FILE command used the /A option, the new data will be appended to the data already in the file. All data would be sent to C:\DATA\LIST.RPT until the third FILE command. The third FILE command would close file C:\LDATA\LIST.RPT and open the printer attached to the LPT1 port of the PC for the subsequent output.

F - REPORT GENERATOR

12

Report Generator Command

Print Text Only for First Set of Data in DATALIST FIRST "string"

When the FIRST command precedes text in double quotes, the text will be printed only during the processing of the first record being examined with the DATALIST command. This allows a title to be put on reports without having the text print each set of data in a DATALIST file. If there is no datalist, the FIRST command behaves as a simple, quoted string.

Example:
FILE XYZ.RPT /A FIRST "REPORT OF EXPERT SYSTEM" C RESTART could be used with a DATALIST command to examine a series of sets of data. The title "Report of Expert System" would be printed only once. The choices would be printed for each set of data in the DATALIST.

F - REPORT GENERATOR

13

Report Generator Command

Unconditional and Conditional Branches GOTO and /G:

EXSYS Professional supports conditional and unconditional GOTO commands in the report generator. The line which GOTO will transfer to is indicated by a single line that starts with a colon ( : ), followed immediately by the label name. The command GOTO LABEL will transfer execution to the line following the line marked label. For example: commands... :XXX commands... GOTO XXX will cause the execution to return to the line ":XXX" in the report file. Alternatively, the /G:label option can be used with the C, Q or V commands in the report generator to produce a conditional GOTO. In this case, the GOTO will be executed only if the C, Q or V command is valid. For example: V1 > 4 /G:end will transfer the line ":END" only if variable 1 has a value greater than 4. By combining conditional and unconditional GOTO commands, the report file can be made much more flexible. Note: If you use GOTO to jump over a FILE command, the FILE command will not be executed.

F - REPORT GENERATOR

14

For example, the report file FILE FILE1 . . . GOTO XXX . FILE FILE2 . . :XXX . . would not open FILE2, but would continue writing to FILE1.

F - REPORT GENERATOR

15

Report Generator Command

Print the Data Input by the User INPUT


The INPUT command sends all the data input by the user to the file opened with the FILE command. Data on all qualifiers and values asked for by the program or obtained from external programs will be sent to the output file.

Options:
/L Adds a blank line after each line of data is output

F - REPORT GENERATOR

16

Report Generator Command

Print the Notes and References NOTE NOTE <rule#> REF REF <rule #>
rule # the number of the rule to print the note or reference from. The NOTE and REF commands cause the report generator to print the note or reference of a specified rule to the report file if the rule has fired. The optional rule number can be left off, in which case notes or references from all rules that fired will be printed to the report file in the order of the rules. This provides a convenient way to provide the information in the notes and references to a user, even if rule display is turned off.

Example:
NOTE REF 4 would cause the printing of the notes from all rules that fired, followed by the reference from rule 4, if rule 4 fired.

F - REPORT GENERATOR

17

Report Generator Command

Data on Qualifiers Q Q Q Q Q

<qual#> <qual#> <test> "Qual name" "Qual name" <test>

qual #the number of the qualifier to output. If the number is omitted, all qualifiers are tested. testa qualifier is tested by checking to see if its values are true. The test condition is a list of the qualifier's values such as numbers separated with commas (just like creating a condition when building a rule). If any of the values specified in the test are set, the test is true. For example, Q2 1,3,7 would be true if qualifier 2 has values 1,3 or 7 true. The test will be true if any of the listed values are true. Qual namethe name associated with the qualifier. Note: This is not the text of the qualifier, but the name used to identify the qualifier. The name must be in quotes. The qualifier command outputs the text of a qualifier with all the values that have been set to the file opened with the FILE command. There are three main forms of the command. 1. The simplest form is just Q. This outputs the text of all qualifiers that had values set.

F - REPORT GENERATOR

18

2. The second form of the command is Q <qual#> Q "Qual name" This outputs the qualifier specified by number or name if any of its values were set during the run. Any values set are also output. 3. The third form of the command is Q <qual#> <test> Q "Qual name" <test> This outputs the qualifier specified by number or name if any of its values were set during the run and the set values match at least one of those specified in the list of values in the test. Any set values are also output.

Options:
/L /S Adds a blank line after the qualifier is output. Suppresses the line feed at the end of the line.

/"string" If the test is true, the qualifier/values are not output, but instead the string in quotes is output. /[var#] If the test(s) is true, do not output the qualifier/values, instead output the value of variable var#. The number of the variable must be in brackets ( [ ] ) and the left bracket ( [ ) must immediately follow the slash ( / ) without any spaces in between. /[var name] If the test(s) is true, do not output the qualifier/values, instead output the value of the variable whose name is specified in the brackets ( [ ] ). The name of the variable must be in brackets ( [ ] ) and the left bracket ( [ ) must immediately follow the slash ( / )without any spaces in between. /Q forces the program to exit to the operating system if the test condition was met. If the command also causes output, which will be written before exiting. causes output of the data on the qualifier(s) to be in a form that can be read in with a DATALIST command. This makes it possible to have one expert system call another and then pass data between them. Such chaining of knowledge bases can be very powerful.
F - REPORT GENERATOR
19

/D

For example, suppose qualifier 7 is THE 1. 2. 3. 4. COLOR IS: RED WHITE GREEN BLACK

and values 1 and 3 are chosen. The report generator line Q 7 would output : THE COLOR IS RED OR GREEN However, the line Q 7 /D would output Q7 1 3 (a form that could be read in with the DATALIST command line option). There can also be an optional number specified immediately after the /D (no space between D and the number). This number will be used in the output of the data as the destination qualifier number. This allows you to specify a different qualifier to be used when the data is read in by another expert system using DATALIST. To use the qualifier example above, the report generator line Q 7 /D outputs Q7 1 3. However, the line Q 7 /D12 would output Q12 1 3. The 12 specified after the /D caused qualifier 12 to be specified as the destination of the data. This allows data from one expert system to be passed to another, even though the qualifier numbers do not necessarily match. If a number is not specified after the /D, the number used will be the same as the qualifier or variable specified. See Chapter M on blackboarding for more information on passing information between knowledge bases. /G Go to a specified line if the conditional test is met. See the GOTO command in this section for more information on branching. Print the qualifier only if it did NOT have a value assigned, (no rules fired which assigned a value to the qualifier, it was not asked of the user and no external program assigned a value). This can be combined with other options such as /".

/U

F - REPORT GENERATOR

20

Examples:
For these examples use qualifier number 6 with an associated name "COLOR" and four values: Qualifier 6: The color is 1 red 2 white 3 blue 4 green Q6 or Q "COLOR" causes the status of qualifier 6 to be output. Q6 2,3 causes the status of qualifier 6 to be output if the statement the color is white or the statement the color is blue is true. Q6 1 /"RED PAINT WILL BE NEEDED"causes the text RED PAINT WILL BE NEEDED to be output if the qualifier statement "The color is red" is true.

F - REPORT GENERATOR

21

Report Generator Command

Restart the System RESTART


The RESTART command resets all choices, qualifiers and variables to their initial state at the beginning of a run. This is particularly useful in two cases. 1. Analysis of a data reportAn EXSYS knowledge base can be designed so it sequentially analyzes many sets of data through the use of an external program or by the command line option DATALIST. In such a case, start the output specification with: FILE filename /A

to have each new report appended to the existing report. End with RESTART to cause EXSYS to restart and run the next set of data. The program will end automatically when the end of the DATALIST is reached and EXSYS returns to the operating system. 2. MonitoringAn EXSYS expert system can be designed using external programs to obtain data that monitors the status of a process. If no action is necessary, it is only necessary to restart the run. If action is necessary, data can be output, alarms can be triggered, and a variety of other actions can be performed.

F - REPORT GENERATOR

22

Report Generator Command

Call an External Program RUN <filename> <parameters>


The RUN command allows external programs to run from the report generator. The filename can be any program executable from the operating system. The parameters can be constants or EXSYS variables. The parameters can be any parameter that could be used in a RUN( ) command from within EXSYS. See Chapter H for more information on the RUN( ) command.

Options:
/C Causes the parameters to be passed as command line arguments. If the /C is not present, the parameters will be passed in PASS.DAT. Causes the first # arguments to be passed on the command line, with the rest passed in PASS.DAT. See Chapter H on calling external programs for more / options. For example, RUN BASIC GRAPH1 /C executes the basic program GRAPH1 from the BASIC interpreter. RUN TEST [X] [Y] [Z] runs the program TEST with the values of variables [X], [Y] and [Z] passed in PASS.DAT. RUN TEST [X] [Y] [Z] /C runs the program TEST with the values of variables [X], [Y] and [Z] passed in on the command line. RUN TEST [X] [Y] [Z] /2 runs the program TEST with the values of variable [X] passed on the command line and the values of variables [Y] and [Z] passed in PASS.DAT.
F - REPORT GENERATOR
23

/#

Report Generator Command

Save the Input Data for a RECOVER SAVEDATA <filename>


This command is the same as selecting the QUIT mode when the results are displayed and you are entering the filename. The input which is provided by the user and then used to obtain the conclusions is stored in the file <filename> in such a way that it can be recovered by the option to recover previously saved input. This is not the same as the INPUT command which writes the user input to the specified file as ASCII and which can not be read back into the program.

F - REPORT GENERATOR

24

Report Generator Command

Print Text String "text"


Placing a string in quotes causes the report generator to output the quoted text to the file opened with the FILE command. The string must start and end with a double quotation mark ( " ). The quotation marks will not be output. A line feed will automatically be added to the end of the line in the output file.

Example:
FILE CON: "The report is being produced" FILE XYZ.RPT . . . Will write the message "The report is being produced" to the screen, then open the file XYZ.RPT for output. The message will stay on the screen until the report specification is finished. This is a useful technique for giving the user status reports when very large report files are used.

F - REPORT GENERATOR

25

Report Generator Command

Print Data on Variables


V V <variable #> V <variable #> <test exp> V <variable #><test exp><2nd test exp> V <test exp> V <test exp> <2nd test exp> [variable name] [variable name] <test exp> [variable name]<test exp><2nd test exp>

variable #the number of the variable to output. If the number is omitted, all variables will be tested for output. variable nameThe name of the variable to output. The name must be enclosed in brackets ([ ]). test expA test to determine if the variable should be output. The available tests are >,<, =, >=, <=, and < >. The test expression must be followed by either a numeric value (for numeric variables) or a string in quotes (for string variables). If string variables are used, the validity of the test is based on alphabetical order. 2nd test expA second test to determine if the variable should be output. The available tests are >,<, =, >=, <=, and < >. The test expression must be followed by either a numeric value (for numeric variables) or a string in quotes (for string variables). If string variables are used, the validity of the test is based on alphabetical order. This second test is used to select variables only within certain bounds. For example: V2 >23.5 <78.4 would output the text and value of variable 2 only if its value was between 23.5 and 78.4. There must be a space between the first and second tests. The variable command outputs the value of variables to the file opened with the FILE command. There are a number of forms of the variable command, most of which have the option of either specifying the variable by number or by name.
F - REPORT GENERATOR

26

1. The simplest form of the command is just V. This outputs the text and value of all variables that received a value during the run. The text of the variable and the value will both be printed, unless options are selected. If a variable is a text only variable, it will be displayed only if it was applied by a rule that fired. 2. The second form of the command, V <variable #> or [variable name] specifies which variable is to be output. Both the text of the variable and the value will be printed, unless options are selected. If a variable is a text-only variable, it will be displayed only if it was selected by a rule that fired. 3. The third form of the command, V <variable #> <test exp> or V <test exp> or [variable name] <test exp> specifies which variable is to be output and sets a test condition which the variable must meet to be printed. Either numeric or string variables can be tested. The text of the variable and the value will both be printed, unless options are selected. If a variable is a text only variable, it will be displayed if it was selected by a rule that fired. If the variable number is omitted, all variables will be tested against the test expression and all variables passing the test will be printed. 4. The fourth form of the command, V <variable #> <test exp> <2nd test exp> or V <test exp> <2nd test exp> or [variable name] <test exp> <2nd test exp> specifies which variable is to be output and sets two test conditions which the variable must meet to be printed. Either numeric or string variables can be tested. The text of the variable and the value will be printed unless options are selected. If a variable is a text-only variable, it will be displayed if it was selected by a rule that fired. If the variable number is omitted, all variables will be tested against the test expressions, and all variables passing the tests will be printed.

F - REPORT GENERATOR

27

Options:
/T /V /L /S Output the text of the variable only, not the value. Output the value of the variable only, not the text. Add an extra blank line after the output. Suppress the line feed at the end of the line.

/"string" If the test is true, do not output the variable, but instead output the quoted text in the string. The string must be enclosed in double quotes and the first quotation mark must immediately follow the slash (/). /[var#] If the test(s) is true, do not output the variable text or value, instead output the value of variable var#. The number of the variable must be in brackets ([ ]), and the left bracket ( [ ) must immediately follow the slash (/) without any spaces in between. This is very useful for printing identifiers, such as a person's name, if they meet the test conditions specified. /[var name] If the test(s) is true, do not output the variable text or value. Instead, output the value of the variable named in the brackets ([ ]). The name of the variable must be in brackets, and the left bracket must immediately follow the slash (/) without any spaces in between. /Q Forces the program to exit to the operating system if the test condition was met. If the command also causes output, the output will be written before exiting. Output data on variables in a form that can be read in with a DATALIST command. This makes it possible to have one EXSYS expert system call another and pass data between them. Such chaining of knowledge bases can be very powerful. For example, suppose variable 3 has a value of 7.9. The report generator line V 3 /D would output V 3 7.9 to the output file rather than printing the text to describe variable 3 followed by the value. There can also be an optional number specified immediately after the /D (no space between D and number). This number will be used in the output of the
F - REPORT GENERATOR
28

/D

data as the destination variable number. This allows you to specify a variable to send the data into. To use the example above: the report generator line V 3 /D

outputs V 3 7.9. However, the line V 3 /D12 would output V 12 7.9. The 12 specified after the /D caused 12 to be specified as the destination of the data. This allows data from one expert system to be passed to another, even though the variable numbers do not necessarily match. If a number is not specified after the /D, the number used will be the same as the variable specified. See Chapter M on Blackboarding for more information on passing data between knowledge bases. /F-m.n Formats the output variable value with format controlled by the parameters. This can be used only for numeric variables. The optional hyphen causes left justification. The default is right justification. The optional parameter m is the total field width. The optional parameter n is the number of places displayed right of the decimal point. For a variable with value 1234.5678: /F6.0 outputs 1235 /F6.2 outputs 1234.57 /F10.3 outputs 1234.568 /E prevents EXSYS from printing the equal sign between the text and the value of the variable. Go to a specified line if the conditional test is met. See the GOTO command in this section for more information on branching. Print the variable only if it did NOT have a value assigned (No rules fired which assigned a value to the variable, it was not asked of the user and no external program assigned a value.) This automatically does a /T, since there is no value to output. This can be combined with other options such as /".
F - REPORT GENERATOR
29

/G

/U

/,

Commas can be inserted into a numeric variable value in the report generator by using the /, option. This would normally be done in conjunction with the /F#.# option to format the output. For example, a variable [X] equal to 123456578.9 could be output various ways: Report Generator Command [X] [X] /, [X] /F15.2 [X] /F15.2 /, Output 12345678.9 12,345,678.9 12345678.9 12,345,678.9

Note: if there are preceding format spaces from a /F#.# command, the /, command will remove one space for each comma added. This preserves the total field width produced by the /F command. Enough extra spaces must be left to allow for the commas. If there is not enough space, the total field width will expand.

Examples:
V causes the text and value of each variable to be output. V2 > 1.5 /T causes the text of variable number 2 to be output if the value of the variable is greater than 1.5. V4 <0 /[8] outputs the value of variable 8 if the value of variable 4 is less than 0. V4 <0 /[X] outputs the value of variable [X] if the value of variable 4 is less than 0. V7 = "ABCD" /L causes the string variable number 7 to be printed if its value string is ABCD, then a blank line will be output. [X] /V causes the value of the variable [x] to be output. [X] >= 2.7 /"THE VALUE WAS HIGH" causes the string THE VALUE WAS HIGH to be output if the value of the variable [X] is greater than or equal to 2.7.
F - REPORT GENERATOR
30

Examples:
FILE B:RESULTS "RESULTS OF EXSYS RUN" C > 2 "USER INPUT" INPUT will cause EXSYS to: 1. Open the file B: Results. 2. Send the text RESULTS OF EXSYS RUN to the file. 3. Send the text and value of each choice with a value greater than 2 to the file. 4. Send the text USER INPUT. 5. Send all the input data obtained from the user. FILE C:\ANALYSIS\TEST.RPT /A V3 /V /L C = 10 /T "*********" FILE LPT1 V3 /V C > 5 BEEP EXIT will cause EXSYS to: 1. Open the file C:\ANALYSIS\TEST.RPT so output is appended to the end of the file, if one exists. 2. Output only the value of variable 3, followed by a blank line. 3. Output a list of only the text of all choices with values of 10. 4. Output "*********" to separate records in the file. 5. Close the first file and open the printer for output. 6. Print the value of variable 3 to the printer. 7. Print all choices that had values greater than 5. 8. Make a beep sound to alert the user. 9. Exit EXSYS and return to the operating system. FILE LPT1 FIRST "POSSIBLE CANDIDATES" FIRST "____________________" FIRST " " C3 >8 /[6] RESTART This would be used with a DATALIST command line option to provide data.

F - REPORT GENERATOR

31

It causes EXSYS to: 1. Open the printer for output. 2. After analyzing the first record, EXSYS prints the report title "POSSIBLE CANDIDATES" (This will be printed for the first record only). 3. Underline the title. 4. Skip one line. 5. Print the value of variable 6 (possibly a name) if choice 3 received a value > 8. 6. Read the next record of data and restart the analysis.

F - REPORT GENERATOR

32

Chapter G Internal Commands and Data Acquisition

In general, EXSYS Professional does not care what text you enter for a qualifier or variable, provided you don't duplicate the names of the special commands that EXSYS recognizes. These internal commands can be used to perform a variety of functions, control EXSYS rule execution and interface to external sources of data. The EXSYS Internal commands can be associated with a qualifier or variable, added as part of the THEN or ELSE part of a rule or (in most cases) included in the command file (<knowledge base name>.CMD).

G1: Internal Commands in a Rule


To add a command in the THEN or ELSE part of a rule, click on the Command button in the rule editing window. Note, commands may not be added in the IF part of a rule, but may be associated with a qualifier or variable that is tested in the IF part.

G - INTERNAL COMMANDS

Rule Title and Number IF: Qualifier Var. / Math Choice Command Repeat IF Part THEN Part ELSE Part Insert AND OR New OR OK Change Delete And/Or Cancel Prev Next Note Reference Name

G2: Commands Used for Data Acquisition


Data acquisition commands may also be associated with a qualifier or variable. Within the editing screens for the qualifier and variable, clicking on the Data Acquisition button will allow you to associate commands that return data with the qualifier or variable. Only commands that can provide the data needed by the qualifier or variable can be associated. Commands the perform actions--CLEAR, EXIT, etc. may not be associated with a qualifier or variable.

G - INTERNAL COMMANDS

Add / Edit Qualifier Qualifier ## NEW QUALIFIER Nam e:

QUALIFER TEXT ASSOCIATED VALUE LIST

Edit

Replace

Ca ncel Edit

Add

Delete

VALUE WORK WINDOW


Display at end Limit input values to: Default Value: Conf. Options Data Acqu. Cancel

OK

Add / Edit Variable Name: Prompt:

Numeric String Text Only Display at end OK

Initialize: Upper Limit: Lower Limit

Data Acquisition Cancel Conf. Options

G - INTERNAL COMMANDS

G3: Internal Command Window


In either case, the Internal Command window will assist you in building the desired command. In many cases, the same syntax you use for the command can also be used in the command language, report generator and even custom screen language. The use of the commands in this way is discussed in the section on the appropriate subject.
Data Acquisition Commands

Direct Command Input Run External Program Lotus 123 dBase III Interface Table Lookup Display a File Frame / Array Lookup LINDO Interface

Report Generator Clear Data or Rules Stop Rule Exec.

OK

Cancel

The edit region at the top of the screen will display the command. This command can be edited directly, or its value can be created using the windows that build the commands. To guarantee correct syntax for the commands, we recommend you use the individual command windows. To select a command window, click on the desired command. When the command in the top edit box is correct, click on the OK button.

G3.1: Direct Command Input


Use direct command input if you know the exact command syntax to enter. A window is opened to enter the command. This is really about the same as editing in the edit region of the general command window. This is especially useful if you are editing an existing command and want to make a minor change. In general, however, it is better to use the individual command windows since the syntax of some commands can be complicated.
G - INTERNAL COMMANDS
4

Internal Command Qualifier / Variable THEN/ELSE Command File Report Generator

Blackboard Interface BB_RD(parameters) BB_WR(parameters) BB_DE(parameters)


Blackboard files can be used to share data between expert system modules. See Chapter M for a full discussion of blackboard files and command syntax.

G - INTERNAL COMMANDS

Internal Command Qualifier / Variable THEN/ELSE Command File Report Generator

dBase III Interface DB_GK(parameters) DB_PK(parameters) DB_GN(parameters) DB_PN(parameters)


Four internal commands allow EXSYS to read or write directly from dBase III files. Note: Underlined items can be repeated multiple times. Get data from db file by key: DB_GK(<db file>, <index file>, <index value>, <field name>, <address>) Put data in db file by key: DB_PK(<db file>, <index file>, <index value>, <field name>, <var name>) Get data from db file by record number: DB_GN(<db file>, <rec #>, <field name>, <address>) Put data in db file by record number: DB_PN(<db file>, <rec #>, <field name>, <var name>)

<db file> <index file> <index value>

The full name of the dBase III file to be used. The full name of the file that has the index of the <db file>. The value to search for in the index.

G - INTERNAL COMMANDS

<field name>

The name of the field that containing the data to be read from or the name of the field to be written to. The name of the EXSYS variable in [ ]. The value of the variable will be read from or written to the specified db field. The variable name ALWAYS applies to the field name specified to its left. The item in which to store the obtained data. The item can be a variable, qualifier or choice. For a variable, use the name of the variable in [ ] For a qualifier, use "Q" followed by the number of the qualifier or the name of the qualifier in quotes For a choice, use "C" followed by the number of the choice or a unique text string in quotes. There must NOT be any spaces in the string between the C, V, or Q and the number or quotation mark. The number of the db record to work with.

<var name>

<address>

<rec #>

The database file name, index name and index variable may be string variables that are set by expert system. <var name> must be an EXSYS variable. Since the field name and associated variable may be repeated as many times as desired, multiple fields from the same record can be passed or returned on a single call.

G - INTERNAL COMMANDS

dBase Command Window


The window for building dBase Interface commands allows you to build commands that retrieve multiple data items with a single call.
dBase Data Acquisition GET data by KEY value PUT data by KEY value DB Filename: Index Filename Index Value Record Number FIELD containing data to read EXSYS Address to put data in GET data by RECORD NUMBER PUT data by RECORD NUMBER

OK

Prev. Field

Next Field

Cancel

To build a dBase internal or data acquisition command, select GET or PUT by KEY or Record Number then enter the database filename. If an index file is used, enter the index filename and index value used to select a record. If record numbers are used, enter the record number used to select a record. Fields in the record and EXSYS addresses are used in pairs. Each field must have a corresponding EXSYS address. With GET, the value of the field will be put in the EXSYS address. With PUT, the value in the EXSYS address will be put in the field specified. Enter the first pair of field and address names. To enter a second pair in the same command, click on Next Field. The Field and EXSYS Address edit boxes will clear and you can enter another pair. This can be done repeatedly. To examine a field or variable pair already entered, click on Prev Field. This will display the previous pair. When all field or variable pairs have been entered, click on OK. The general Command window will return, with the dBase command in the top edit window. When you click on OK again, the command will be added to the rule, qualifier or variable (depending on how the window was called.)

G - INTERNAL COMMANDS

Use in Rules
In rules, dBase commands are usually used to set data as the result of a rule firing. In some cases, a rule may also trigger a dBase command to get data into a particular variable. Since the commands to get data have a variable associated with them, they can be called independently of a specific variable. The following example, IF ...... THEN DB_PN(parts.dbf, 5, price, [X]) will WRITE the value of variable [X] into field "price" of record 5 of database "parts" if the rule fires.

Use in a Variable
When a dBase command is associated with a variable, it will automatically be called if a value for the variable is needed. Rather than asking the end user for the value, the call to dBase will be made. If a value for the variable is never needed in the system, the dBase call will never be made. To associate the dBase call with a variable, the dBase command precedes the text entered as the Prompt Text for the variable. The dBase call will not be displayed when the prompt text is used in reports, final results, etc. For example, if we had a variable [X] with a prompt "The price is," we would associate a dBase call with the variable by changing the prompt to: DB_GN(parts.dbf, 5, price, [X]) The price is If the value of [X] is needed, the program will READ the value of field "price" from record 5 of database "parts" into variable [X]. If needed, there could be additional field and address pairs in the expression to get more data from the record. If the variable is a string variable, the value returned will automatically be handled as a string--even if it contains numeric data. If the variable type is numeric, the value returned will automatically be converted to a numeric. Be sure to return string data (names, addresses, etc.) to string variables. If the data from the database is to be used in numeric calculations, make sure it is returned to numeric variables. When the data acquisition windows are used to build the command, the command will automatically be added to the prompt text.
G - INTERNAL COMMANDS
9

Use in a Qualifier
The use of a dBase command in a qualifier is very similar to the use in a variable. The dBase command precedes the qualifier text. The command will not be displayed when the qualifier text is used in reports, conclusions, etc. However, when a value for the qualifier is needed, the dBase call will automatically be used. For example, if we had a qualifier named "COLOR," The color is 1 red 2 blue 3 green and we wanted to get the color from the data base, we could change "The color is" to DB_GN(parts.dbf, 5, part_color, Q "COLOR") The color is When the qualifier's value was needed the dBase call would automatically be made and the value in the field part_color in record 5 would be used to set the qualifier named "COLOR." The data returned from the database for qualifiers must be in the form of a string containing the numbers of the values to select. If more than one number is returned, they must be separated by spaces of a comma. For example, if the database call returned "1,2" to a qualifier, it would set the first two values of the qualifier to be true. If it returned "3," it would set the third value to true. When the data acquisition windows are used to build the command, the command will automatically be added to the qualifier text.

Use in Choices
The command text cannot be associated directly with a choice. Instead, dBase commands that assign values to choices must be in the THEN /ELSE part of a rule or used in one of the other command files. When a value is to be assigned to a choice, the data returned from the database must be consistent with the confidence mode being used. For example, if the mode is 0-10, the value must be an integer between 0 and 10. The value returned will be combined with the other values given to the choice by rules that fired. For example (in the 0-10 system), a value of 10 assigned by a database call would lock the value at 10. A value of 5 would be averaged with any other values assigned to the choice.

G - INTERNAL COMMANDS

10

DB_GN(parts.dbf, 5, val, C 4) will return the value of field "val" into choice 4.

Use in the Report Generator


In the report generator, dBase commands are usually only used to write data out to a database file as part of the conclusion of the system. Commands to get data can be used, but must be used with care since they can change the data used by the system and thereby confuse the results. Commands to get data would usually only be used in conjunction with a command file to control the execution or to get data that is only written out as part of the report and not used by the rules. For example, the following command in the report generator DB_PK(parts.dbf, part.ndx, A567, price, [X], conf, C 7) will WRITE the value of variable [X] into field "price" of the record in database "parts," indicated in the index file "part.ndx" by the value "A567," and write the confidence value to choice 7 into the "conf" field of the same record.

Use in the Command Language


Database commands in the command language can be used to control when data is obtained, rather than associating the data acquisition commands with a specific qualifier or variable. This often gives more control and is easier to read. There may also be dBase commands at the end of the command file to write results back to a database.

Top Record Function


The EXSYS function TOPREC( ) returns information on the number of records in a database file. This is particularly useful when running an expert system against every record in a file. To call the function in an expression, use TOPREC(<filename>) where <filename> is the name of the database file in quotes. For example, TOPREC("price.dbf")
G - INTERNAL COMMANDS
11

would return the number of records in the database file "price.dbf." This function can be used like sin( ), cos( ) or any other EXSYS function in an expression. It can be used most effectively in the command language, such as in the following: SET [I] 0 WHILE ([I] < TOPREC("price.dbf")) RULES ALL REPORT DBRPT CLEAR ALL SET [I] ([I]+1) WEND The above example would initialize the variable [I] to 0 then run the rules against each record in a database. After each record, the values are cleared and [I] is incremented and checked against the total number of records in the data base. If there is another record, the rules are run again. Each run adds the report produced with the report specification DBRPT. A simple command file like this can run an expert system against each record in a database to select those with particular characteristics and write them to a report.

G - INTERNAL COMMANDS

12

Internal Command THEN/ELSE Command File

Clear Out Known Data or Rules CLEAR(....)

The internal command CLEAR( ) allows a qualifier, variable, choice or rule to be reset to an unknown or unused state. Normally, EXSYS will only ask a qualifier or variable once and will only fire a rule once in a run. There are cases, however, where it is desirable to clear user input or re-use a rule. The CLEAR command makes this possible. When the CLEAR command is encountered, EXSYS will reset the rule, qualifier, variable or choice to its original unknown state or flag a rule as unused. This allows user input to be erased. If the qualifier, variable or choice is needed later during the run, it will be reasked or rederived from other rules. If a rule is reset with CLEAR, it can be reused if needed. There are many forms of the CLEAR( ) command. The easiest are CLEAR(Q #) CLEAR(V #) CLEAR([var name]) CLEAR(C #) CLEAR(R #) Clear Qualifier # Clear Variable # Clear Variable [var name] Clear Choice # Clear Rule #

For example, suppose we want to allow the user to ask for more information on a qualifier. We could have the qualifier Qualifier 7: The model needed is: 1 Model A 2 Model B 3 Model C 4 Need more information

G - INTERNAL COMMANDS

13

and a rule Rule 22 IF 1 THEN ...... ELSE 1 2 3 DISPLAY(model.inf) CLEAR(Q 7) CLEAR(R 22)

The model needed is Model A or Model B or Model C

where the THEN part of rule 22 performs some action relevant to the run. If the user selects a model from the list, the THEN part will continue execution. If the user selects value 4, NEED MORE INFORMATION, the ELSE part will fire and display the file MODEL.INF (an file created to provide assistance to the user), CLEAR qualifier 7 to unknown and reset rule 22 to unasked. The program would then go back and again ask for information on qualifier 7 and re-use rule 22. This same effect could be achieved more easily with hypertext help associated with some of the word; it is used here only to show the use of the CLEAR command.

Clearing Ranges
The internal command CLEAR( ) can also be given a range to clear, rather than your having to specify each item individually. CLEAR(X a-b) will clear all items between a and b. The X can be Q, V, C or R for qualifier, variable, choice or rule. In the following example, CLEAR(R 34-56) CLEAR(Q 1-5) CLEAR(X ALL) will clear ALL items. The X can be Q, V, C or R for qualifier, variable, choice or rule. In the following example, CLEAR(R ALL) clears all rules CLEAR(V ALL) clears all variables CLEAR(ALL) will clear ALL qualifiers, variables, choices and rules.
G - INTERNAL COMMANDS
14

will clear all rules from 34 through 56 will clear the first 5 qualifiers

CLEAR(R THIS) clears the rule that the command occurs in. This applies ONLY to rules. The command prevents problems when rules are reorganized. In the following example, IF ...... THEN ...... ELSE CLEAR(R THIS) will clear the rule if the rule is false, regardless of the rule's number.

Clearing by Name
In EXSYS, both rules and qualifiers have optional names. These names can be used in the CLEAR command with wild card matching. The name must be in quotation marks used in place of a number to specify the rule or qualifier. Names may be given to groups of rules for convenience when referring to them. Wild card matching allows referring to groups of rules. In wild card matching, a "?" may be used anywhere in the name to match any single character and a final "*" will match any string. The "*" may only be used as the last character. For choices, rather than names, the choice can be identified by any unique text sub-string in the choice. CLEAR(Q "name") CLEAR(R "name") CLEAR(C "text") In the following example, CLEAR(Q"A*") CLEAR(R"XXX") CLEAR(C"ZZZ") CLEAR(R"?XX") will clear all qualifiers whose NAME starts with A will clear the rule named XXX will clear all choices that have the string "ZZZ" in them will clear all rules with 3 character names ending in "XX" Clear Qualifier name Clear Rule name Clear the Choice containing the string "text."

G - INTERNAL COMMANDS

15

CLEAR Command Window


CLEAR: Qualifier Variable Choice Rule Everything By: Number Name Range of Numbers All This OK Cancel

To build the command using the CLEAR command window, click on one of the buttons on the left to indicate what is to be cleared. The appropriate items on the right will be enabled or disabled. Select one of the items on the right an, if necessary, enter the number or name of the item. Then click on OK. The general Command window will return, with the CLEAR command in the top edit window. When you click on OK again, the command will be added to the rule.

While Loops
Clearing rules can also be used to create WHILE loops, in effect, in a set of rules. In the above example, until the user selects a Model from the list, the question will be reasked. The same effect could be obtained from a value calculated by other rules or external programs. The rule(s) would loop until the IF conditions were true. Note: The preferred, and recommended, technique of creating WHILE loops is through the command language. CAUTION: CLEAR allows certain problems to be handled by EXSYS that are not possible otherwise, but clearing already asked or derived information should be done with great care. The changing of the normal EXSYS flow can easily result in an infinite loop or errors of logic. If you experience problems with CLEAR, use TRACE to see what is happening as the rules fire. This should help to find the error in the logic. Experience has shown that it is almost impossible for our technical support to help with CLEAR( ) problems over the phone due to the very convoluted logic that can result from use of this command.
G - INTERNAL COMMANDS
16

Internal Command THEN/ELSE Command File

Read a File of Data DATAREAD(filename)


The DATAREAD command will read a file of data and set the values for various EXSYS variables, qualifiers and choices. The format of the data is identical to that in a return file from an external program or datalist file. Data passed back to EXSYS must be in an ASCII file with only one data item per line. The format of each line must be For qualifiers: Q <qual #> <value(s)> or Q "name" <value(s)> V <var #> <value> or [var name] <value>

For variables:

For choices: C <choice #> <value> or C "text" <value > <qual #>, <var #> or <choice #>: The number of the qualifier, variable or choice that the data is being passed back to. "name": The name associated with the qualifier. "text": A unique text sub-string in the choice. <value>: The data to assign. See Section H6 for more details on the syntax of data passed to EXSYS. This is useful if you have several files of data created by a single external program. Normally, an external program call will read only one file of return data, but with DATAREAD, other files can be also read.
G - INTERNAL COMMANDS
17

DATAREAD Command Window


The window to build a DATAREAD command only asks for the name of the file containing the data. If an EXSYS string variable containing the file name is desired, it must be put in [[ ]] for replacement.

File containing data to read:

OK Cancel

G - INTERNAL COMMANDS

18

Internal Command THEN/ELSE Command File Report Generator

Display a File In a Window


DISPLAY <filename> <options> DISPLAY [string variable] <options>
filename: the name of the file to display string variable: a string variable whose value is the name of the file to display

Options
/C: File to display uses GUI Custom Screen Commands The /C option causes the DISPLAY command to parse the file for Custom Screen Commands. See Chapter I for a discussion of the GUI Custom Screen Language. /N: No wait after screen is displayed The /N option causes the DISPLAY command to display the requested file in a window then immediately continue processing. This can be useful for report files that are created and displayed. With the /N option, several report data windows can be simultaneously active. /S - Small text The /S option causes the DISPLAY command to display a text file using a small font. The default is to use a larger font. This applies only to ASCII files. /F: Fixed size font The /F option causes the DISPLAY command to display a text file using a fixed-size font. This is useful for aligning columns of data. The /S and default fonts are proportionally spaced and aligning data can be difficult. This applies only to ASCII files. The internal command DISPLAY(filename) causes the file "filename" to be displayed on the screen in a window. The file can be an ASCII file or a file containing EXSYS Custom Screen language commands. If it is an ASCII file, the user can move forward and backward in the
G - INTERNAL COMMANDS
19

file as needed. If it is a Custom Screen file, it can have buttons, scroll bars, mouse regions, etc. The window can be set so that when the user finishes reading the file, execution of the rules continues, or execution can continue as soon as the window is drawn and the user can read it later. This is used to display a larger section of text than is possible in a note or reference. Also, it allows the text to be displayed to the user even though the rule display is switched off. The custom help screen feature can also be used to display text to the user and sometimes is more appropriate than the DISPLAY command See Chapter I for information on custom help screens. The DISPLAY command is very useful for displaying the report produced by the report generator to the user. When displaying the file produced by the report generator, CLOSE THE FILE BEFORE DISPLAYING IT. Here are some examples: DISPLAY INFO1.T would display the contents of the ASCII file INFO.T for the user to read. FILE F1 . . (report generator commands) . CLOSE DISPLAY F1 would create a file F1 containing output from the report generator commands. The file F1 would be closed by the CLOSE command. The DISPLAY command would then display the contents of the newly-created report on the screen or terminal. The CLOSE command must be used to close F1 before it is displayed. DISPLAY SCR1.SCR /C

would display the file SCR1.SCR which contains Custom Screen Commands. IF . . THEN DISPLAY(FILE1)
G - INTERNAL COMMANDS

20

would display the contents of the ASCII file FILE1 on the screen if the rule fired. The text will be displayed immediately when the rule fires, even if execution were not yet complete. IF . . THEN DISPLAY([X]) would display the contents of the ASCII file whose name is stored in the string variable [X] if the rule fired.

Display Command Window


The window to build DISPLAY commands provides some special commands because of the GUI interface.
DISPLAY Command File to Display:

Use Custom Screen commands No wait after display Normal font Small font Fixed space font

OK

Cancel

Enter the name of the file to display. Two types of files can be displayed: simple ASCII text files and files with Custom Screen Commands. If you are using custom screen commands, check the Custom Screen box. If the file is just text, do not check the box.

G - INTERNAL COMMANDS

21

In a GUI, after a window is created, the processing of the expert system can either continue or wait until the window is closed. If you wish the file to be displayed and processing to immediately continue, check the No Wait box. If the box is not checked, the window will be displayed, and processing will wait for the user to click OK to dismiss the window. There are three possible fonts to use in the display box. These only apply to the display of simple ASCII text files. The default is a fairly large font. If there is a large amount of text, it may be better to use the small font. If positioning of the text is important for alignment of columns, use the Fixed font. The default and Small font are proportional and it is difficult to align columns. When the correct parameters are set, click on the OK .

G - INTERNAL COMMANDS

22

Internal Command Qualifier / Variable THEN/ELSE Command File Report Generator

Frame Interface FRAME(parameters)


Frame files can be used to share data between expert system modules and to store data. See Chapter L for a full discussion of frame files and command syntax.

LINDO Linear Programming Interface LINDO(parameters)


EXSYS can be used to create LINDO linear programming model and interpret the results of the LINDO analysis. See Chapter N for a full discussion of the EXSYS / LINDO interface.

G - INTERNAL COMMANDS

23

Internal Command Variable THEN/ELSE Command File Report Generator

Lotus 123 Interface Commands SS_RD(parameters) SS_WR(parameters)


Two commands allow EXSYS to read or write directly from Lotus 123 files. The same commands can be used from within rules, the report generator or the command files. The syntax of the call is the same in each case. Note: Underlined items can be repeated multiple times. To read Cells from a Spreadsheet, use the following: SS_RD(ssname, cell, [varname]) To write Cells to a Spreadsheet, use the following: SS_WR(ssname, cell, [varname]) ssname cell The name of the spread sheet to use, with the .wks or .wk1 extension. The cell to read from or write to. The cell can be specified in the 123 form, column letter followed by row number (e.g.. A4), or by column number, dash or row number (e.g. 4-3 for column 4 row 3). In either case, variable replacement can be done with [[ ]] replacement of variable values. For example, if you want variable [R] to select the row in column G, you could use G[[R]]. The value of [[R]] will be replaced with the value of [R]. If [R] has the value 3, the cell will be G3.

G - INTERNAL COMMANDS

24

If the variable must select the column, use the #-# form. For example, if variable [C] contains the column to use, you could use [[C]]-5 to select a specific column in row 5. You can also use [[C]]-[[R]] to select an arbitrary column/row determined by the variables. NOTE: In all cases, there must not be any spaces in the cell specification; B2 will work, but B 2 will not. Likewise, there must not be any spaces between characters if the #-# form is used. var name The name of the EXSYS variable to use. If the SS_RD is used, the data is read INTO this variable. If the SS_WR command is used, the data is written FROM this variable to the cell. The variable always applies to the cell on its left.

The <cell> and <var name> pairs may be repeated as many times as needed in a single call. For example, SS_RD(salary.wks, C3, [X], D5, [Y], E12, [Z]) will read the contents of cell C3 into [X], D5 into [Y] and E12 into [Z]. The same can be done for the SS_WR command as well. If the variable is numeric, the data will be assigned as numeric-assigning a text string will produce a 0 value. If the variable type is string, the data will be assigned as a string, even if it is numeric data. Likewise, if the variable type is numeric, the data will be written to the spreadsheet as numeric. If the variable type is string, the data will be written as a string. Note that if the SS_RD command is used as the text of a variable; to get data for that variable, you must include the variable name in the SS_RD command. For example, if you want the value of variable [X] to be obtained automatically from cell D7 of a spread sheet, you could make the text associated with [X] SS_RD(data.wks, D7, [X]) The value of ... This will automatically read the data from D7 if [X] is needed. But, you must specify that the data is for [X] in the third parameter of the SS_RD command. This is unlike a RUN( ) command that would "know" the data was for [X].

G - INTERNAL COMMANDS

25

The SS_WR command will not work with Lotus 1 or 1a, since these ignore multiple cells with the same address. It will work with Lotus 2 and clones that allow multiple cells with the same address. Note: The SS_WR command writes the new cell information to the end of the spreadsheet. The SS_RD command reads the first cell with the correct address that it finds. Consequently, SS_WR followed by a SS_RD for the same cell new value. If the cell had no old value, then the new value will be read. Once the spreadsheet is read and saved by 123, the SS_RD will return the new data because 123 will have removed the old data. 123 will correctly display the new data.

Here are some examples: In a Rule, IF ...... THEN SS_WR(price,F35,[X]) will WRITE the value of variable [X] into cell F35 of the spreadsheet "price," if the rule fires. In a Variable, SS_RD(parts,E22,[X],E23,[Available]) The price is is the text associated with a variable [X]. If the value of [X] is needed, the program will read the value cell E22 from the "parts" spreadsheet into variable [X] and the data in E23 into a variable on part availability. If needed, there could be additional cell and variable pairs in the expression to get more data from the spreadsheet. In the Report Generator or Command Language, the line SS_WR(price,H78,[TOTAL COST]) in the report generator will WRITE the value of variable [TOTAL COST] into cell H78 of the "price" spreadsheet.

G - INTERNAL COMMANDS

26

In a WHILE loop, SET [I] 1 WHILE ([I] < 100) SS_RD(parts,E[[I]],[X], F[[I]], [Y]) RULES ALL REPORT SS.RPT CLEAR ALL SET [I] ([I]+1) WEND would initialize [I] to 1 then read the value of row E column [I] into [X] and row F column [I] into [Y]. Then the rules would be executed and a report written. [I] is then incremented until it is greater than 100. In this example, [[ ]] are used to insert the value of the variable in the expression.

Lotus 123 Command Window


The window for building Lotus 123 Interface commands allows you to build commands that retrieve multiple data items with a single call.
Lotus 123 Data Acquisition READ from spreadsheet WRITE to spreadsheet

Spreadsheet Filename

Spreadsheet CELL ID:

EXSYS Address to put data in:

OK

Prev. Field

Next Field

Cancel

To build a Lotus 123 data acquisition command, select READ or WRITE and enter the spreadsheet filename. Cell IDs (row, column) and EXSYS variable names are used in pairs. Each Cell ID must have a corresponding EXSYS variable. In a READ, the value of the cell is put in the EXSYS variable. In a WRITE, the value of the EXSYS variable is put in the cell.

G - INTERNAL COMMANDS

27

Enter the first pair of cell and variable name. To enter a second pair in the same command, click on Next Field. The Cell ID and EXSYS Address edit boxes will clear and you can enter another pair. This can be done repeatedly. To examine a cell or variable pair already entered, click on Prev Field. This will display the previous pair. When all cell or variable pairs have been entered, click on the OK button.

G - INTERNAL COMMANDS

28

Internal Command THEN/ELSE Command File

Run a Report Specification File REPORT <filename> REPORT [string variable name]
filename: the name of the report command file to use. string variable name : a string variable whose value is the name of the report command file to use.

The REPORT( ) command allows the report generator to be called from any EXSYS rule or from the command file. The report specification file contains the report generator commands to be used in creating a report. The first form allows the report file to be specified explicitly, while in the second form the value of the string variable is used as the name of the file to use for the report specification. In this way, the knowledge base itself can set the name of the report specification file to be used by assigning a value to the string variable. The REPORT( ) command is also useful when a large amount of data must be passed to an external program. Here is an example: IF . . THEN REPORT(RPTFILE.1) RUN(PROG1) The report specification RPTFILE.1 could contain commands to write a large amount of data into a file that would then be read by PROG1 when it is called.

G - INTERNAL COMMANDS

29

Alternatively, a number of report specifications can be used to each add data to an overall conclusion report. The knowledge base rules can control what report specifications are invoked and used. Each of the report command files could append data to an overall report. The details of the Report Generator language are in Chapter F.

Report Command Window


The window to build a report command only asks for the name of the Report Command file or EXSYS string variable containing the command file name.

Report Generator File to Use:

OK Cancel

G - INTERNAL COMMANDS

30

Internal Command Qualifier / Variable THEN/ELSE Command File Report Generator Custom Screen

Run an External Program RUN(filename parameters)


The internal command RUN( ) is used to call external programs, pass data to the programs and receive data back from the programs. See Chapter H for the details on calling external programs with the RUN command.

G - INTERNAL COMMANDS

31

Internal Command THEN/ELSE Command File

Stop Program Execution STOP

The STOP command will terminate execution of rules and go directly to the report generator (if one is present) and then display the conclusions. This is quite useful in situations where, once a particular answer is known, there is no need to continue asking questions. The STOP command can only appear in the THEN or ELSE part of a rule or in the command file. The execution of the rules will immediately stop if a rule with a STOP command fires. Here is an example: IF The color is green THEN and Choice 1: Probability=10/10 STOP

If this rule fires, Choice 1 will be given a value of 10 and the running of the rules will be stopped, despite any other rules that are available on other choices. STOP can be used with the FORWARD and NOBACKWARD options.

G - INTERNAL COMMANDS

32

Internal Command Qualifier / Variable THEN/ELSE Command File Report Generator

Table Interface TABLE(parameters)


Table files can be used to store data needed by EXSYS in a simple ASCII format. See Section L1 for a full discussion of table files and command syntax.

G - INTERNAL COMMANDS

33

Chapter H External Program Calls


EXSYS has many ways to access data from other programs. This allows easy integration with other applications. There are built-in commands to access data directly from some programs such as dBase, Lotus 123 and LINDO. However, for other programs external programs calls are used. Calling external programs is the most general way to access data from other programs and allows any program that can be run on the computer to be accessed by EXSYS. External programs are called with an EXSYS internal command. Data can be passed to the external program and also can be passed back into EXSYS for analysis. The use of external programs provides a powerful capability that enables EXSYS to handle a wide range of problems and provides almost limitless ways to extend the EXSYS package. There are several ways to call external programs from the expert system. 1. 2. 3. 4. 5. 6. Programs called at the start of a run. Programs associated with a qualifier or variable. Programs called in the THEN/ELSE rules. Programs called from the report generator. Programs called from the command language. Programs called from the screen language

Each way of running external programs uses basically the same syntax and command options. The external program can be any program which can be run from the operating system. The program can be written in any language or it can be an application. This ability to run any program provides the great flexibility. When EXSYS calls an external program, EXSYSP.EXE (or EDITXSP.EXE) remains in memory. Thus, there must be enough memory available for both EXSYS and the external program to run. If there is not enough memory, you will get an error message. In most GUI environments, memory is not a problem.

H - EXTERNAL PROGRAM CALLS

H1: Syntax
All versions of the RUN command have the same basic form: RUN(filename <data1> <data2> .... <options>) filename: The name of the program to run. This can be any program that can be run from the operating system. Instead of an actual filename, the first parameter can be a string variable whose value is the name of the program to run. If a string variable is used, the first parameter is the name of the variable in [ ]. Here's an example of an external program call. RUN([P] 1 [X]) In this case, the program would derive or ask the user for the value of the string variable P, which would be used as the name of the external program called. The program name can be a batch file in DOS if the /B option is used. Data can be returned to EXSYS through a file. Any program which can write an ASCII file can pass data back to EXSYS. data#: The call to an external program can pass a number of pieces of data. The list of parameters can include either text or variables. If text is used, it is just listed. If variables are used, the name of the variable must be placed in [ ]. The variable will be replaced with its value in the call to the program. For example, RUN(DEMO ABC [X] 1.2) would call the program DEMO and pass the string ABC, the value of [X] expressed as a string and the string 1.2. It is up to the program called to correctly accept and use these items of data. If an item is in quotes, it will be passed without change. This allows passing the strings such as, "[X]" or "/C" to a called program.

H - EXTERNAL PROGRAM CALLS

Options:

There are a variety of options that effect the external program call. /B Batch Mode / DOS programs EXSYS supports calls to batch files; or DOS commands; by adding a /B to a RUN( ) command. It is also possible to call a batch file by calling COMMAND.COM and passing the batch file name as a parameter. There may be a problem with this approach: depending upon the end user's computer configuration, it may not be easy to tell where COMMAND.COM is. With the /B option, EXSYS will determine where COMMAND.COM is and use it to call the batch file or DOS command. If the MS Windows version of EXSYS is being used, and a NON-Windows (DOS) program is being called, use /B. For example: RUN(XXX.BAT /B) will execute the batch file XXX.BAT. RUN(DIR C:*.C /B) will display a directory of the .C files on drive C. In this case, the program will not pause after displaying the directory. However, you could use 2 commands such as, RUN(DIR C:*.C >C:LIST /B) DISPLAY(C:LIST) The first command uses the ability of DOS to redirect the directory output to a file C:LIST, and the second command, displays the file created. (For information on redirection, see your DOS manual.)

H - EXTERNAL PROGRAM CALLS

/C and /# Passing Arguments on the Command Line This determines if the data arguments will be passed to the external program on the command line; or in a file. Data is passed to an external program by two methods: Passing data in a file Passing data on the command line The default method is to pass data in the file PASS.DAT. This is an ASCII file. Data parameters are written to this file and the file is closed before the external program is called. It is the responsibility of the external program to read the data from PASS.DAT. (The name of the file that the data is passed to can be changed with the option PASS= in the command line or configure file.) Passing data by using a file, is very general, but has some disadvantages. - It requires opening, writing/reading and closing a file twice which may be slow. Also, if a call is made to a program like BASIC, the name of the basic program must be specified (e.g. RUN(BASIC BASPROG) - we want the name of the basic program, BASPROG, passed to BASIC, not written to a file.) To avoid these problems, EXSYS can also pass the parameters on the command line when the external program is called. This is just like entering the parameters on the command line when a program is called from the operating system. Passing data on the command line is much faster since the data does not have to be written to a file and then read from a file. Instead, the data is immediately available to the called program. Unfortunately, not all programs can accept data as a command line argument. If it is desired to pass arguments on the command line, the /C option MUST be used or all arguments will be passed in PASS.DAT. The /C and /# options tell EXSYS to pass the arguments on the command line rather than in PASS.DAT. If you want to pass more than the program name as a command line argument, but still pass others in PASS.DAT, use /# - where # is the number of the argument to pass on the command line.

H - EXTERNAL PROGRAM CALLS

For example, BASIC will not usually accept command line arguments for data. Suppose we want to call a basic program TEST and pass it the value of [X] and [Y] in PASS.DAT. If we use RUN(BASIC TEST [X] [Y]) the program name TEST will not be passed as a command line argument. Instead, it will be written to PASS.DAT. The file PASS.DAT will contain the ASCII string TEST and the values of the variables [X] and [Y]. If we use RUN(BASIC TEST [X] [Y] /C) all of the parameters will be passed on the command line and the file PASS.DAT will not be created. Basic will not be able to use the values of [X] and [Y] passed this way. We could pass the values of [X] and [Y] using the REPORT( ) command, however, it is easier to use RUN(BASIC TEST [X] [Y] /2) This causes the first 2 arguments, BASIC and TEST, to be passed as command line arguments. PASS.DAT will be created with the values of [X] and [Y]. [X] and [Y] will be passed in PASS.DAT. When programs can accept data on a command line, this method is very fast. When programs make many calls, it is also much more efficient. NOTE: In DOS, data passed on the command line is limited to 127 characters in length. Since numeric variables are stored as floating points, each can use 10 characters and it is possible to fill up the command line. If this happens EXSYS will tell you and you must use the PASS.DAT method instead.

H - EXTERNAL PROGRAM CALLS

/R

Restart This option causes EXSYS to RESTART; at the beginning of the run, after calling the external program. This is very useful for expert systems that are monitoring a process. For example, an expert system could have a rule that fires to call an external program to do something and then restart the process again. If new data indicated some action was necessary, a different rule could call another external program (or the same program with different parameters passed) to alert someone or to correct the process. Do not use the /R option unless you want to restart the run after the external program is called. Returning Multiple Values Normally, a RUN( ) command associated with a particular qualifier or variable will only return data for that qualifier or variable. The /M option tells the program that multiple data items will be returned. If /M is not added, EXSYS will default to accepting only one item of data when an external program call is associated with a specific qualifier or variable. If data will be returned, the /M option must be used when calling external programs from the THEN/ELSE portion of a rule or a command file. Add Ctrl-Z Adding the /Z option to the run command, causes a CTRL-Z to be added to the end of the PASS.DAT file. This is necessary for compatibility with some external programs.

/M

/Z

H - EXTERNAL PROGRAM CALLS

H2: RUN Command Window


To build a RUN command from the command window:

Program Name: Data: Pass all parameters on the command line Pass first N parameters on command line N= Pass parameters in PASS.DAT

Return Mutliple data items Batch file or NON-WINDOWS program Restart after call Add Ctrl-Z to PASS.DAT Cancel OK

Enter the program name and any data to pass to the program. The data may contain EXSYS variables, text strings or quoted strings. Select how the parameters should be passed to the program and click on the appropriate radio button. If only some parameters are to be passed in PASS.DAT, enter the number of parameters to pass. If the program will return multiple data items, or if the call is not associated with a qualifier or variable, click on the Multiple data items box. If the program is running in MS Windows, and the called program is a Non-Windows (DOS) program, click on the NonWindows button. If a restart or Ctrl-Z is required, click on the appropriate button. Once all of the parameters are set, click on the OK button.

H - EXTERNAL PROGRAM CALLS

H3: Microsoft Windows Program Calls


The way the external program must signal that it is complete differs among the supported GUI operating systems. In the non-GUI versions of EXSYS, the external program need only terminate. In some windowed environments, it is more complicated because multiple programs may be running simultaneously and another technique must be used to indicate that a program is finished and the data are ready to be returned. In Microsoft Windows, both Windows and non-Windows (DOS) programs can be called. The best technique for calling external programs is to set up Dynamic Data Exchange (DDE) and pass signals to indicate the end of a process. To set this up would require significant modification to user developed external programs and would not be possible for non-Windows (DOS) applications. In order to keep the interface to user developed external programs as simple as possible, another technique has been developed which works for both Windows and non-Windows programs. (DDE links to external programs can be established using the Linkable Object version of EXSYS for MS Windows.) The technique is to create a flag file just before the external program terminates. EXSYS looks for this flag file and waits until it is created to read data back into the expert system. This technique works for both Windows and non-Windows applications, and requires only minimal modification to user developed external programs. Also, a batch file approach allows applications developed for DOS to run without modification. The default name of the flag file is EXSYS_EP.FIN. You can change the default name with the configure option: EP_FLAG_FILE=filename Since EXSYS frequently checks for the external program, we recommend that you rename it to a file in RAM disk. Do not name the flag file with the same name as the return data file. EXSYS will check for the existence of the file every 2 seconds. This time interval can be lengthened or shortened with the following configure option: EP_TIME_INC=number

H - EXTERNAL PROGRAM CALLS

The sequence that should be used in the external program is: 1. Call the external program from EXSYS. If it is a nonWindows (DOS) program, be sure to set the /B option in the RUN( ) command. 2. Have the external program perform its operations. 3. If data is to be returned, have the external program open the return data file (usually RETURN.DAT), write the data and close the return file. 4. When the external program is finished, have it open the flag file for writing, immediately close the flag file and exit. For example: f = fopen("EXSYS_EP.FIN", "w"); fclose(f); exit(0); It is not necessary to write anything to the file. Its creation, even with 0 bytes length is adequate. It is very important to exit as soon as possible since EXSYS is checking for the existence of the file and will retake control as soon as it finds it. EXSYS is designed to allow a short time after it finds the file to allow your program to terminate, but the time is limited. If you already have a non-Windows program which you wish to call, you can also use a batch method. 1. Create a 1 byte file named xxx (or whatever you like). 2. Instead of directly calling your program, call the following batch file: copy xxx exsys_ep.xxx call your program here rename exsys_ep.xxx exsys_ep.fin The first line makes a dummy file. The second runs your program which should create the return data file, but NOT the flag file. The third line creates the flag file through a "rename" which is the fastest possible way to create it. Parameters can be passed into your program through batch file replaceable parameters. (See your DOS manual for information on replaceable parameters in a batch file.)

H - EXTERNAL PROGRAM CALLS

H4: Macintosh Program Calls


The way the external program must signal that it is complete differs among the supported GUI operating systems. In the non-GUI versions of EXSYS, the external program need only terminate. In some windowed environments, it is more complicated because multiple programs may be running simultaneously and another technique must be used to indicate that a program is finished and the data are ready to be returned. For the Macintosh, the technique is to create a flag file just before the external program terminates. EXSYS looks for this flag file and waits until it is created to read data back into the expert system. This technique works for both Macintosh System 6 and System 7. The default name of the flag file is EXSYS_EP.FIN. You can change the default name with the configure option: EP_FLAG_FILE=filename Since EXSYS frequently checks for the external program, we recommend that you rename it to a file in RAM disk. Do not name the flag file with the same name as the return data file. EXSYS will check for the existence of the file every 2 seconds. This time interval can be lengthened or shortened with the following configure option: EP_TIME_INC=number The sequence that should be used in the external program is: 1. Call the external program from EXSYS, passing all arguments to the program using the pass.dat file. 2. Have the external program perform its operations. 3. If data is to be returned, have the external program open the return data file (usually RETURN.DAT), write the data and close the return file. 4. When the external program is finished, have it open the flag file for writing, immediately close the flag file and exit. For example: f = fopen("EXSYS_EP.FIN", "w"); fclose(f); exit(0); It is not necessary to write anything to the file. Its creation, even with 0 bytes length is adequate. It is important to exit as soon as possible since EXSYS is checking for the existence of the file and will retake control as soon as it finds it. EXSYS is designed to allow a short time after it finds the file to allow your program to terminate, but the time is limited.
H - EXTERNAL PROGRAM CALLS
10

H5: UNIX and VMS Program Calls


No special flag files or other operations are required in UNIX or VMS. EXSYS will wait for the called program to terminate and will then read the RETURN.DAT file.

H6: Returning Data to EXSYS


There are two reasons for calling an external program: 1. Getting data from another program 2. Calling a program to display some information to the user The first is much more common and it requires that there be a method for the data to be passed back to EXSYS. In order to have the most generic technique possible, EXSYS expects the data to be returned in an ASCII file. In this way, the only constraint on the called program is that it be able to write an ASCII file. There is a slight speed penalty in passing data in files, but it is very small. Other techniques of passing data are much more complicated to implement and severely limit the number of programs that could be called. Data is returned to EXSYS by having the external program write it to a file which is automatically read by EXSYS after the external program is finished. The default file name that is used to pass data back is RETURN.DAT. This is an ASCII file created by the called program. The name of the file used to return data to EXSYS can be changed by the RETURN= configure option. It is the responsibility of the external program which was called to write data to the appropriate return file in a form which EXSYS can read. If multiple items of data are being passed back, it is necessary to tell EXSYS what qualifier, variable or choice the data is used for and the value to be assigned to it. If the external program call is associated with a particular qualifier or variable, only the value need be returned. Data passed back to EXSYS must be in an ASCII file with only one data item per line. The format of each line must be: For qualifiers: Q <qual #> <value(s)> or Q "name" <value(s)>
11

H - EXTERNAL PROGRAM CALLS

For variables:

V <var #> <value> or [var name] <value> C <choice #> <value> or C "text" <value >

For choices:

<qual #>, <var #> or <choice #> The number of the qualifier, variable or choice for which the data is being passed back "name" "text" <value> The name associated with the qualifier. A unique text sub-string in the choice. The data to assign, in the correct format. For numeric variables, a numeric value. For string variable, a text string. For qualifiers a string listing the numbers of the values to set. If more than one value is set, they must be separated by spaces or a comma. For choices, a value appropriate to the confidence system being used.

For example: 1. V3 2.1 2. [X] 2.1 means assign a value of 2.1 to variable 3 means assign a value of 2.1 to variable [X]

3. If qualifier #7 has four values: Qualifier #7 THE COLOR IS 1. RED 2. BLUE 3. GREEN 4. ORANGE and we have a line in RETURN.DAT, Q7 1,2 this means for qualifier 7, set values 1 and 2 as true, or "The color is red or blue". If more than one value is passed back, the values must be separated by a space or comma. If this qualifier has the associated name "COLOR", we could use Q "COLOR" 1,2
H - EXTERNAL PROGRAM CALLS

12

4. You can pass data back for as many variables, qualifiers or choices as you wish. For example, if RETURN.DAT contained: V2 1.7 [X] 6.3 V12 ABCD Q7 1,2 Q "TIME" 3 C "Part ABC" 8 EXSYS would assign a value of 1.7 to variable number 2; assign 6.3 to variable [X]; assign the string "ABCD" to string variable 12; select the first two values of qualifier 7; select the third value of the qualifier named "TIME" and assign a value of 8 to the choice containing the text "Part ABC'. 5. The multi-variable approach is useful if the external program can set several items of data at once. Suppose we want to have the user enter a list of variables and pass the number of data points and the average back to EXSYS, which stores the data in variables 1 and 6. We could use the following program written in BASIC. 10 COUNT = 0 20 SUM = 0 30 INPUT "DATA TO BE AVERAGED OR <ENTER> TO END", X 40 IF X <> 0 THEN COUNT=COUNT+1: SUM=SUM+X: GOTO 30 50 OPEN "RETURN.DAT" FOR OUTPUT AS #1 60 PRINT #1, "V1 ";SUM/COUNT 70 PRINT #1, "V6 ";COUNT 80 CLOSE #1 90 SYSTEM The program writes "V1 " and the average value on one line and "V6 " with the number of data points on the next line in the file RETURN.DAT. Note: The file compression utility SHRINKP removes unused formulas and variables. This can cause the number of a variable to change if there were unused variables preceding it. Be sure to check the numbers of your variables after running SHRINKP and make the appropriate corrections in your external programs. Likewise, deleting a qualifier can change the qualifier numbers. It is a good idea to pass data by name or text whenever possible.

H - EXTERNAL PROGRAM CALLS

13

When data is passed back for a choice, the value will be incorporated with any other values assigned to the choice by other rules. The value will NOT overwrite existing data; it will be combined with it as if it were assigned in a rule.

H6.1: RAM Disks


If speed is critical in a particular application, we recommended that, in those operating systems that support it, the data be passed on a RAM disk file. To pass data on a RAM disk file, redefine the name of the file in which the data will be returned with the RETURN= command in the configure file. For example, if drive D is a RAM disk, and we use RETURN=D:RETURN.DAT, data will be passed on the RAM disk. This is substantially faster than passing it on a the hard disk.

H6.2: Erasing RETURN.DAT


After EXSYS reads the returned data, the file which returned the data is erased. This is done to prevent inadvertently reading the file again after a subsequent external program call that did not return data. If your application requires that the file which returns the data not be deleted, use the configure option NODELETE.

H - EXTERNAL PROGRAM CALLS

14

H6.3: Passing Back a Command from an External Program


In addition to returning data, an external program can return a command to EXSYS. If the RETURN.DAT file has a line which starts with an "!", the remainder of the line will be used as a command rather than treated as data. This enables external program to ask for questions that would normally be asked from the Questions menu. If a command is returned, EXSYS will call the external program after executing the command, so that data can be obtained. This allows a complete customization of the interface, yet retains the ability to ask questions of the system. The commands which are supported are: !WHY !? or !HELP !KNOWN !EXIT Displays the current rules being tested Displays the custom help file associated with the qualifier or variable. Displays the known data Exits the program

For example, if RETURN.DAT contained !WHY EXSYS would display the rules that caused the question to be asked.

H6.4: Returning Hypertext Words from External Programs


In addition to returning data, an external program can return a call to display a EXSYS hypertext keyword. If the RETURN.DAT file has a line which starts with an "?", the remainder of the line will be used as hypertext keyword. When hypertext words are returned, EXSYS displays the screen(s) associated with the hypertext words then, calls the external program again so that you can obtain data. This allows external programs to access the hypertext system, and still be able to obtain the needed data. The syntax is: ?keyword For example, if RETURN.DAT contained ?Part 23 EXSYS would display the hypertext screen associated with the keyword "Part 23" and would then, recall the external program.
H - EXTERNAL PROGRAM CALLS
15

H7: Calling Programs from THEN/ELSE


Calling external programs from the THEN/ELSE part of rules is the easiest form of the RUN( ) command. A program is called using the internal command RUN(). The form of the RUN( ) command is the same as described in Section H1. Data and variables can be passed to the program by the RUN( ) command and the options for passing on the command line can be used. This is entered as an internal command by clicking on the Command button in the rule editing window, and selecting Run External Program. When the RUN( ) command is encountered in a rule that fires, EXSYS will immediately call the specified external program . When the external program is done, (and exits as if it were going to the operating system) control will, instead, return to EXSYS at the point in the rule where the program was called. Data will usually not be returned from a RUN( ) in the THEN/ELSE. However, if it is desired to return data, the /M option will cause EXSYS to look for and read a RETURN.DAT file. For example: IF [X] > 0 THEN RUN(TEST [X]) will cause the program TEST to be called if [X] is greater than 0. The value of [X] will be passed in a PASS.DAT file. IF [X] > 0 THEN RUN(TEST [X] /C /M) will also run the program TEST if [X] is greater than 0, but the value of [X] will be passed on the command line due to the /C and the program will expect data to be returned from the called program due to the /M option. Remember, in a backward chaining system, a rule will be tested and fired ONLY if there is some reason to do so. When external programs are used in the THEN part of rules, there MUST also be some mechanism to make them fire. EXSYS does not know what variable the external program will return data for, and does not know when a external program is relevant. Some techniques to force an external program to fire are:

H - EXTERNAL PROGRAM CALLS

16

1. Have a choice also in the THEN part of the rule. The system will backward chain on the choice IF [X] > 0 THEN RUN(TEST [X]) and Choice 1: Conf=5 2. Have a variable in the THEN part of the rule if the system will backward chain on the variable. IF [X] > 0 THEN RUN(TEST [X]) and [X] is given the value 1 3. Force the rule to fire through the command language RULES 5 /F 4. Use forward chaining. Since forward chaining is not goal driven, it will test all of the rules.

H - EXTERNAL PROGRAM CALLS

17

H8: Calling Programs from the Report Generator, Command File or Custom Screen File
Calling external programs from the report generator or other command files, is the same as calling a program from the THEN/ELSE part of a rule except, the command is put in the report specification file with an ASCII editor. It is not part of the EXSYS rules. Note, in the report generator, the command does not have to be in ( ). The ability to pass data and the options available are the same as in the above RUN ( ) command from THEN/ELSE. Remember, you must use the /C or /# option if the data is to be passed on the command line. Using the /M option causes EXSYS to read returned data. This should only be used for REPORT commands in rules. For example, the rule: IF ... THEN REPORT(XXX.RPT) where the report specification file XXX.RPT contained: FILE xxx.dat V CLOSE RUN TEST /M would be a way to call an external program, TEST, and make all of the data on the variables available to it. This would be a useful technique if there were too many variables to pass on the command line or list in the run call.

H - EXTERNAL PROGRAM CALLS

18

H9: Calling an External Program at the Start of a Run


Many expert systems that interface to other programs, get much of their data from a single external program. This may be a database, spread sheet or custom data acquisition program. The external program is called at the start of the run. If the external program provides all of the information needed by the expert system, the user may not actually interact with EXSYS at all. This allows the creation of embedded systems which get all data from other programs and use the report generator to output the results. One of the options available on the knowledge base Parameters window, is the option to call an external program at the start of a run. This program will be called at the start of each run. To edit the name of the external program, select Parameters from the Options menu, and click on the Ext Prog button. Enter the name of the program and any data to pass then, click on OK. Do not enter "RUN" or the ( ). These are not needed when you are calling an external program at the start of a run. Only the parameters that would normally appear in the ( ) are entered. filename <data1> <data2> ... <Options> Remember,this call is made at the start of a run, so there are no EXSYS variables know to pass to the external program. All data passed should be text items.

H - EXTERNAL PROGRAM CALLS

19

H10: Calling External Programs from Variables


In addition to external program calls associated with the expert system or a particular rule, external program calls can also be associated with a specific variable. In such a case, the external program will only be called when the value of the variable is needed and if a value cannot be derived from other rules. Associating an external program call with a variable is done by entering the RUN( ) command at the start of the text you would normally associate with the variable: RUN(filename <data> ... <Options>) <var text> The parts of the RUN command are the same as described previously and the <var text> is just the normal text you would associate with the variable. Only the <var text> will be used when EXSYS displays results, prints the value from the report generator, etc. The RUN(...) part of the text is "invisible" to the user seeing the results of the run. Be sure to place a space between the closing ")" and the first character of the variable text. It is easiest to build the RUN( ) command by using the Data Acquisition button on the Variable Window. For example, we might have a variable [PIPE DIAMETER] that represents the diameter of a pipe. When we first use the variable [PIPE DIAMETER] in an expression, the program asks for text to associate with the variable. If we want the user to be asked for the diameter, we enter: The diameter of the pipe Suppose however, that we want to call a program called PIPE and pass it the value of [PIPE TYPE] on the command line. This program will return the value of the pipe's diameter. In this case, we would select the Data Acquisition option to build a RUN( ) command. The text associated with the variable would then be: RUN(PIPE [PIPE TYPE] /C) The diameter of the pipe The variable which calls the external program can have limits, be displayed, etc. but do not initialize it or the program will never be called. External programs associated with a variable are called only if the user would be asked for a value for the variable. If the variable is initialized, the user would not be asked for a value and the program would not be run. When, EXSYS determines it needs the value of the variable, and it can not derive a value from other rules, the external program will be called.

H - EXTERNAL PROGRAM CALLS

20

Since the program is being called to get a value for the variable, EXSYS expects data to be returned. The method of passing data back is in the file RETURN.DAT (unless changed to another filename with the RETURN= command). In this case, there are two options to the form in which the data is passed: 1. A single value passed back with no "address" information. It is assumed the value returned will be assigned to the variable that caused the program to be called. 2. Multiple values passed back with "address" information on each line. (The call to the external program must have used the /M option.) The first form is the standard way to get data for programs associated with a specific variable. In this case, just the value to be returned is written by the external program in the file RETURN.DAT. For example, if variable 7 called an external program which returned the value 4.5 as the value, the RETURN.DAT file could contain just 4.5 rather than V7 4.5, although the second form would also be valid if the /M option was used. If the /M option is used, data can be passed back for many variables, qualifiers and choices. But be sure to pass data back for the variable that caused the program to be called. The format of the data passed back with the /M option is the same as described in Section H6. CAUTION: Passing back multiple items from an external program call associated with a variable can overwrite existing data. Passing data back for a variable or qualifier that already has a value will OVERWRITE the existing value with the new one. This can result in changing the values input by the user or derived by the system. Note: Use care when passing data back to other than the calling qualifier or variable to prevent overwriting existing data.

H - EXTERNAL PROGRAM CALLS

21

H11: Calling External Programs from Qualifiers


In addition to external program calls associated with the expert system or a particular rule, external program calls can also be associated with a specific qualifier. In such a case, the external program will only be called when the value of the qualifier is needed and a value cannot be derived from other rules. The technique used is very similar to that used in associating an external program with a variable. Instead of the text associated with the variable containing the RUN( ) command, the qualifier text is started with RUN(filename <data> ... <Options>) <qual text> The parts of the RUN command are the same as described above and the <qual text> is just the normal qualifier text you would use. Only the <qual text> will be used when EXSYS displays conditions, prints from the report generator, etc. The call to the external program is "invisible" to the user seeing the results of the run. For example, suppose we have a qualifier: The color is 1 red 2 white 3 blue 4 green When information on this qualifier is needed, the user is asked to select a value. If instead, there is a program COLOR that can determine the color, we could input the call to the external program in the qualifier text. This call can be easily built by using the Data Acquisition button on the qualifier editing window. RUN(COLOR) The color is 1 red 2 white 3 blue 4 green When the value of the qualifier is needed and can not be derived from other rules, the external program COLOR would be run. Since the purpose of running the external program is to get data, it is expected that data will be returned in the file RETURN.DAT. As

H - EXTERNAL PROGRAM CALLS

22

with external programs associated with a variable, data can be returned in two forms: 1. A single value list passed back with no "address" information. It is assumed the value returned will be assigned to the qualifier that caused the program to be called. 2. Multiple values passed back with "address" information on each line. (The call to the external program must have used the /M option.) In the first case, the data is automatically assigned to the qualifier that called the program. The data returned is the number or numbers of the values that are to be selected. For example, if after the call to COLOR in the example above, RETURN.DAT contained: 1,3 the first and third values in the list would be set for the qualifier or: The color is red and blue If the /M option is used, data can be passed back for many variables, qualifiers and choices. Be sure to pass data back for the qualifier that caused the program to be called. The format of the data passed back with the /M option is the same as described in Section H6. Caution: As with variables, passing back multiple items from an external program call that is associated with a qualifier can cause problems. It is possible to overwrite existing data. Passing data back for a variable or qualifier that already has a value will OVERWRITE the existing value with the new one. This can result in changing the values input by the user or derived by the system. Note: Use care when passing data back to other than the calling qualifier to prevent overwriting existing data.

H - EXTERNAL PROGRAM CALLS

23

H12: Problems Calling External Programs


If you call an external program and the command is ignored or you get an error message about not being able to find the file, there are several likely causes. The first thing to do is to use the TRACE= configure command to get a listing of the run. 1. The trace listing does not show a call to the program. When the RUN( ) command is in the THEN or ELSE part of a rule, determine if the rule fired. In a backward chaining system, rules are only used if they are relevant to the problem. If the rule contains no choices or variables that are displayed at the end of the run, the rule will not be used unless the program is run in the FORWARD or FINALPASS mode. (See the Chapter E on forward chaining for more information on these commands.) If the RUN( ) is associated with a qualifier or variable, decide if the data was needed by the system. RUN( ) commands associated with a qualifier or variable will only be used if needed. If the qualifier or variable received a value in the trace listing, decide where it came from. If a variable or qualifier has an initial value, or if a value can be derived from the rules, the associated run command will not be used. 2. The trace listing shows an attempt to call the external program. There may be a system resource problem. Some systems have a limit on the number of files or processes simultaneously open or running. Another possible resource problem may be lack of memory. Both EXSYS and the called program must reside in the available memory. Usually a lack of memory will result in an error message. If you have memory problems running an external program from the editor, try it with the runtime program. The Runtime program is much smaller. If there is just not enough memory to run both programs, try creating a batch file that calls the external program first, creates a RETURN.DAT file with the external program, exits the external program, loads EXSYS and reads the RETURN.DAT file with the DATALIST command. This approach will often allow running a program too large to be co-resident with EXSYS. If there does not seem to be a resource problem, but EXSYS can not find the called program or cannot execute it, it may be looking on the wrong drive. If you are calling a program that is not on the default drive, be sure to specify the FULL drive and path specifications. This sometimes seems to be necessary even if the program is on the default drive. It is especially important when calling BASIC programs, since both the path to BASIC and the path to the basic

H - EXTERNAL PROGRAM CALLS

24

program must be specified. For example, suppose BASIC.COM is on disk C in sub-directory BAS and your basic program TEST.BAS is also in the same sub-directory. To run this program you would enter: RUN(C:\BAS\BASIC C:\BAS\TEST /C)

Also remember, the file called by the RUN( ) command as an external program MUST be an executable file. In DOS that is one that ends in .EXE or .COM, not a batch file. In UNIX or VMS, make sure the program can be run and that the access privileges allow running. If a batch file is used, the /B option must be used.

H - EXTERNAL PROGRAM CALLS

25

H13: Calling External Programs Summary


Single Variable Approach
1. Called by adding RUN(filename...) at the start of the text associated with a specific variable or qualifier. Do not use the /M option unless it is desired to return multiple data items. 2. Data is returned in the file RETURN.DAT and passed out in the file PASS.DAT. 3. Only a single value need be returned which is assigned to the variable or qualifier that called the external program. Returning multiple values is permitted if /M is used and "address" information is included in the RETURN.DAT file. 4. Form of data returned: Numeric variable - single floating point number expressed as an ASCII string String variable - text string, without " " Qualifier - list of the numbers of the values in the list to set to true. Numbers should be separated by a space or comma. 5. External program called only when the value for the variable or qualifier is needed.

Multi-variable Approach
1. Called by indicating that an external program should be called at the start of EXSYS or by using the /M option with an external program call from a qualifier or variable. Returned data must include "address" information on what qualifier, variable or choice to assign the data to. 2. Data is returned in the file RETURN.DAT. Data is passed out in PASS.DAT or on the command line. 3. Allows data to be passed back for any number of variables, qualifiers or choices.

H - EXTERNAL PROGRAM CALLS

26

4. The return file has data in the form: For qualifiers: Q <qual #> <value(s)> or Q "name" <value(s)> V <var #> <value> or [var name] <value> C <choice #> <value> or C "text" <value >

For variables:

For choices:

H - EXTERNAL PROGRAM CALLS

27

H14: DATALIST: Analyzing a Multiple Record Data Report


EXSYS has a very powerful capability to analyze, using expert system rules, a report containing multiple records of data;. Typically, such a report would come from a database manager or some other external program. This is done through the use of the report generator and the DATALIST command line option. The external source of the data must provide a report in the normal form of data passed to EXSYS from an external program called at the start of a run (e.g. V2 4.7 means assign the value 4.7 to variable 2, or [X] 1.5 means assign the value 1.5 to variable [X]). The individual sets of data to be analyzed must be separated by the command END. For example: V 2 4.7 [X] 2.3 Q 1 2 END V 2 5.3 [X] 1.6 Q 1 1 END . . . EXSYS MUST be started using the command line option DATALIST, telling the program that there is data to be read (even though no external program was called) and that individual sets of data are separated by the END command. In the above example, EXSYS would read the first 3 lines, assign values to the designated variables and qualifiers and start applying the rules. There should be a report specification file (the .OUT file) associated with the knowledge base that defines the order in which the results are to be sent to a disk file. This report specification should start with FILE filename /A The /A is important since you will want to append data to the output report for each set of data. The report specification MUST end with the RESTART command to tell EXSYS to start its analysis again. Since we used the DATALIST command, EXSYS will automatically get the next set of data. EXSYS will automatically stop when it runs out of data.

H - EXTERNAL PROGRAM CALLS

28

This allows batch analysis of database records without user intervention and, with this technique, an expert system can be created to analyze raw data from an external source and produce a report of the analysis. For example, the report file might contain: FILE ACCTDUE.RPT /A FIRST "Accounts Overdue" C1 =10 /V2 RESTART This report will print the title "Accounts Overdue" and a list of account numbers (or names) contained in variable 2. Choice 1 would be set to indicate if the account was overdue. Only when choice 1 was set to a value of 10 would the value of variable 2 be printed to the file. The RESTART command tells EXSYS to immediately read the next set of data. The data passed in would include name or account number along with other data to determine the status of the account.

H - EXTERNAL PROGRAM CALLS

29

H15: DATAREAD: Reading a File of Data


A DATAREAD command is similar to a DATALIST option, but DATAREAD is an internal command while DATALIST is a configuration option. Inputting the DATAREAD command is described in Section H15. The data in the file read by a DATAREAD command is the same as in a RETURN.DAT file returning with a /M option. The END command used in DATALIST files should not be used.

H - EXTERNAL PROGRAM CALLS

30

Chapter I Customizing the User Interface


When an expert system is created with EXSYS, there is a default format for asking questions. This provides the normal EXSYS user interface. For most systems, this interface is appropriate. However, in some cases, it is desirable to change the look of EXSYS. There are a variety of ways to do this. The customization techniques covered in this section include:

1. Custom help screens


These allow a user to select the Explain Question menu item on the Questions menu to get more detailed information on what the expert systems' question means. These help screens are generated by the author of the expert system.

2. Custom question screens


These allow the developer to redefine the screens used to ask questions of the user. The screen definition language provides easy commands for defining screens.

3. Hypertext
Providing multilevel custom help for key words in rules, qualifiers, notes, etc. Hypertext keywords are highlighted in blue and clicking on a hypertext word brings up an explanation of the word. The explanation screens are designed using the custom screen language.

4. Qualifiers with values inserted in the middle


Normally EXSYS qualifier conditions are made by having the qualifier text followed by one or more value text strings. It is possible to have the text of the values inserted in the middle of the qualifier text. This allows some questions to be phrased more easily .

5. Adding special characters by ASCII code


Characters that can not be directly entered in EXSYS text can be included by adding their ASCII code.

6. Embedding data in text


Data on the value of a qualifier or variable can be embedded in the text of another choice, qualifier, note, reference or custom screen. This allows the easy creation of text that contains the actual data which being used in the run. The first 3 items all use the EXSYS GUI Custom Screen Definition Language to define the custom screens or help screens. The same syntax is used for all three.

I - USER INTERFACE

I1: GUI Custom Screen Definition Language


EXSYS allows you to create custom screens to ask questions of the user, provide custom help or hypertext help screens. The use of custom screens allows you to customize the user interface. Custom screens are created with a word processor, text editor or can be edited using the Screen menu item on the KB Files menu.. The screen definition language file consists of ASCII text. All lines are either commands or text to be echoed to the screen. Lines starting with a ~ are commands. Many screens are stored in a single file and are separated by special commands that indicate the start of a new screen. All of the ~ commands must be the only text on the line and the ~ must be the first character on the line. EXSYS enables you to design your own custom screens using GUI elements. These screens are used to ask for data in place of the default EXSYS screens. The screen designed with the Screen Definition Language are portable across the supported GUI environments (MS Windows, Macintosh, Open Look, Motif and Presentation Manager).

I - USER INTERFACE

I2: Screen Files


There are several different files that can contain the custom screen definitions: <knowledge base name>.SCR Contains custom screens to ask questions and screens for hypertext keywords. <knowledge base name>.HLP Contains custom screens to provide custom help for questions. These screens are accessed by the Explain Question item of the Questions menu. Any file name A file of custom screen commands can be called with the DISPLAY(file /C) command.

I - USER INTERFACE

I3: Screen File Structure


Custom screen files usually contain many separate screens in a single file. For example, each of the qualifiers and variables in an expert system might have its own screen. The screens are separated by a special command that indicates the start of a screen for a particular data item. All commands following the identifier apply to that screen until either: 1. The end of the file is reached 2. A ~ identifier command indicates the start of the screen for a new qualifier, variable or hypertext keyword. The syntax is: ~ Qualifier or Variable ID ~~ Hypertext keyword

I3.1: Indicating the Qualifier or Variable


The definition of each custom screen designed to ask a question or provide custom help is indicated by a ~ followed by an identifier for the qualifier or variable. The identification can be by name or by number. There should be no other text on the line. ~Q # ~Q "name" ~V # ~ [var name] Following screen is for qualifier # Following screen is for qualifier "name" Following screen is for variable # Following screen is for variable [var name]

For example:
~Q 1 ~Q "DAY" ~V 4 ~[X] indicates the start of the custom screen for qualifier 1 indicates the start of the custom screen for the qualifier named "DAY" indicates the start of the custom screen for variable 4 indicates the start of the custom screen for variable [X]

I - USER INTERFACE

I3.2: Hypertext Keywords


For hypertext screens, the start of the screen for a keyword is indicated by ~~. The ~ is doubled to allow screen definition commands to be used as hypertext keywords. For example: ~~length indicates the start of the hypertext screen for the keyword length

I3.3: Custom Screens for Confidence Variables


In confidence mode 5, the user can be asked for confidence values for the input provided. These questions can make use of the custom screen option. A custom screen for a confidence variable is defined in the same way as for a regular variable or qualifier, but a % must follow the ~. For example, the custom screen for variable [X] would start with: ~[X] or ~V # The custom screen for the confidence associated with [X] would start with: ~%[X] or ~%V #

Likewise the confidence associated with a qualifier would start with: ~%Q "name" or ~%Q #

I4: Returned Data


Several of the screen elements can return information buttons, mouse regions, scroll bars. The syntax of the returned data should be the same as data returned from an external program. (See Section H6 for details of the syntax.) Each item selected may return one line of data. A single screen can return multiple items of data. In most cases, a particular button may indicate that the screen should terminate and return data. Sometimes clicking on any button will return data, in other cases multiple data items are set and then an OK button returns all of the data that was set.

I - USER INTERFACE

In many cases, the returned information needs to contain a quote, ", character to designate a qualifier name or choice text string. Since the screen commands use " " to designate strings, a " character in the string will be incorrectly handled. To avoid this problem, within quoted strings a single quote character ' can be used. This will be converted to a " when the string is returned. For example, if we want to set value 1 of the qualifier named color, the normal return string is Q "COLOR" 1 but in a button command use: ~BUTTON("RED", "Q 'COLOR' 1", 200, 300, 60, 30 - I) notice that the word color is marked with ' rather than ". When the string is returned, the ' will be converted to " to return Q "COLOR" 1.

I4.1: Returning Commands


In addition to returning information, buttons, mouse regions and scroll bars can return commands. The commands are the same as those which can be returned from an external program. !WHY !? or !HELP !KNOWN !EXIT !END Displays the current rules being tested Displays the custom help file associated with the qualifier or variable Displays the known data Exits the program Terminates a hypertext stack - returns to the starting screen even if there are several levels of hypertext screens

For example, if a button was defined as: ~BUTTON("Why?", "!WHY", 200, 300, 60, 30 - I) clicking on the button would display the rules that caused the question to be asked.

I - USER INTERFACE

I4.2: Passing Back a Hypertext Call


In addition to returning information, button, mouse regions and scroll bars can return a call to display a EXSYS hypertext keyword. If the return data starts with an "?", the remainder of the string will be used as hypertext keyword. If a hypertext word is returned, EXSYS will display the custom screen after displaying the screen(s) associated with the hypertext word, so that data can be obtained. This allows custom screens to access the hypertext system, but still be able to obtain the needed data. Note in a custom screen the ^^word^^ is not used. Custom screens echo text to the screen exactly as it is defined. It is the responsibility of the developer to add hypertext buttons, or mouse regions and control the highlighting of the screen. The syntax is: ?keyword For example, if a mouse region was defined: ~MOUSE("?Part 23", 200, 300, 60, 30 -I)

If a mouse click was made in the specified regions , EXSYS would display the hypertext screen associated with the keyword "Part 23". Passing back !END will terminate a hypertext stack and return to the starting screen, even if there are several levels of hypertext screens.

I5: Syntax for a RCT


The following commands frequently require specifying a rectangle on the screen. In the commands this is abbreviated RCT. The syntax for an RCT is: left side, top, horizontal size, vertical size For example 10,10, 100, 50 means a rectangle 100 pixels horizontally, and 50 pixels vertically with the upper left corner at the coordinates 10,10.

I - USER INTERFACE

I6: Setting the Window Size


The window size is set by the ~SET_WIN rct command. It must be the first line in the screen definition for each screen. For example: ~SET_WIN 50,50, 400, 300

will make the overall window 400 pixels wide and 300 pixels high with the upper left corner at 50,50. If there is no SET_WIN command, the default window size is set to: 100,100,350, 250 It is the responsibility of the developer to make sure that all text, buttons, etc. are within the window size specified. The window created will start at the size specified, but can be resized and moved by the end user. If you do not want the end user to be able to move or resize the window, repeat the SET_WIN command twice at the start of the file. This will force the window to remain the same size. For example: ~SET_WIN ~SET_WIN 50,50, 400, 300 50,50, 400, 300

will prevent the window from being moved or resized.

I7: Embedded Variables


Text may be embedded in the commands in a custom screen file using [[ ]]. However, all embedded variables must have a value prior to being used. Double square bracket expressions in a custom screen will not invoke backward chaining or other actions to derive a value. The value must be already known. See Section I16 for the details of double square bracket replacement.

I - USER INTERFACE

I8: GUI Custom Screen Commands


~ARROW x, y direction
Draw an arrow from current point to x,y. End "arrow" sets new starting point for the next line. The point of the arrow is controlled by the direction parameter. direction: START - arrow points to start END (default) - arrow points to end BOTH - arrow has points on both ends

~BACKGROUND color
Sets the background and foreground color. To set entire screen to a color, set background and then do ~CLS. For lines and rectangles, see ~LINE_COLOR and ~FILL_COLOR. color: RED GREEN BLUE CYAN MAGENTA YELLOW BLACK DKGRAY GRAY LTGRAY WHITE #, #, # red, green, blue values for custom colors

~BEEP
Causes a beep to sound.

~BUTTON "label", "return string", rct


Options: -I -C -R -S -E -A -P -X -D
I - USER INTERFACE
9

Define a button. The button can be a push-button, check box or radio button. label return string label for the button, in " " the string to return if the button is pressed, in " ". If the button is pressed, this is the string that will be returned to EXSYS. The syntax of the string should be the same as that used for returning data from an external program into EXSYS. If the return string is "~command", pressing the button causes the specified command to execute immediately. Command can be any EXSYS GUI screen definition command (However ~PAUSE is NOT recommended, and should not be necessary). This is especially useful with ~GOTO commands. When the ~command form is used, normally the -X option will also be used. If more than one command is to be executed, separate commands with "|||" (Three vertical line characters). Note: If double quotes, " , are needed in the return prefix for data element identification, or to define a command string, replace " with ' . The ' will automatically be converted to " when the string is used. rct left side, top, horizontal size, vertical size

Options:
-I -C -R -S return immediately if this button is pressed. (option - default=NO) make button a check box (option - default=normal button) make button a radio box (option - default=normal button) for radio buttons only: Indicates START of the set of radio buttons. Only one item in this set can be selected at a given time. (default=include in current set)
I - USER INTERFACE
10

-E

-A -P -X -D

for radio buttons only: Indicates END of the set of radio buttons. Only one item in this set can be selected at a given time. (default=include in current set) Make active at start - make the button the default. Break a ~PAUSE. Write current data and continue with the next command after the PAUSE. No output in return file - use for command or information buttons. Delete command after executing it. Note: If the return string = ~command form is used, in some cases the command should only be executed once - even if the button is pressed multiple times. The -D option will prevent multiple calls to the same command. The command is again available for use after a reset, such as a ~PAUSE followed by a ~GOTO. Note: Radio buttons must be defined as a set with sequential BUTTON commands. If more than one set is defined, the -S and -E flags should be used to designate the individual sets. If there is only one set, the -S and -E commands flags are not necessary, but the BUTTON commands must be sequential.

Examples:
~BUTTON "RED" "Q1 2" 100, 100, 60, 30 -I will create a button labeled RED at pixel coordinates 100, 100 with a horizontal size of 60 pixels and a vertical size of 30 pixels. If the button is pressed, the string Q1 2 will immediately be returned to EXSYS to set qualifier 1 value 2. ~BUTTON "YELLOW" "Q1 1" 100, 100, 60, 30 -R -S -A ~BUTTON "RED" "Q1 2" 150, 100, 60, 30 -R ~BUTTON "GREEN" "Q1 3" 200, 100, 60, 30 -R -E will create a set of radio buttons button labeled YELOW, RED and GREEN. The starting active button will be the one labeled YELLOW. Since these are defined as a set, only one of the radio buttons can be selected at a given time. Clicking on one will reset the others. When the screen returns (due to some other button) the string associated with the last button pressed will be returned to set the qualifier.
I - USER INTERFACE
11

~CANCEL
Cancel all information already written to return file and empty file. After the ~CANCEL command, new information can be written to the return file. A ~CANCEL command is normally used as a button command or controlled by a GOTO command. To guarantee an empty return file, follow the ~CANCEL by a ~EXIT. For example: ~BUTTON "Cancel" "~CANCEL|||~EXIT" 100, 100, 50, 50 -I

~CLR_BUTTON
Delete all active buttons from the screen. Data on the buttons that were pressed prior to the execution of the ~CLR_BUTTON command, are written to the file before they are deleted.

~CLR_EDIT
Delete all active Edit regions from the screen. Information on the edit regions is written to the file before they are deleted.

~CLR_MOUSE
Delete all active Mouse regions from the screen. Information on the mouse regions that were selected is written to the file before they are deleted.

~CLR_SCROLL
Delete all active Scroll regions from the screen. Information on the scroll bars is written to the file before they are deleted.

I - USER INTERFACE

12

~CLS
Clear window to current pattern and background color. Does not clear buttons, scrolls, edit windows or mouse regions. See CLR_ .

~CURSET x, y
Sets x,y coordinates for next echoed text and sets starting point for a ~LINE or ~ARROW command. x,y - x and y coordinates in pixels.

~EDIT "return prefix", rct


Options: -B -W -1 -H -V -S:x -L -R -F:filename -M:# -X
Add a text edit window to the screen. This can be used to ask for data or present results and explanations. Return Prefix prefix to write before value in return file. If the string includes ##, the ## will be replaced by the number of the line being returned. (e.g. "[addr ##]" would return a series of EXSYS variables [addr1], [addr2], etc. This should usually be used with the -M option.). Note: If double quotes, " , are needed in the return prefix for data element identification, replace " with ' . The ' will automatically be converted to a " when the string is used. rct left side, top, horizontal size, vertical size -B -W -1 -H -V -R -L Do not draw a border around box Do not Wrap text in the box Allow only a single paragraph Disable automatic horizontal scroll Disable automatic vertical scroll Make text read only - no editing allowed Add all following screen command lines to the edit window up to a ~LISTEND command

Options:

I - USER INTERFACE

13

-F:filename Add the contents of file "filename" to the edit window -S:x Set text size. X = B - use big font S - Use small font F - Use fixed space font (Default is to use normal font) -M:# maximum number of lines to return. This is not the maximum that is accepted in the edit window. If more than # lines are entered, they will be ignored. This prevents creating undefined EXSYS variables with ## in the return prefix. Do not return data for this edit box. Information only. Even read only boxes will return data unless the -X option is used. read only box can be a convenient way to force a file of data into the return data file.

-X

Examples:
~EDIT "", 20,20, 300, 200 -F:stuff.txt -R -X

will make an edit region at 20,20 with horizontal size of 300 pixels and vertical size of 200 pixels. The text of file STUFF.TXT will be put in the edit region as a read only file the will not return any data.

~EDIT "[S]",

20,20, 300, 30 -V -1

will make a edit region that will accept one line of text without vertical scrolling. The string entered will be returned, preceded by [S] to indicate that the value is to be assigned to the EXSYS variable [S].

~EDIT _FILL filename


Edit regions can have default values assigned to them with the -L and -F options. However, it may be inconvenient to add text to several edit regions at once. The EDIT_FILL command will add text to multiple edit regions from a single file.

I - USER INTERFACE

14

First create the edit regions with ~EDIT commands, then call ~EDIT_FILL filename. The file specified should contain the values to put in the edit regions. The file should be have one value per line. The value on the first line will be put in the first EDIT regions defined in the screen commands, the second line will be put in the second region defined, etc. To skip an edit region, leave a blank line in the file. If there are more lines than in the screen file, the extra lines will be ignored.

~EXIT
EXIT immediately without writing any additional information to the return file. A CANCEL command is normally used as a button command, or controlled by a GOTO command. Data already written to the return file, will not be deleted. To guarantee an empty return file, follow the ~CANCEL by a ~EXIT.

~FILL_COLOR color
Sets color to use to fill shapes (rectangles and ovals). color: RED GREEN BLUE CYAN MAGENTA YELLOW BLACK DKGRAY GRAY LTGRAY WHITE #, #, #

red, green, blue values for custom colors

I - USER INTERFACE

15

~FOREGROUND color
Sets the foreground color. Foreground applies to text echoed to the screen. For lines and rectangles, see ~LINE_COLOR and ~FILL_COLOR. color: RED GREEN BLUE CYAN MAGENTA YELLOW BLACK DKGRAY GRAY LTGRAY WHITE #, #, #

red, green, blue values for custom colors

~GOTO:label
GOTO to line ~:label. The GOTO point must be in the originally specified screen, defined by the ~word. It is not possible to GOTO a section of the screen file for another ~word. GOTO should be used to go to a label point further DOWN in the file. This is always safe. GOTO can be used to go back in the file, however the action is not exactly the same. When going further down in the file, all current data is saved. When going UP in the file, GOTO resets the starting point for window updates to that new line. Consequently, when going up in the file, it may be necessary to restate some parameters such as color to make sure they are not lost in updates. All buttons, scrolls and edit windows active when a GOTO is called, will stay active. This is to allow screens which can ask additional information only when particular buttons are pressed. Moving up in the file makes it possible to make two copies of a button, scroll, or edit window. This can be a problem because each copy will write data back to the return file. In some cases, it is desirable to recreate buttons which have been cleared, but the screen designer must consider which buttons are active and which are inactive when moving UP the file. Use CLR_BUTTON, etc. and then redefine the button if necessary.

I - USER INTERFACE

16

~:label
GOTO branch point. Used from GOTO as a command or in return string from a button.

~LINE x, y
Draw a line from current point to x,y. End point sets new starting point for the next line. x,y - x and y coordinates in pixels.

~LINE_COLOR color
Sets the color to be used for drawing for lines and borders of shapes. color: RED GREEN BLUE CYAN MAGENTA YELLOW BLACK DKGRAY GRAY LTGRAY WHITE #, #, #

red, green, blue values for custom colors

~LINE_WIDTH width
Set width, in pixels, for lines, arrows and the borders of shapes.

I - USER INTERFACE

17

~MOUSE "return string", rct


Options: -I -2 -P -X -D
Define a mouse region. A mouse region is a region of the screen where a mouse click will cause some action to take place, or some return string to be flagged. return string the string to return if the mouse is clicked in the rct. If the mouse is clicked in the region, this string will be returned to EXSYS. The syntax of the string should be the same as that used for returning data from an external program into EXSYS. If the return string is "~command", pressing the mouse will cause the specified command to be executed immediately. Command can be any EXSYS GUI screen definition command (However ~PAUSE is NOT recommended, and should not be necessary). This is especially useful with ~GOTO commands. When the ~command form is used, normally the -X option will also be used. If more than one command is to be executed, separate commands with "|||" (Three vertical line characters) Note: If double quotes, " , are needed in the return prefix for data element identification, or to define a command string, replace " with ' . The ' will automatically be converted to a " when the string is used. rct left side, top, horizontal size, vertical size of the mouse region

Options:
-I -2 -P return immediately if the mouse is clicked in the region. (option - default=NO) Return immediately only if a Double Click is done in the region Break a ~PAUSE. Write current data and continue with the next command after the ~PAUSE.

I - USER INTERFACE

18

-X -D

No output in return file - use for command or information regions Delete command after executing it. If the return string = ~command form is used, in some cases the command should only be executed once even if the mouse is pressed multiple times in the region. The -D option will prevent multiple calls to the same command. The command is again available for use after a reset, such as a ~PAUSE followed by a ~GOTO.

~OVAL rct
Draws an oval or circle with current line color and type. Fill is current pattern and fill color. The RCT defines the maximum size of the oval. rct left side, top, horizontal size, vertical size

~PATTERN pattern
Defines the pattern to be used for filling solids, rectangles and ovals. pattern: NONE HOLLOW SOLID HORZ VERT FDIAG BDIAG CROSS DIAGCROSS no pattern empty solid horizontal lines vertical lines forward diagonals backward diagonals Crosshatch Diagonal Crosshatch

~PAUSE
Pause the screen and wait for input. The ~PAUSE is broken by a button with a -I or -P option or the EXIT line from the menu. All data elements selected will be written to file after the pause is broken. PAUSE can be used to create multiple part screens that write out some data, clear and ask additional data.

I - USER INTERFACE

19

~ROUND_RECT rct
Draws an rounded corner rectangle with current line color and type. Fill is current pattern and fill color. rct left side, top, horizontal size, vertical size

~RECT rct
Draws an rectangle with current line color and type. Fill is current pattern and fill color. rct left side, top, horizontal size, vertical size

~SAMEAS word
Often there are two or more keywords that should call the same hypertext screens. Sometimes this is due to grammar (plurals for example) or sometimes the words are just synonyms. When there are different keywords calling the same screen, you could just repeat the screen with the new keyword. However, that would waste space and be more difficult to maintain. The ~SAMEAS command allows one keyword to be defined as another. The word referenced must exactly match the ~~keyword line in the .SCR file. The ~SAMEAS command must be the first (and only) line in the set of screen commands for a keyword being referenced to another. Note: This command is ONLY used for hypertext screens. For example, to define WORD1 to use the same screen as WORD2: ~~WORD1 ~SAMEAS WORD2 would cause the WORD1 hypertext screens to be called if WORD2 was selected. Note: Be careful about loops!! In the above example, if we also had: ~~WORD2 ~SAMEAS WORD1 there would be a loop and the system would hang.

I - USER INTERFACE

20

~SCROLL "return prefix", start_val, end_val, rct


Options: -V -H -A:value -D:x,y -X
Add a scroll bar to the screen. This can be used to graphically ask for numerical data or present results. Return Prefix prefix to write before value in return file. This should usually be an identifier for what EXSYS variable will receive the data. Note: If double quotes, " , are needed in the return prefix for data element identification, replace " with ' . The ' will automatically be converted to a " when the string is used. low range of slider value high range of slider value left side, top, horizontal size, vertical size

start_val end_val rct

Options:
-V -H -A:value -D:x,y -X Make slider vertical Make slider horizontal Initial value for the scroll thumb Display current value of scroll thumb at coordinate x,y in current font and color. Set the font and colors before calling ~SCROLL. No return value. Use to display info only.

~SET_WIN rct
Set window size and position - must be the first command. rct left side, top, horizontal size, vertical size

text
A text string with no starting ~ is echoed to the screen in the current text size and color. A screen position can be set with CURSET, and then sequential lines echoed to the screen. Line spacing will be set appropriately for the font size. All lines will have the left margins aligned at the point set by the CURSET column position.

I - USER INTERFACE

21

~TEXTSIZE size
Set the size of the text echoed to the screen, or displayed with a ~SCROLL -D option.

Size:
LARGE NORMAL SMALL

~VERIFY expression
The ~verify command allows user input for a variable to be verified against a boolean expression. It is used only for screens created to ask for user input for variables - not for custom help screens, hypertext or screens for qualifiers. The program will accept user input and then test it using the expression. The expression must be a boolean expression that will evaluate to TRUE for valid data. The expression can contain any valid EXSYS expression. The ~VERIFY command will be considered the last command in the screen definition for the variable. If the input passes the specified test, processing continues. However, if the input fails the test, the commands following the ~verify will be displayed and the original question asked again to get appropriate input. This allows a custom message to be displayed if the data was not appropriate. Data verification, beyond simple range checking, can be removed from the rules and put in the VERIFY statement. This is much simpler and easier to maintain. For example, suppose we have a variable [X] and only want to accept integer values between 0 and 10 and we wanted to display a message if the value was out of range. We could use: ~[X] screen commands for [X] ~VERIFY (([X]>=0) && ([X]<=10) && ([X]==INT([X])) ~SET_WIN 100,100, 300,200 ~PATTERN SOLID ~BACKGROUND RED ~CLS ~CURSET 20,20 The input provided is invalid. The value must be between 0 and 10 and be an integer. You input [[X]] which does not meet the criteria. ~BUTTON "OK", "" , 20, 165, 50, 25 -I ~END more custom screens
I - USER INTERFACE
22

The value input would be checked against the verify expression. If the VERIFY expression was true, the program would continue and use the data. If the expression was false, the custom screens commands following the ~VERIFY up to the start of the next screen would be displayed. The custom screen for [X] would then be redisplayed and new data requested. Note: the command lines following the VERIFY should have an OK button with a -I option or something equivalent to end the window. The VERIFY option can also be used for string variables. Suppose variable [S] can only have one of three acceptable names: ~VERIFY (([S]=="JOE") || ([S]=="SAM") || ([S]=="MIKE")) If the value for [S] is one of the three names it will be accepted, otherwise it will be rejected. VERIFY can also be used with the custom screens for confidence variables.

I - USER INTERFACE

23

I9: Custom Screen Examples


Example 1: This is a screen with simple YES / NO buttons and some buttons for asking for additional information. ~Q "LIGHT" ~SET_WIN 30, 50, 500, 400 ~PATTERN SOLID ~BACKGROUND BLACK ~CLS */ ~FILL_COLOR CYAN ~LINE_COLOR WHITE ~LINE_WIDTH 5 ~ROUND_RECT 20,20,460, 300 ~LINE_WIDTH 2 ~ROUND_RECT 30,30,440, 280 ~FILL_COLOR BLUE ~LINE_COLOR WHITE ~RECT 30, 340, 440, 55 /* screen for Qualifier named LIGHT */ /* set window size */ /* clear screen to solid black

/* draw accent box */ /* draw 2nd accent box */ /* draw main rectangle */ /* add buttons to ask

questions */ ~BUTTON "WHY", "!WHY", 60, 350, 80, 35 -I ~BUTTON "KNOWN", "!KNOWN", 160, 350, 80, 35 -I ~BUTTON "EXIT", "!EXIT", 260, 350, 80, 35 -I ~BUTTON "HELP", "!HELP", 360, 350, 80, 35 -I ~FOREGROUND BLACK ~TEXTSIZE LARGE ~CURSET 50,120 /* position cursor for text */ The WARNING light is ON: /* write text message */ ~BUTTON "YES", "Q 'light' 1", 100,175,100,50 -I ~BUTTON "NO", "Q 'light' 2", 300,175,100,50 -I ~END

I - USER INTERFACE

24

The WARNING light is ON:


YES NO

WHY

KNOWN

EXIT

HELP

Example 2: This screen has several check boxes. Multiple boxes can be checked and the screen will not return until the OK button is pressed.
~~Q "SOUND" /* screen for qualifier "SOUND" */ /* set window size */ /* make non movable */

~SET_WIN 30, 50, 500, 400 ~SET_WIN 30, 50, 500, 400 ~PATTERN SOLID ~BACKGROUND BLACK ~CLS /* fill with solid black*/ ~FILL_COLOR CYAN ~LINE_COLOR WHITE ~LINE_WIDTH 5 /* draw accent box */ ~ROUND_RECT 20,20,460, 300 ~LINE_WIDTH 2 ~FILL_COLOR WHITE ~ROUND_RECT 30,30,440, 280 ~TEXTSIZE NORMAL ~FOREGROUND BLACK ~CURSET 50,60 /* set position for following text */

Reconnecting CABLE A to the system, with the power on and a signal in the amplifier produces: /* define check boxes */ ~BUTTON "No Sound", "Q 'sound' 1", 75,100,150,40 -C ~BUTTON "Static", "Q 'sound' 2", 75,160,150,40 -C
I - USER INTERFACE
25

~BUTTON "Intermittent Static","Q'sound' 3", 75,220,150,40 -C ~BUTTON "Clicks", "Q 'sound' 4", 275,100,150,40 -C ~BUTTON "Loud POP", "Q 'sound' 5", 275,160,150,40 -C ~BUTTON "Good Sound","Q 'sound' 6", 275,220,150,40 -C ~BUTTON "OK", "", 225,270,50,30 -X -I ~END

Reconnecting CABLE A to the system with the power on and a signal in the amplifier produces: No signal Static Intermittent Static Clicks Loud POP Good Sound

OK

Example 3: This screen is almost identical to that in Example 2, but the check boxes have been changed to radio buttons. In Example 2, multiple boxes could be checked, while here only a single radio button can be selected. The screen will not return until the OK button is pressed. ~~Q "SOUND" ~SET_WIN 30, 50, 500, ~SET_WIN 30, 50, 500, ~PATTERN SOLID ~BACKGROUND BLACK ~CLS ~FILL_COLOR CYAN ~LINE_COLOR WHITE ~LINE_WIDTH 5 ~ROUND_RECT 20,20,460, ~LINE_WIDTH 2 ~FILL_COLOR WHITE ~ROUND_RECT 30,30,440, ~TEXTSIZE NORMAL ~FOREGROUND BLACK ~CURSET 50,60 400 400 /* custom screen for qualifier "SOUND" */ /* set window size */ /* make non movable */ /* fill with solid black*/ /* draw accent box */ 300 280 /* set position for following text */

I - USER INTERFACE

26

Reconnecting CABLE A to the system, with the power on and a signal in the amplifier produces: /* define check boxes */ ~BUTTON "No Sound","Q 'sound' 1", 75,100,150,40 -R -S ~BUTTON "Static", "Q 'sound' 2", 75,160,150,40 -R ~BUTTON "Intermittent Static","Q 'sound'3", 75,220,150,40 -R ~BUTTON "Clicks", "Q 'sound' 4", 275,100,150,40 -R ~BUTTON "Loud POP", "Q 'sound' 5", 275,160,150,40 -R ~BUTTON "Good Sound", "Q 'sound' 6", 275,220,150,40 -R -E ~BUTTON "OK", "", 225,270,50,30 -X -I ~END

Reconnecting CABLE A to the system with the power on and a signal in the amplifier produces: No signal Static Intermittent Static Clicks Loud POP Good Sound

OK

Example 4: In this case the radio buttons from example 3 have been rearranged and an edit filed has been added to provide explanation. The text input into the edit field is read only and not returned as data. ~~Q "SOUND" ~SET_WIN 30, 50, 500, 400 /* set window size */ ~PATTERN SOLID ~BACKGROUND BLACK ~CLS ~FILL_COLOR CYAN ~LINE_COLOR WHITE ~LINE_WIDTH 5 /* draw accent box */ ~ROUND_RECT 20,20,460, 300 ~LINE_WIDTH 2 ~FILL_COLOR WHITE ~ROUND_RECT 30,30,440, 280 ~TEXTSIZE NORMAL ~FOREGROUND BLACK ~CURSET 50,60 /* position for writing text */
I - USER INTERFACE
27

Reconnecting CABLE A to the system, with the power on and a signal in the amplifier produces: /* add radio buttons */ ~BUTTON "No Sound", "Q 'sound' 1", 65,100,150,20 -R -S ~BUTTON "Static", "Q 'sound' 2", 65,130,150,20 -R ~BUTTON "Intermittent Static","Q'sound'3", 65,160,150,20 -R ~BUTTON "Clicks", "Q 'sound' 4", 65,190,150,20 -R ~BUTTON "Loud POP", "Q 'sound' 5", 65,220,150,20 -R ~BUTTON "Good Sound", "Q 'sound' 6", 65,250,150,20 -R -E ~BUTTON "OK", "", 225,275,50,25 -X -I /* define edit region */ ~EDIT "", 275,100,180,170 -S:S -X -R -L /* echo text into the edit region */ Connecting the cable to the system should be done with care. First turn off all power to the system. Check that all lights are off. Make all connections and then turn power back on, starting with the preamp. Turn the amplifier on last. If the system makes a loud noise, turn it off immediately and check the fuses. ~LISTEND ~END /* end of edit region text */

Reconnecting CABLE A to the system with the power on and a signal in the amplifier produces: No signal Static Intermittent Static Clicks Loud POP Good Sound OK
Connecting the cable to the system should be done with care. First turn off all power to the system. Check that all lights are off. Make all connections and then turn power back on, starting with the preamp. Turn the amplifier on last. If the system makes a loud noise, turn it off immediately and check the fuses

Example 5: This screen shows a set of SCROLL controls that return values to a set of EXSYS variables simultaneously. The current value of the scroll is echoed beneath it.
I - USER INTERFACE
28

~SET_WIN 30, 50, 450, 320 /* set window size */ ~PATTERN SOLID ~BACKGROUND BLACK ~CLS ~LINE_COLOR BLUE ~FILL_COLOR BLACK ~RECT 10,10,430,300 /* draw a border */ ~TEXTSIZE NORMAL ~FOREGROUND WHITE ~CURSET 20,30 Select the filter pattern to apply to the signal: ~TEXTSIZE SMALL ~FOREGROUND YELLOW ~curset 25,60 2040 ~SCROLL "[F 20 40] ", 1, 100, 27,80,36,135 -D:27,235 -V ~curset 65,60 4080 ~SCROLL "[F 40 80] ", 1, 100, 67,80,36,135 -D:67,235 -V ~curset 105,60 80160 ~SCROLL "[F 80 160] ", 1, 100, 107,80,36,135 -D:107,235 -V ~curset 145,60 160320 ~SCROLL "[F 160 320]", 1, 100, 147,80,36,135 -D:147,235 -V ~curset 185,60 320640 ~SCROLL "[F 320 640] ", 1, 100, 187,80,36,135 -D:187, 235 -V ~curset 225,60 6401K ~SCROLL "[F 640 1K] ", 1, 100, 227,80,36,135 -D:227, 235 -V ~curset 265,60 1K2K ~SCROLL "[F 1K 2K] ", 1, 100, 267,80,36,135 -D:267,235 -V ~curset 305,60 2K4K ~SCROLL "[F 2K 4K] ", 1, 100, 307,80,36,135 -D:307,235 -V ~curset 345,60 4K8K ~SCROLL "[F 4K 8K] ", 1, 100, 347,80,36,135 -D:347,235 -V
I - USER INTERFACE
29

~curset 385,60 8K16K ~SCROLL "[F 8K 16K] ", 1, 100, 387,80,36,135 -D:387,235 -V ~BUTTON "OK", "", 180,260,90,40 -X -I ~END

Select the filter pattern to apply to the signal:


2040 4080 80160 160320 320640 6401k 1k2k 2k4k 4k8k 8k16k

50.5

50.5

50.5

50.5

50.5

50.5

50.5

50.5

50.5

50.5

OK

Example 6: This screen is a multiple text edit, radio button and check box window that could be used to enter a variety of information on a person. When all of the data is entered, clicking on the OK button would return the data entered. The [NAME##] form is used in the name and address field. Each line of the address will be returned as a separate EXSYS variable. The first line will be returned as [NAME1] the second as [NAME2] etc. The same is done for the comment field. This allows long addresses to be entered and used in EXSYS. It is the responsibility of the developer to make sure there are enough appropriately named EXSYS variables to accept the data. ~SET_WIN 30, 50, 500, 400 ~PATTERN SOLID ~BACKGROUND BLUE ~CLS ~BACKGROUND WHITE ~TEXTSIZE NORMAL ~FILL_COLOR BLUE ~LINE_COLOR CYAN /* set window size */

I - USER INTERFACE

30

~LINE_WIDTH 2 /* draw accent box */ ~RECT 10,10,480, 380 ~FOREGROUND WHITE ~CURSET 25,30 Name & Address ~EDIT "[NAME##]", 25,35, 200, 150 -W ~CURSET 25,205 Phone ~EDIT "[PHONE]", 25,215, 200, 30 ~CURSET 25,270 Social Security # ~EDIT "[SSN]", 25, 275, 200, 30 ~BUTTON "MALE", "Q 1 1", 130,320,75,30 -R ~BUTTON "FEMALE", "Q 1 2", 130,345,75,30 -R ~BUTTON "OK","",40,330,40,40 -I ~FILL_COLOR WHITE ~LINE_COLOR WHITE ~RECT 240,20,240,250 ~FOREGROUND BLUE ~CURSET 260,35 Experience ~BUTTON "Technical", "Q 2 1", 270,40,130,30 -C ~BUTTON "Sales", "Q 2 2", 270,65,130,30 -C ~BUTTON "Management", "Q 2 3", 270,90,130,30 -C ~BUTTON "Clerical", "Q 2 4", 270,115,130,30 -C ~BUTTON "Other", "Q 2 5", 270,140,130,30 -C ~CURSET 260,195 Highest College Degree ~BUTTON "HS", "Q 3 1", 260,200,60,30 -R ~BUTTON "BS", "Q 3 2", 260,225,60,30 -R ~BUTTON "MS", "Q 3 3", 340,200,60,30 -R ~BUTTON "PhD", "Q 3 4", 340,225,60,30 -R ~FOREGROUND WHITE ~EDIT "[COMNT##]", 240,275, 240, 100 -S:S -L COMMENTS: ~LISTEND ~END

I - USER INTERFACE

31

Name and Address

Experience Technical Sales Management Clerical Other Highest College Degree HS MS BS PhD Comments Male Female

Phone

Social Security #

OK

Example 7: This example shows the use of the ~PAUSE command. Part of the screen is displayed, and after pressing a button the rest of the screen is displayed. The "NOT within Spec" button will execute a GOTO command to display the rest of the screen and display the scroll bars. The "WITHIN spec" button will immediately return. ~SET_WIN 30, 50, 500, 400 /* set window size */ ~PATTERN SOLID ~BACKGROUND BLACK ~CLS ~FILL_COLOR CYAN ~LINE_COLOR WHITE ~LINE_WIDTH 5 /* draw accent box */ ~ROUND_RECT 20,20,460, 300 ~LINE_WIDTH 2 ~ROUND_RECT 30,30,440, 280 ~TEXTSIZE NORMAL ~FOREGROUND BLACK ~CURSET 50,70 The process temperature and pressure measurements are: ~BUTTON "WITHIN Specs", "Q 'spec' 1", 50,120,140,30 -I ~BUTTON "NOT within Specs", "~GOTO:spec", 50,180,140,30 -X -D ~PAUSE /* pause at this point */ ~:spec ~LINE_COLOR RED /* highlight box */ ~LINE_WIDTH 4 ~RECT 46,176,148,38

I - USER INTERFACE

32

~LINE_COLOR WHITE ~CURSET 210, 100 ~LINE 210,290

/* draw vertical line */

/* temperature scroll */ ~FOREGROUND WHITE ~SCROLL"[TEMP]",170, 220, 220,120,215,10 -H -A:212 -D:350,110 ~CURSET 220,110 ~FOREGROUND BLUE TEMPERATURE /* add label */ ~CURSET 235,152 ~TEXTSIZE SMALL 170 180 190 200 210 220 /* pressure scroll*/ ~TEXTSIZE NORMAL ~FOREGROUND WHITE ~SCROLL"[PRESSURE]",2.0,4.1,220,200,215, 10 -H -A:2.8-D:325,190 ~CURSET 220,190 ~FOREGROUND BLUE PRESSURE /* add label */ ~CURSET 235,232 ~TEXTSIZE SMALL 2.0 2.5 3.0 3.5 4.0 ~TEXTSIZE NORMAL /* delete or move down */ ~FOREGROUND WHITE /* delete or move down */ ~BUTTON "OK", "", 235,245,80,50 -X -I ~END When the screen is first displayed it uses only the commands up to the ~PAUSE:

I - USER INTERFACE

33

The process temperature and pressure measurements are WITHIN Specs

NOT within Specs

If the NOT within Specs button is press, the rest of the screen is displayed:

The process temperature and pressure measurements are TEMPERATURE 212.0 WITHIN Specs 170 180 190 200 210 220 NOT within Specs PRESSURE 2.0 2.5 2.8 3.0 3.5 4.0

OK

I - USER INTERFACE

34

I10: EXSYS_CS Custom Screen Preview


You can test the custom screens that you develop without running the full expert system by using the program EXSYS_CS. Use this syntax for calling EXSYS_CS: EXSYS_CS filename -R:ret_filename filename ~word -R:ret_filename ~word

file containing the screens word to search for. Screen starts after ~~word in file Filename to use as the return data file. Default = return.dat.

EXSYS_CS will display the custom screen specified in the command line. If the program is called with no command line, it will ask for the name of the file and ~word to display. If EXSYS_CS is called with only a file name, it will display all of the screens in the file.

I - USER INTERFACE

35

I11: Custom Screens to Ask Questions


EXSYS allows you to create custom screens to ask questions of the user. These screens replace the standard format of the questions asked by the program. The use of custom screens allows you to customize the user interface. The screen definition language allows easy customization of the question screens, without having to write external program calls. Custom screens can also be used to validate data before it goes to the rules with the VALIDATE command. This can save many rules in complex systems. In addition, explanation screens can be displayed if the data does not pass the validation test, and the user will automatically be asked for new input. Custom screens to ask questions are kept in a file named: <expert system name>. SCR This file must be in the same directory/path as the other knowledge base files. If we had a knowledge base named TEST, the custom screen file would be TEST.SCR. If a qualifier or variable has a custom screen, it will automatically be used in place of the normal EXSYS questions about the item. The custom screen is displayed and the program will then wait for the user to supply an answer by clicking on a button or some other action. Custom screens are created with a word processor or text editor. Lines starting with ~ are used to indicate the start of a custom screen or a screen definition command. See Chapter I for the details of creating a custom screen file. If a qualifier or variable has an associated command, such as a RUN or dBase command, the command will be executed rather than the custom screen. Note: It is not necessary to have a custom screen for each qualifier or variable. EXSYS will automatically use the default screen if there is no custom screen.

I - USER INTERFACE

36

To make a custom screen file, start a file named <knowledge base name>.SCR. Use the screen commands described in Chapter I to build the custom screen. You can check the screens quickly with the EXSYS_CS utility. It may take some experimentation to get the screens the way you want them. The screens in this file will be called automatically when EXSYS needs information.

When Developing New Systems


The .SCR file makes it easy to have a custom interface for the questions in your system, but remember, first make it work, then make it pretty. When developing a new system, do not worry about custom screens until the logic of the system works. For development, just use the standard EXSYS questions. When it is ready to be distributed to users, then make custom screens to change the user interface if it is desired.

I - USER INTERFACE

37

I12: Context Sensitive Help Files


A user can create custom help files for their knowledge base. This is useful where it may be necessary to explain in detail about a qualifier or variable. In general, it is best to keep the text of the qualifiers and variables short, but sometimes a new user may require a long section of text to explain exactly what is needed for input. It would be confusing to include all of the information in the text of the variable or qualifier, and it would not be desirable to print the information in each rule. Also, once the user reads the full explanation once, they will usually not need to do so again and will be able to answer the short question on subsequent runs. The custom help files can provide the longer explanation, while still having short qualifiers. The custom help file is very similar to the custom screen file to ask questions. To create a user help file, create an ASCII file with a text editor, named: <knowledge base name>.HLP This file must be in the same directory/path as the other knowledge base files. If we had a knowledge base named TEST, the help file would be TEST.HLP. The help file is defined using the custom screen commands described in Chapter I. The order of the qualifiers or variables is unimportant and not all qualifiers or variables in a knowledge base need have a custom help screen in the file. If a qualifier or variable does have a screen defined, the Explain Question menu item under the Questions menu will be active. Selecting this menu item will display the custom help screen. The custom help screen can also be displayed by returning !HELP or !? from the custom screen used to ask a question, or from an external program.

I - USER INTERFACE

38

I13: Hypertext
EXSYS supports a hypertext help system. This system allows a series of explanatory screens to be created that can be called as needed by the user. The screens are indexed by keyword and can be called from most of the EXSYS screens. Hypertext is different from the custom help screens or the WHY command. The WHY command displays the logic of the rules that lead to an item of information being requested. The custom help screen displays detailed information on the question being asked and what the user is expected to do. Hypertext is not associated with a specific qualifier or variable, but with words. These words can appear in qualifiers, rules, choices, notes, etc. Whenever a hypertext keyword is displayed on the screen, it will be highlighted in blue and the user can ask for more information on what that word means by double clicking on it. It does not matter if the word is displayed as part of a question, part of a rule or in the conclusions. If the user does not understand the word, he can get help by double clicking. Most importantly, these hypertext keywords can appear in other hypertext screens. This allows one hypertext screen to call other hypertext screens to explain its keywords. This provides a multi-level help system that can be very complex. Hypertext screens can contain embedded EXSYS variables, so the explanation can be specific to the data input. (NOTE: If embedded variables are used, make sure that they have a value (DATALIST, rules, etc.) before the hypertext screen is called.

I - USER INTERFACE

39

I13.1: Defining Screens


The individual screens for each hypertext keyword are created and stored in the .SCR file for the knowledge base. This is the same file as used for custom screens to ask questions. The hypertext screens are created using the screen definition commands described in Chapter I. A screen is indicated to be a hypertext screen by putting double ~ "~~" before the key word. So if the key word was EXSYS, the entry in the .SCR file would be: ~~EXSYS screen definition If the keyword "EXSYS" is flagged anywhere in the program and selected, this screen is displayed. The screen created can also contain other keywords activated by buttons or mouse clicks. Make sure that there is a screen for every keyword flagged in the system. In many cases, the use of the ~SAMEAS command will reduce the number of screens required.

I13.2: Flagging Keywords


To indicate that a word (or phrase) in an EXSYS system is a hypertext keyword, precede and follow it with ^^. The keyword or phrase can be up to 40 characters. It must be exactly the same spelling (including spaces) as the word in the .SCR file - but the match is not case sensitive. Keywords can be flagged in the text of qualifiers, variable prompts, choices, text only variables, notes, and references. Essentially any text that EXSYS puts on the screen can have hypertext words flagged. For example, we might have a qualifier with an unusual word: The ^^thermothrocal^^ temperature is ... By putting thermothrocal in ^^, we have made it a hypertext keyword. Whenever this qualifier is displayed on the screen, Thermothrocal will be highlighted in blue. This indicates that it is a keyword. The ^^ will not be displayed on the screen. A screen can have up to 40 keywords simultaneously displayed. The ~SAMEAS command can be used when there are two keywords that call the same screens. This can often happen if grammar requires that the words not be quite identical. For example, you might have a sentence that has the word thermothrocals. Selecting this as a keyword will not match on a screen definition
I - USER INTERFACE

40

starting with ~~thermothrocal (no ending S). Rather than repeat the screen, just add an entry: ~~thermothrocals ~SAMEAS thermothrocal This will cause the thermothrocal screen to be called.

I13.3: Using Keywords


If a screen is displayed with hypertext keywords highlighted, and you wish to know about one of the words, double click the keyword. The screen defined for that word will be displayed. If this screen also has hypertext keywords, they can be selected to display a screen for the new keyword. This can be repeated for many layers. As each screen is terminated (usually with an OK button), the previous (calling) screen will be displayed. If any of the screens return !END the entire set of hypertext screens will be closed and the starting screen will be displayed. The !END command is usually returned from a Cancel button in the hypertext screens: ~BUTTON "CANCEL", "!END", 20, 300, 80, 30 -I The inclusion of a Cancel button is an option for the system developer and is not required. However, if very deep multi-level hypertext is expected, a Cancel button is a good idea.

I13.4: The .HYT File


There is a file created by EXSYS for indexing the hypertext - the .HYT file. This file is automatically created and should never be modified by anyone. It contains offset information for the .SCR file. If a modification is made to the .SCR file, the .HYT file will automatically be updated. This is done at runtime (either from the editor or runtime program) and, for a large .SCR file may take a little time. This is only done if the .SCR file has been modified. The .HYT file allows much faster loading time and access to custom screens and hypertext screens. Remember to move the .HYT file with your knowledge base if a copy is made. (However if you forget, EXSYS will build a new one.)

I - USER INTERFACE

41

I13.5: Example:
Suppose we have a qualifier: The ^^thermothrocal^^ temperature is 1 above ^^threshold^^ 2 at or below ^^threshold^^ We would enter this just as it is displayed here, with the ^^. We might use this to build a rule: IF: The ^^thermothrocal^^ temperature is at or below ^^threshold^^ THEN: ...... When we run this system, any time the qualifier text is displayed, either to ask a question, display the rule, display the know data or display the conclusions, the words "thermothrocal" and "threshold" will be highlighted and the ^^ will not be displayed. Any time the keywords are displayed, the user could double click the highlighted word and select the hypertext screen for these words. A .SCR file would contain the hypertext screens in it: ~~thermothrocal screen commands . . . ~~threshold screen commands . . It is not necessary to have every screen call others, but the real power of hypertext is its ability to create hierarchical help systems that provide the proper level of detail for any user.

I - USER INTERFACE

42

I14: Inserting Value Text in the Middle of Qualifiers

EXSYS normally appends the text of the value(s) selected to the end of the qualifier text to create a condition. For example, if we have the qualifier: The color is 1 red 2 green 3 blue and we select 2, green will be added after the qualifier to make the condition "The color is green". For most situations this is suitable, however, there are times when it is desirable to put the value text in the middle of the sentence. EXSYS allows the value(s) to be put anywhere in a qualifier by inserting four underline characters, _ _ _ _ , at the point where the values are to be inserted. For example you could have: The______is red 1 house 2 car 3 boat If you selected 2, the condition "The car is red" would be built. Users are asked the question with the four underline characters as a fill-in-the-blank type question.

I - USER INTERFACE

43

I15: ASCII Codes

ASCII control characters can be embedded in any text string by using the notation @@### where # is the three digit ASCII code for the character desired. There must be 3 digits following the @@ even for codes less than 100. For example: This @@013@@010 is will replace @@013 with an ASCII 13 and replace @@010 with an ASCII 10 and print a carriage return/line feed between "This" and "is". The ASCII conversion is only performed during the run mode, so editing of the codes can be done in the edit mode. WARNING: ASCII REPLACEMENT MUST BE USED WITH CAUTION!!! Many operations in EXSYS are designed to stay within certain screen boundaries if standard alphanumeric text is used. Embedding ASCII codes can cause the text to go out of those boundaries with undesirable effects. Embedded codes are best for simple formatting or printer control in the report generator.

I - USER INTERFACE

44

I16: Embedding Data in Text


EXSYS allows many text strings to be modified by having embedded data in them to modify the text with the value of the variable or qualifier.

I16.1: Variables
Data on a variable is embedded in text by entering its name in double square brackets. The value of the variable will be used to replace the [[var name]] in the text. For example: Hello, [[NAME]], please enter the value of X would have [[NAME]] replaced by the value of the string variable [NAME]. If [NAME] had the value "John", the string would be displayed as: Hello, John, please enter the value of X EXSYS will usually backward chain during a run to derive the value for the variable in [[ ]] or will ask the user for a value. If WHY is used, or certain window operations are being performed, backward chaining is turned off, and only known values will be used. In this case, rules may be displayed with [[ ]] expressions if there is no data. The [[ ]] expressions can be used in: Qualifiers Qualifier values Choices Notes References Text associated with a variable Command File line Report generator commands Custom screen command Custom Help commands One powerful use of double brackets is to have the [[ ]] expression in a qualifier or variable text, contain a RUN ( ) command or other internal command.

I - USER INTERFACE

45

For example, suppose we have a qualifier: [[X]] The color is 1. Red 2. Green 3. Blue and we set the value of the string variable [X] to RUN(GETCOLOR). EXSYS will consider the text of the qualifier to be RUN(GETCOLOR) The color is and will call the external program GETCOLOR for the value of the qualifier. We could easily assign a different external program to the qualifier by changing the value of [X]. Another application is to embed variables in the note or reference text of a rule. This makes the note more precise to the data entered. For example, we might have an explanatory note: Since the length is [[LENGTH]] and ...... The value of the variable [LENGTH] will be used in the note to make a more precise statement explaining why the rule fired. The embedded variables will be used in the display of results or in text printed from the report generator.

I16.2: Formulas
In EXSYS, replacement of [[ ]] is also supported in formulas, allowing the rules to self-modify the formulas being tested. A formula is parsed for [[ ]] expressions before being evaluated. For example, the formula 3[[X]]2 could have [X] be replaced with "+" for a value of 5 or "-" for a value of 1 or "7" for a value of 372.

I16.3: Qualifiers
The text of a qualifier and its values can also be used as an embedded variable. The syntax is: [[*Q <qualifier number>]] [[*Q "<qualifier name>"]]

I - USER INTERFACE

46

Note: The * is required as the first character to indicate the name is not a variable name. The text of the qualifier/value will be placed in the string in place of the [[ ]] expression. For example, suppose qualifier 3 is "The color is" and values "RED" and "BLUE" are set. If we had text: The values set so far are: [[*Q 3]] it would be displayed as: The values set so far are: The color is RED and BLUE

I16.4: Embedding Qualifier Values


The full text of a qualifiers and its value can be embedded by using: [[*Q #]] or [[*Q "name"]]

However this embeds the text of both the qualifier and all of the values that have been set. There are times when it is desirable to embed only the value(s) or the number(s) of the value(s) which are set. To do this use: [[*QV #]] [[*QN #]] or or [[*QV "name"]] [[*QN "name"]]

The [[*QV...]] will be replaced by the text of only the values set for the qualifier. The [[*QN ...]] will be replaced by only the number of the values set. For example, suppose we have a qualifier 5: The 1 2 3 and value 2 is set: [[*Q 5]] [[*QV 5]] [[*QN 5]] would be replaced with THE COLOR IS WHITE would be replaced with WHITE would be replaced with 2 color is red white blue

I - USER INTERFACE

47

I16.5: Embedding Expressions


In addition to single qualifiers or variables, entire expressions can be embedded in text. The syntax for this is: <? expression ?>

The expression can be any EXSYS expression, involving numeric or string variables. Any of the supported mathematical operators or functions can be used. The <? ?> syntax can be used to embed a value in any EXSYS text, including qualifiers, notes, references, choices, report generator commands, command files, etc. Any place that a [[ ]] can be used, a <? ?> can be used. This eliminates the need to create temporary variables to embed in data. For example, we could have a note: The sin of [[X]] is <? sin([X]) ?>

This would replace [[X]] with the value of [X] and then replace the <? ?> expression with the sin([X]). String variables can also be used: The part number is <? [str 1] + "-" + [str 2] ?> The strings will be concatenated and then displayed. Functions can also be embedded: The largest is <? MAX([X], [Y], [Z]) ?>

I16.6: Recursive Brackets


A [[ ]] expression may be within another [[ ]] expression or within the <? ?> expression. This allows very complex expressions to be generated: For example, suppose string variable [FCT] is the name of a function: X was given the value <? [[FCT]]([Y]) ?> If [FCT] had the value "TAN", the expression would become: X was given the value <? TAN([Y]) ?> which would then be evaluated.
I - USER INTERFACE

48

I16.7: [[ ]] Replacement in the Report Generator and Command File


The [[ ]] replacement technique to insert the value of a variable in a string can also be used in the report generator and the command language commands. In the report generator, the variable must have a value already assigned. In the command language, if a variable does not have a value, backward chaining will be used to get a value or the user will be asked for the value. For example, the report generator command: C >[[X]] would replace the [[X]] with the value of variable X. Only choices with a value greater than X would be output.

I - USER INTERFACE

49

Chapter J Command Language

EXSYS Professional provides a command language to control the execution of a knowledge base. The command language provides control mechanisms for the input of data, execution of rules, display of results, looping, branching, etc. The command language can be used in conjunction with the report generator specifications for even greater control. The command language is similar to DOS batch language in many respects. Most of the individual commands are quite simple; however, the combination of commands allows great power and flexibility. External programs, report specifications and named subsets of the rules can be accessed by single commands. The default command file for an expert system is in the following file: <expert system name>.CMD For example, if the name of the knowledge base file is TEST, the command file would be TEST.CMD. The command file must be in the same subdirectory as the .RUL and .TXT portion of the knowledge base. The command file is simply an ASCII file and can be created with any ASCII editor or word processor in ASCII mode. Note: Many word processors add special formatting characters that will not produce files that can be used as command files. If you are using a word processor, make sure it is in a mode that does not introduce special characters. To check if the file has formatting characters, print the command file to the screen with TYPE <filename>. If the display does not have unusual characters, it should work for command file editing. The command file is optional. If a command file is not present, EXSYS will default to the standard mode of a backward chaining system using all rules and displaying results at the end of the session. If the command file is present, EXSYS will use it automatically.

J - COMMAND LANGUAGE

J1: Changing the Name of the Command File


The name of the command file may be changed with the command line or .CFG file option: COMMAND=<file name> The above redefines the name of the command file to be used.

J2: Expressions and Variables


While expressions can be evaluated in the command language, it is expected that most of the evaluation of qualifiers, choices and variables will be done in the rules. The command language allows running named subsets of the rules to set values with conditional branching in the command language, depending upon the results. The use of rule subsets allows running only those rules that derive a particular piece of information and then branch on the resulting value. Note: All variables used in the command file must be defined in the rule set.

J - COMMAND LANGUAGE

Command Language

Request User Input for a Specific Item ASK


The ASK command in the command file behaves exactly like the ASK command in the .CFG file. EXSYS will ask the user for the value of the qualifier(s) or variable(s) specified. If the qualifier or variable has an associated command such as RUN( ) or DB_...( ), the appropriate action will be performed. If there is no special operation to be performed, EXSYS will ask for the information using the standard request format or custom screen if one has been created. Syntax: ASK Q # ASK Q "name" Ask qualifier number #. Ask the qualifier named or, if wild cards are used in the name, ask all of the qualifiers that meet the name criteria. Ask variable #. Ask variable named or, if wild cards are used in the name, ask all of the variables that meet the name criteria.

ASK V # ASK [var name]

Examples: ASK Q "COLOR" ASK Q "A*" ASK [TE*] ASK [?D] will ask the qualifier named COLOR. will ask all qualifiers whose names start with A. will ask all variables whose names start with TE. will ask all variables whose names are two letters ending in D.

J - COMMAND LANGUAGE

Command Language

Make a Beep Noise to Alert User BEEP

The BEEP command in the command file behaves exactly like the BEEP command in the .CFG file.

J - COMMAND LANGUAGE

Command Language

Branch Point Label


Any line which has : as the first character will be used as a branch point label. Such lines will be ignored during normal execution and serve only as a branch point for a GOTO command. The label should not include spaces and can be up to 15 characters long. For example, commands.... :LOOP commands.... GOTO LOOP would return to the line ":LOOP" when executing the GOTO command. Note: The matching of label names is not case sensitive. That is, a label ":loop" will be found by a "GOTO LOOP," even though one is in upper case and the other in lower case.

J - COMMAND LANGUAGE

Command Language

Causes a "Change and Rerun" Option CHANGE <loop pt.>


The CHANGE command causes a change/rerun option. All data input by the user is displayed for the user to change. When the user decides to run the modified data, the program goes to the <loop pt> label in the command file. All data is cleared out before going to the loop point. The following example, :LOOP RULES ALL WHILE ([X]<100) CHANGE LOOP WEND RESULTS would run the rules and keep asking for changed input until [X] was greater than 100.

J - COMMAND LANGUAGE

Command Language

Allow Command Files to be Commented Comments: /*

Anything on a line following /* is ignored. This allows comments to be included in the command file. Starting spaces are ignored. The following example, /* This is a comment

would be ignored by the program. ASK [X] /* get the value of X

would perform the ASK command and ignore the comment starting with /* A note to C programmers: The /* does not carry over to other lines and does not require a */ to end the comment.

J - COMMAND LANGUAGE

Command Language

Erase Data or Reset Rules to Unused CLEAR

The CLEAR command is the same as the internal CLEAR( ) command, except it lacks the ( ). The CLEAR command is used to clear qualifiers, variables, choices or rules for re-use. The "ALL" and range options for CLEAR work from the command file, but not the "THIS" option, which can only be used in the internal command form from a rule. Syntax: CLEAR CLEAR CLEAR CLEAR CLEAR CLEAR CLEAR CLEAR CLEAR Q # Q "name" V # [var name] C # C "text" R # R "name" X a-b Clear qualifier number #. Clear named qualifier(s). Clear variable number #. Clear named variable. Clear choice number #. Clear choice containing "text." Clear rule number #. Clear named rule. Clear all items between a and b. The X can be Q, V, C or R for qualifier, variable, choice or rule. Clear ALL items. The X can be Q, V, C or R for qualifier, variable, choice or rule. Clear all qualifiers, variables and choices.

CLEAR X ALL

CLEAR ALL

When a qualifier or variable is cleared, it is reset to an unknown state and will be re-derived or re-asked if needed. If the confidence system is custom formulas, the confidence variables associated with the qualifier or variable will also be cleared. When a choice is cleared, it is reset to its initial state. When a rule is cleared, it is reset to unused and can be fired again.

J - COMMAND LANGUAGE

Here are some examples: CLEAR R 34-56 clears all rules from 34 through 56. clears the first 5 qualifiers. clears all rules. clears all variables. clears all qualifiers whose NAME starts with A. clears the rule named XXX. clears all choices that have the string "ZZZ" in them. clears all rules with 3 character names ending in "XX."

CLEAR Q 1-5 CLEAR R ALL CLEAR V ALL CLEAR Q"A*" CLEAR R"XXX" CLEAR C"ZZZ" CLEAR R"?XX"

J - COMMAND LANGUAGE

Command Language

Call Another Command File CMDFILE


The CMDFILE command allows calling and executing another command file from within a command file. The called command file can end with EXIT, in which case the program will return to the operating system or DONE, in which case the program will continue with the next line in the calling command file. Syntax: CMDFILE <filename> <Filename> is the name of the new command file to run. The following example, commands.... IF [X] > 0 CMDFILE FILE1 ELSE CMDFILE FILE2 ENDIF commands.... will check the value of [X]. If it is greater than 0, the commands in command file FILE1 will be run; if not, the commands in FILE2 will be run. Unless the called command file ends with an EXIT command, the commands following the ENDIF will be run.

J - COMMAND LANGUAGE

10

Command Language

Cause the Next Record of Data to be Read from a DATALIST File DATALIST <loop pt.>
The DATALIST command causes the next set of data to be read from the DATALIST file. The DATALIST option must still be specified as a command line option. Note: The first set of data is read from the datalist file before the .cmd file is started. The DATALIST command causes the next set of data to be read. After data is read, the program branches to the loop point specified. If there is no more data, the branch is not executed and the program falls through to the next command in the .cmd file. DATALIST does not clear any data. It should be preceded by whatever CLEAR commands are needed for the particular system, usually CLEAR ALL. The following example, :LOOP RULES ALL REPORT XXX CLEAR ALL DATALIST LOOP BEEP runs all rules and writes a report for each set of data. The CLEAR ALL prevents data from a previous run from being kept in the next run. The DATALIST command causes the next set of data to be read and then the program to branch to the line labeled :LOOP. When there is no more information, the DATALIST command does not go to LOOP, but rather falls through to the BEEP.

J - COMMAND LANGUAGE

11

Command Language

dBase III Interface Commands


The DB_... commands are essentially the same as the DB_ ... internal commands used in rules. These commands allow direct reading and writing from dBase III files without the overhead of loading the entire dBase program. Four commands allow the command language to read or write directly from dBase III files. dBase III files can be accessed from rules, the report generator or the command files. The syntax of the call is the same in each case. Note: Underlined items can be repeated multiple times. Get data from db file by key: DB_GK(<db file>, <index file>, <index value>, <field name>, <address>) Put data in db file by key: DB_PK(<db file>, <index file>, <index value>, <field name>, <var name>) Get data from db file by record number: DB_GN(<db file>, <rec #>, <field name>, <address>) Put data in db file by record number: DB_PN(<db file>, <rec #>, <field name>, <var name>) <db file> <index file> <index value> <field name> The full name of the dBase III file to be used. The full name of the file that has the index of the <db file>. The value to search for in the idex. The name of the field that contains the data to be read from or the name of the field to be written to. The name of the EXSYS variable in []. The value of the variable will be read or written to the specified db field. The name always applies to the field name specified to its left.

<var name>

J - COMMAND LANGUAGE

12

<address>

<rec #>

The item in which to store the data obtained. The item can be a variable, qualifier or choice. For a variable, use the name of the variable in [ ]. For a qualifier, use "Q" followed by the number of the qualifier or the name of the qualifier in quotation marks. For a choice, use "C" followed by the number of the choice or a unique text string in quotation marks. There must not be any spaces in the string between the C, V or Q and the number or quotation mark. The number of the db record to use.

The database file name, index name and index variable can be a variable. <var name> must be an EXSYS variable. Since the field name and associated variable can be repeated as many times as desired, multiple fields from the same record can be passed or returned on a single call. The data returned for qualifiers or choices, should be in the same form as if it were being returned for an external program call. For example, if the database call returned "1,2,3" to a qualifier, it would set the first three values of the qualifier to true. The following example, DB_PN(parts.dbf, 5, price, [X]) will WRITE the value of variable [X] into field "price" of record 5 of database "parts." DB_GN(parts.dbf, 5, price, [X], number, Q1) will READ the value of field "price" from record 5 of data base "parts" into variable [X] and the data in field "number" will be used to set the value(s) in qualifier 1. If needed, there could be additional field and variable pairs in the expression to get more data from the record. DB_PK(parts.dbf, part.ndx, A567, price, [X]) will WRITE the value of variable [X] into field "price" of the record in database "parts," indicated in the index file "part.ndx" by the value "A567." DB_GK(parts.dbf, part.ndx, A567, price, [X]) will READ the value of field "price" into [X] from the record in database "parts," indicated in the index file "part.ndx" by the value "A567."
J - COMMAND LANGUAGE
13

Top Record Function


There is also a function which has been added for working with databases. The function returns the number of records in a database file. This is particularly useful when running an expert system against every record in a file. To call the function, use TOPREC(<filename>) where <filename> is the name of the database file in quotes. The following example, TOPREC("price.dbf") would return the number of records in the database file "price.dbf." This function can be used like sin( ), cos( ) or any other EXSYS function. It can be used most effectively in the command language. Here is an example: SET [I] 0 WHILE ([I] < TOPREC("price.dbf") . . . RULES ALL REPORT DBRPT . . . SET [I] ([I]+1) WEND The above would run the rules against each record in a database, producing a report with the report specification DBRPT. The program could get data one record at a time with a DB_... call.

J - COMMAND LANGUAGE

14

Command Language

Display the Contents of a File DISPLAY

The DISPLAY command displays the contents of a file on the screen. The user can go forward or backward in the file. This is the same as the DISPLAY command in rules. Syntax: DISPLAY <filename> <options> DISPLAY [string variable name] filename - the name of the file to display. string variable name - a string variable whose value is the name of the file to display. <options>

Options
/C - File to display uses GUI Custom Screen Commands The /C option causes the DISPLAY command to parse the file for Custom Screen Commands. See Chapter I for a discussion of the GUI Custom Screen Language. /N - No wait after screen is displayed The /N option causes the DISPLAY command to display the requested file in a window and immediately continue processing. This can be useful for report files that are created and displayed. By using the /N option, you may have several report data windows simultaneously active. /S - Small text The /S option causes the DISPLAY command to display a text file using a small font. The default is to use a larger font. This applies only to ASCII files. /F - Fixed size font The /F option causes the DISPLAY command to display a text file using a fixed size font. This is useful for aligning columns of data. The /S and default fonts are proportionally spaced and aligning data can be difficult. This applies only to ASCII files.

J - COMMAND LANGUAGE

15

The following example, DISPLAY INTRO.MSG will display the contents of the file INTRO.MSG on the screen. DISPLAY scr1.scr will display the file scr1.scr on the screen using Custom Screen Language commands.

J - COMMAND LANGUAGE

16

Command Language

Exit a Command File Called by Another Command File DONE


The DONE command is used to exit a command file when it has been called from another command file. This differs from the EXIT command which immediately exits to the operating system. DONE returns to the calling command file to execute any following commands. If there are no following commands, DONE behaves like EXIT. Syntax: DONE The following example, commands.... DONE in a command file called from another command file using the CMDFILE command would return to the initial command file and allow subsequent commands to be executed. An EXIT command in the same place would go to the operating system without returning to the initial command file.

J - COMMAND LANGUAGE

17

Command Language

Exit to the Operating System EXIT

The EXIT command terminates the run and returns to the operating system. Syntax: EXIT The following example, commands.... IF [X]>[Y] EXIT ENDIF would exit to the operating system if the value of [X] is greater than [Y].

J - COMMAND LANGUAGE

18

Command Language

Unconditional Branch GOTO

The GOTO command causes an unconditional branch to another line in the command file. Syntax: GOTO <label> <Label> is the text of the branch point to go to. The branch point must be a single line starting with a : and containing the text of <label>. The reference to the label in the GOTO command does not use the ":". The following example, :LOOP commands... GOTO LOOP will cause the program to return to the line :LOOP when the "GOTO LOOP" command is found.

Use of GOTO with Nested IF or WHILE Structures


If there are nested IF or WHILE structures, the GOTO command should not be used to go to a deeper nesting level. It is legal to use the GOTO to go to the same or higher nesting level. This is because the IF or WHILE are looking for the next ENDIF or WEND that they encounter. If they go to a deeper nesting level, they will find another ENDIF or WEND and not know that it applies to that level. As long as the nesting level is the same or higher, the program can determine where it is.

J - COMMAND LANGUAGE

19

For example, the following are legal (In all cases IF/ENDIF can be replaced with WHILE/WEND). IF [X]>0 GOTO X ENDIF :X _________________ :X IF [X]>0 GOTO X ENDIF _________________ IF [X]>0 :X GOTO X ENDIF _________________ IF [X]>0 GOTO X _ :X ENDIF _________________

J - COMMAND LANGUAGE

20

IF [X]>0 IF [Y] < 10 GOTO X ENDIF _ :X ENDIF _________________ IF [X]>0 IF [Y] < 10 GOTO X ENDIF _ ENDIF :X The following is not legal because the GOTO jumps over an IF to a deeper nesting level. This will not be caught as an error, but may give incorrect results. IF [X]>0 GOTO :X IF [Y] < 10 :X ENDIF _ ENDIF

J - COMMAND LANGUAGE

21

Command Language

Allow Conditional Execution of Blocks of Rules IF....ELSE....ENDIF

The IF command allows conditional execution of blocks of commands. Syntax: IF <expression> commands.... ELSE (optional) commands.... ENDIF (not optional) <expression> can be any mathematical expression that could be evaluated in the IF portion of a rule. If the expression is true, the commands immediately following are executed until an ELSE or ENDIF is encountered. If the expression is false and an ELSE is present, the commands following the ELSE will be executed. In either case, execution will continue with the line following the ENDIF. IF commands can be nested. Each IF must have a matching ENDIF, though. The following example, IF [X]>0 CLEAR [X] RULES 1-10 ELSE RULES 20-30 ENDIF will test if [X] is greater than 0. If it is, [X] will be cleared and rules 1 through 10 will be run. If [X] is less than or equal to 0, rules 2030 will be run.

J - COMMAND LANGUAGE

22

IF [NUMBER FOUND] = 10 GOTO END ENDIF commands..... :END commands.... will check if the variable [NUMBER FOUND] is equal to 10. If it is, the program will branch to the point :END.

J - COMMAND LANGUAGE

23

Command Language

Pause Until a Key is Pressed PAUSE

The PAUSE command in the command language will cause the program to display a dialog box and wait until the OK button is pressed. There is no message displayed. This is usually used for debugging a command file.

J - COMMAND LANGUAGE

24

Command Language

Recover Data Saved with a QUIT or SAVEDATA Command RECOVER [filename]


The RECOVER command restores the state of the run from data in a file created by QUIT or SAVEDATA. Syntax: RECOVER [filename] The optional filename is the name of the file to read the data from. If the file name is not present, the program will prompt the user for the name of the file to use. The following example, RECOVER PART1.DAT RULES 35-200 will recover the data in file PART1.DAT and then run rules 35-200.

J - COMMAND LANGUAGE

25

Command Language

Run a Report Generator Specification REPORT

The REPORT command calls and executes a report generator specification file. This is the same as the internal REPORT command and the REPORT command in the report generator itself. Syntax: REPORT <filename> The following example, RULES 1-200 REPORT FIRST.RPT would run the first 200 rules and then run the report specification file FIRST.RPT to produce a report to disk file or screen, depending on the contents of the report specification.

J - COMMAND LANGUAGE

26

Command Language

Display the Results of the Run RESULTS

The RESULTS command displays the standard EXSYS results screen with options for change and rerun, etc. The same format and options as the final results display is used. Note: The results of a command file run will not be displayed unless the RESULTS command is used. Syntax: RESULTS <options> Two options are available: /C:<loop point> This is the point to loop to if a change/rerun is selected. Since the command file will have used one or more RULES commands to run the knowledge base, the starting point for a change and rerun must be specified. The new data input for the change and rerun will be done by EXSYS; the user must supply only the starting point. The following example, ASK [X] :LOOP RULES [Y] /F/N RULES 1-100 RESULTS /C:LOOP will run the rules using two RULES commands and then display the results. If change and rerun is selected, the program will allow the user to modify the data and branch back to :LOOP. The /C should always be used unless the change and rerun option has been disabled.

J - COMMAND LANGUAGE

27

Command Language

Run the Rules or a Subset of the Rules RULES


The RULES command has many variations and is used to execute all or a subset of the rules in the knowledge base. Either forward or backward chaining can be used. The backward chaining can be limited to the same subset of rules or can be allowed to use all of the rules. Syntax: RULES RULES RULES RULES allowed). RULES RULES RULES RULES RULES RULES RULES RULES ALL # #-# "name" C C # C #-# C "text" Q Q # Q #-# Q "name" Run all rules. Run rule #. Run rules # through #. Run named rules (wild cards Run rules relevant to all choices. Run rules relevant to choice #. Run rules relevant to choices # - #. Run rules relevant to choices with "text" in them. Run rules relevant to all qualifiers. Run rules relevant to qualifier #. Run rules relevant to qualifiers # - #. Run rules relevant to qualifiers specified by name (wild cards Run rules relevant to all variables. Run rules relevant to variable #. Run rules relevant to variables # #.[name].

allowed). RULES V RULES V # RULES V #-#

The default mode is backward chaining using all rules for derivation of information.

Options:
/F /N causes forward chaining. suppresses all backward chaining (like the NOBACKWARD option). This should only be used with /F.
J - COMMAND LANGUAGE
28

/L

forces all backward chaining to derive needed information to be limited to the same subset of rules. If /L is not present, backward chaining can invoke rules outside of the specified subset. clears all data out before starting the run. This is equivalent to CLEAR CLEAR CLEAR CLEAR RULES R ALL C ALL V ALL Q ALL .....

/C

If /C is not used, existing data from SET, ASK or previous runs will remain and be used. Rules are "relevant" to a qualifier, variable or choice if the qualifier, variable or choice appears in the assignment portion of the THEN or ELSE part of the rule. The rules relevant to qualifier 3 would be all rules with qualifier 3 in the THEN or ELSE portion. The rules relevant to [X] would be all rules with conditions that start [X] IS GIVEN THE VALUE ..., but not necessarily rules that have [X] as part of an expression assigned to another variable. For example, suppose there are 100 rules: RULES ALL RULES ALL /F would run all rules in backward chaining mode. would run all rules in forward chaining mode.

RULES ALL /F /C would CLEAR all existing data and then run all rules in forward chaining mode. RULES 5 RULES 1-10 would run rule 5. would run rules 1 through 10 in backward chaining mode, with all rules used for backward chaining to derive information needed. would run rules 1 through 10 in backward chaining mode, with only rules 1-10 used for backward chaining to derive information needed.

RULES 1-10 /L

J - COMMAND LANGUAGE

29

RULES Q 1-3 /F /N would run those rules that have qualifiers 1, 2 or 3 in their THEN or ELSE parts in a forward, NOBACKWARD mode. RULES Q "A*" would run all rules relevant to qualifiers whose names start with A in a forward chaining mode, with ALL rules used for derivation of information needed. RULES Q "A*" /L would run all rules relevant to qualifiers whose names start with A in a forward chaining mode, with ONLY the same sub-set of rules used for derivation of information needed. RULES [X] /F would run all rules that derive a value for [X] in a forward chaining mode. RULES [X] /F /C would CLEAR all existing data and then run all rules that derive a value for [X] in a forward chaining mode. RULES C 3 would run all rules relevant to choice 3.

RULES C "blue" would run all rules relevant to the choice with the word "blue" in it.

J - COMMAND LANGUAGE

30

Command Language

Run an External Program RUN


The RUN command allows running an external program from the command file. Data can be passed to the program and optionally returned in RETURN.DAT to set variables, qualifiers and choices. The RUN command is the same as the run command in rules, with the addition of the /D option and lacking ( ). Syntax: RUN filename <parameters> <options> <parameters> optional data or variables to pass out to the external program. <options]>/D - causes the program to look for and read a RETURN.DAT file and to assign any data found to the appropriate variable, qualifier or choice. For information on the format of the RETURN.DAT file, see Chapter H on the internal command RUN() (This automatically invokes the equivalent of the internal command /M option). If the /D option is not used, the program will not look for or use a RETURN.DAT file, even if one is created by the external program. /C - passes parameters on the command line. /B - allows calling batch files of DOS commands. /# - passes # parameters on the command line and the rest in the PASS.DAT file. See Chapter H for more information on / options. The following example, RUN TEST [X] /C will run the external program TEST and pass it the value of [X] on the command line. No data will be returned. RUN TEST [X] /C /R will run the external program TEST and pass it the value of [X] on the command line. The program will receive data back in the file RETURN.DAT.

J - COMMAND LANGUAGE

31

Command Language

Save the Current System Data SAVEDATA

The SAVEDATA command saves the current state of the run in a file, just as if a QUIT command were executed. Syntax: SAVEDATA [filename] The optional filename is the name of the file to store the data in. If the file name is not present, the program will prompt the user for the name of a file. The following example, RULES 35-200 SAVEDATA PART1.DAT will run rules 35-200 and save the input provided in the file PART1.DAT.

J - COMMAND LANGUAGE

32

Command Language

Assign a Value to a Variable, Qualifier or Choice SET

The SET command is used to assign values to choices, variables and qualifiers at the start of or during a run. The SET command can be used anywhere in a command file, but it is usually used at the start to set starting values. Syntax: SET [var name] expression Assign the value of the expression to the named variable. SET V # expression Assign the value of the expression to the variable specified by number. SET Q # {list of values} Set the specified values of qualifier number #. SET Q "name" {list of values} Set the specified values of the name qualifier. SET C # expression Assign the value of the expression to the named choice. SET C "text" expression Assign the value of the expression to the choice specified by a unique text sub-string. Here are some examples: SET [X] 5 will assign the value 5 to variable [X] SET [X] ([Y]/2) will assign the value of one half [Y] to variable [X]. If the value of [Y] is not known, the program will invoke backward chaining to determine [Y] or ask the user. The variables in the expression must be valid EXSYS variables in the knowledge base.

J - COMMAND LANGUAGE

33

SET V 3 3.14159 will assign 3.14159 to variable number 3. SET Q 5 1,2 will set values 1 and 2 of qualifier number 5. If qualifier 5 was The color is 1. red 2. blue 3. green this SET command would set values 1 and 2 or "The color is red and blue." SET Q "COLOR" 1 will set value 1 of the qualifier named "COLOR." Using the same qualifier as above, the result would be setting "The color is red." SET C 7 1+2+3 will set the value of choice 7 to the expression 1+2+3 or 6. SET C "large" [X]+3 will set the value of the choice containing the sub-string "large" to the expression [X]+ 3. If the value of [X] were not known, it would be derived or asked.

J - COMMAND LANGUAGE

34

Command Language

Execute a Block of Rules While a Condition is True WHILE.....WEND


The WHILE command allows repeated execution of a block of commands controlled by a test expression whose value usually changes during the execution of the block of commands. Syntax: WHILE <expression> commands.... WEND <expression> can be any mathematical expression that can be tested, such as those used in the IF part of a rule. The WHILE command will continue until the first WEND command is encountered, at which point it will reevaluate the test expression. If the test expression is true, the block of commands will be executed again. If it is false, the program will continue with the first command after the WEND command. WHILE commands may be nested, but each will end on the first WEND encountered and each must have a matching WEND. Note: A WEND must be used for each WHILE. The following example, WHILE [X] > 0 RULES 1-100 CLEAR R 1-100 WEND will execute rules 1 through 100 until [X] is less than or equal to 0. A FOR command is not part of the EXSYS command language, but an equivalent structure can be created using the WHILE and SET commands. The following example (using the syntax of BASIC), FOR X=1 to 50 STEP 2 could be expressed SET [X] 1 WHILE [X] <= 50 commands.... SET [X] ([X]+2) WEND
J - COMMAND LANGUAGE
35

Chapter K Rule Compiler


The EXSYS Rule Compiler allows a text representation of expert system rules to be compiled to the internal EXSYS knowledge base representation. The files produced by the rule compiler can be run with the EXSYS Professional Runtime or Rule Editor. There are many very substantial advantages to using the EXSYS Rule Editor over a word processor for most expert system development; however there are certain cases where the word processor approach has definite advantages. The rule compiler is designed to be used when those cases arise. It is not intended to be a replacement for the EXSYS Rule Editor for most knowledge base development. Due to the nature of a compiler, certain syntactical information must be specified. The program has to be able to tell a qualifier from a formula, choice, etc. This is a disadvantage found in all rule compilers (The EXSYS Rule Editor "knows" the difference from the menu items selected). The extra syntactical notation has been kept to a minimum and the word processor representation of the rules looks as much like the standard representation as possible. The syntax information required does not make the rules difficult to read. The program can determine most syntactical information without assistance; however a few extra characters are required for qualifiers and choices. In addition, in special cases where the program might become confused, it is possible to specify exactly what an item is. The EXSYS Professional Rule Editor has an option to print the rules with the extra syntactical information needed for the rule compiler included. Such a file can be directly read back into the rule compiler. This option on the Professional Rule Editor plus the EXSYS Rule Compiler allows easy incorporation of word processor editing in the development cycle.

K - RULE COMPILER

K1: Getting Started


This section assumes that you are familiar with EXSYS terminology and rule structure. If you are new to EXSYS, read the sections of the manual on the EXSYS rule structure and terminology before you read this section. If you are new to EXSYS, you should not start by using the text input form of rules with the rule compiler. Instead, use the EXSYS Professional Rule Editor (EDITXSP.EXE). It will make learning to use EXSYS much easier and faster. The Rule Editor provides menu prompts for input and provides most of the internal structure automatically. The development of an expert system is much faster with the Rule Editor than with the rule compiler. The Rule Editor allows immediate testing of rules and rapid editing. The Rule Compiler requires loading the compiler, compiling, loading the runtime program, loading the rules, running the rules, determining what changes to make, loading a word processor, loading the text form of the rules, making the changes, saving the rules and then loading the compiler again. This is very time consuming compared to the Rule Editor. However, for some types of changes the word processor form is superior, and in some cases it is the only way to make certain types of modifications. The rule compiler is easiest to use with printouts from EXSYS which have the syntactical information added. Such systems can be modified with a text editor to perform changes that are difficult or impossible to do with the Rule Editor. For example:

1. Changing the order of qualifier values


Print out the rules using the EXSYS editor. In the Qualifier: command, find the qualifier that you wish to change the order of values in. Change the order of the values in the list. Compile with EXSYSRC. The qualifier values will now be in the new order.

2. Changing the order of Choices


Print out the rules using the EXSYS editor. In the Choice: command, change the order of the choices in the list. Compile with EXSYSRC. The choice values will now be in the new order.

K - RULE COMPILER

3. Changing the confidence system


This is a little more complicated, but it is not possible by any other means. Print out the rules with the EXSYS Editor. Using your text editor, search for "Probability" or "Confidence." In each place that a confidence is assigned, change it to a value appropriate to the new confidence system selected. Then change the PROBABILITY SYSTEM: command to the system desired and re-compile. If there are any values out of range, you will get an error message.

4. Moving an expert system to EXSYS from another shell


Make a printout of the rules in the other shell. Change the syntax to that required by the EXSYS Rule Compiler. Depending on how similar the other shell's syntax is to EXSYS, this may be easy or difficult.

5. Creating similar blocks of rules


In some systems, there are nearly identical blocks of rules that are repeated several times. By printing out the rules and using the text editor to make copies of the block of rules, you can then edit the copies as needed and re-compile. In some cases this may be faster than entering the rules with the Rule Editor.

6. Correcting a system that has been damaged


In rare cases, it is possible for an expert system to become damaged by some error. Because of the use of pointers in EXSYS, such damage sometimes can be difficult to correct. However, if the rules can be printed out, you can check the printout for possible errors and re-compile to produce an undamaged version of the program.

7. Building systems using a text editor


Despite the advantages in building systems using the Rule Editor, some people prefer to use a text editor. The Rule Compiler disk contains a file RULEFORM. This is a blank skeleton of the syntax of an expert system for the rule compiler. Make a copy of RULEFORM and use it to start editing. You can fill in the blanks for the lines with text appropriate to your system or delete the unnecessary lines. A summary of the syntax for most commands is in the file as comments. The file also contains a skeleton for a rule. Make copies of this as needed and fill in the conditions. With RULEFORM to remind you of the syntax, it should be relatively easy to build a set of rules.

K - RULE COMPILER

K2: Starting the Rule Compiler


In addition the developing rules in the Rule Editor, rules can be developed with a text editor and compiled with the Rule Compiler. The syntax for the rules in a GUI environment is the same as in the non-GUI environments. To run the rule compiler 1. Click on the Rule Compiler icon. 2. Select Open from the File menu. 3. Select the file to compile. The filename is the name of the file holding the text representation of the rules to be compiled. This file can have any extension except .RUL or .TXT. The compiler will produce the two EXSYS files with the same name but with .RUL and .TXT extensions. The files will be written to the same directory as <filename>. 4. Select the option for file output and error messages: a. Output file: The name displayed will have .TXT and .RUL extensions added to it for the resulting knowledge base. This name can be changed by editing the name field. b. If you wish to have the error messages written to a file, check the "Write errors to file" box. The default name for the file will be set to <knowledge base name>.CER. This name can be changed if you wish. c. The LIST ONLY mode is set. This requires that all qualifiers, variables and choices be defined prior to being used in the rules. If you wish to have the compiler generate the lists of qualifiers, etc. during the compile, set LIST ONLY off. 5. Click on COMPILE 6. A window will display the progress of the compile. If an error is encountered, the error and the section of code in which the error occurred will be displayed.

K - RULE COMPILER

K3: Editing the Text Files


Text representations of the expert system rules can be produced with a word processor or text editor. The word processor or text editor used must not add special control characters. This may require working in a "non-document" mode. To see if the word processor adds special characters, produce a file and display it on your monitor with TYPE <filename> If there are no unusual or extra characters, the word processor or text editor should work with the rule compiler.

K4: Producing Files That Can Be Compiled


The EXSYS Professional Rule Editor has an option that allows it to print the knowledge base to disk with the syntactical information needed by the compiler included. If you have an existing expert system that you wish to edit with a word processor, select the Print menu item from the File menu.

K - RULE COMPILER

Print to PRINTER Print to FILE filename Standard Output Format Rule Compiler Format C Code Replacement for Rules

Rules Qualifiers / Variables Cross Reference List Formulas OK

One Per Page Continuous

Cancel

Select Rule Compiler format and enter a filename for the output file. The file can have any name, but do not use a file with a .RUL or .TXT extension. The listing will include all of the qualifiers, variables, choices, etc. and will use the LIST ONLY command. If you add new qualifiers, variables or choices, they must be added to the starting lists or the LIST ONLY command (found on the first line of the listing) must be deleted. If the LIST ONLY command is deleted, the new item will automatically be added to the lists. If you print the rules to disk without specifying that they are for word processor editing, the syntactical information will not be added and the rules will not be able to be directly read back in with the rule compiler. To compile such a listing would require adding the syntactical information by hand.

K - RULE COMPILER

K5: Commands
The compiler has a number of reserved command words. These words have special meaning to the compiler only if they appear at the start of a line. In all cases, preceding spaces or tabs are ignored. These words should not be used in your rules since the compiler could misinterpret them. This should not be a problem since all reserved words 1. Must be the first text on the line; 2. End in a ":" , "=" or carriage return. For example, the word AUTHOR in your rules would not cause a problem since only AUTHOR: is a reserved word. Likewise AUTHOR: in the middle of a line would not be considered a reserved word. The meaning of the reserved command words will be discussed individually.

Reserved Command Words:


/* SUBJECT: AUTHOR: STARTING TEXT: ENDING TEXT: EXTERNAL PROGRAM: DISPLAY THRESHOLD: PROBABILITY SYSTEM: INITIAL CHOICE CONFIDENCE: DISPLAY RULES: DERIVATION: QUALIFIERS: VARIABLES: CHOICES: LIST ONLY RULE: IF: MAXIMUM QUALIFIER= MAXIMUM VARIABLE= MAXIMUM RULE= MAXIMUM CHOICE= MAXIMUM CONFIDENCE= MAXIMUM FORMULA=

K - RULE COMPILER

In addition to the above reserved words, there are other command words that have meanings when they follow one of the reserved words. These are discussed in the sections on the individual reserved command words. Note: In all commands, the EXSYS Rule Compiler is case insensitive and preceding spaces or tabs are ignored. Text that is part of a qualifier, variable, etc. can go over several lines. There is no end of string delimiter. The program will recognize when a new command has been reached.

K - RULE COMPILER

Rule Compiler Command

Allow Comments to be Added to a File COMMENTS: /*

In any line, text following a /* is treated as a comment and ignored. If the /* is part of a quoted string it will not be considered the start of a comment. Other text or commands on the line preceding the comment will be used. Any line can start with indenting spaces or tabs. For example: /* this is a comment QUALIFIERS: /* this is another comment

A note to C programmers: Unlike C, it is not necessary to have a closing */ and comments do not carry over to the next line.

K - RULE COMPILER

Rule Compiler Command

Define the Subject of the Expert System SUBJECT: <text>

The text following the SUBJECT: command is used as the title for the expert system. All expert systems must have a title. The Title is limited to 200 characters; however the lines will be merged together. The text can be over multiple lines. The text is considered ended when there is a blank line or a line which starts another command. If you wish to embed special characters in the text, you can use the @@### control code as part of the text., where the ### is replaced with the THREE digit ASCII code of the character you wish to use. For example, @@013 will insert a carriage return. See Section I15 on @@### replacement for more details. For example: SUBJECT: This is the title of the expert system or SUBJECT: This is a subject line that continues over three lines. EXSYS will consider this all part of the subject.

K - RULE COMPILER

10

Rule Compiler Command

Define the Author of the Expert System AUTHOR: <text>

The text following the AUTHOR: command is the name of the author of the expert system. All expert systems must have an author. The author text is limited to 100 characters. The text can be on multiple lines; however the lines will be merged together. The text is considered ended when there is a blank line or a line which starts another command. If you wish to embed special characters in the text, you can use the @@### control code as part of the text, where the ### is replaced with the THREE digit ASCII code of the character you wish to use. For example, @@013 will insert a carriage return. See Section I15 on @@### replacement for more details. For example: AUTHOR: Your name

K - RULE COMPILER

11

Rule Compiler Command

Define the Starting Text of the System STARTING TEXT: <text>

The text following the STARTING TEXT: command is used as the text to display at the start of the expert system. The starting text is optional. The text is limited to 1800 characters. The text can be on multiple lines; however the lines will be merged together. The text is considered ended when there is a blank line or a line which starts another command. If you wish to embed special characters in the text, you can use the @@### control code as part of the text, where the ### is replaced with the THREE digit ASCII code of the character you wish to use. For example, @@013 will insert a carriage return. See Section I15 on @@### replacement for more details. For example: STARTING TEXT: This is the text that will be displayed on the screen when the expert system is run.

K - RULE COMPILER

12

Rule Compiler Command

Define the Ending Text of the System ENDING TEXT: <text>

The text following the ENDING TEXT: command is used as the text to display at the end of the expert system. The ending text is optional. The text is limited to 1800 characters. The text can be on multiple lines; however the lines will be merged together. The text is considered ended when there is a blank line or a line which starts another command. If you wish to embed special characters in the text, you can use the @@### control code as part of the text, where the ### is replaced with the THREE digit ASCII code of the character you wish to use. For example, @@013 will insert a carriage return. See Section I15 on @@### replacement for more details. For example: ENDING TEXT: This is the text that will be displayed on the screen at the end of the expert system run.

K - RULE COMPILER

13

Rule Compiler Command

Define an External Program to Call at the Start of a Run EXTERNAL PROGRAM: <text>

The text following the EXTERNAL PROGRAM: command is used as the name of the external program to call at the start of an EXSYS run. The external program is optional. The text is limited to 100 characters. The text can be on multiple lines. The text is considered ended when there is a blank line or a line which starts another command. The name of the external program and any arguments passed out to it follow the standard EXSYS syntax for external programs. A RUN( ) is not needed since this is the external call at the start of the program. The following example, EXTERNAL PROGRAM: TEST [X] /C will call the external program TEST and pass it the value of variable [X] on the command line.

K - RULE COMPILER

14

Rule Compiler Command

Set the Threshold for Choice Display DISPLAY THRESHOLD: <value>

The value following the DISPLAY THRESHOLD: command is used as the threshold value for choice display at the end of the run. To be displayed, a choice must have a value greater than this value. The command is optional; however if it is not used, a default value of 0 will be used. The following example, DISPLAY THRESHOLD: 5 will cause only choices with a value greater than 5 to be displayed with the results of the run.

K - RULE COMPILER

15

Rule Compiler Command

Define the Confidence System to be Used PROBABILITY SYSTEM: <value>

The value following the PROBABILITY SYSTEM: command is used to set the probability confidence value system used in the expert system. The command is required and a confidence system must be specified before the rules are entered. The value must be an integer between 1 and 5. The values correspond to the confidence modes in EXSYS: 1. 2. 3. 4. 5. Yes / no system 0-10 system (O and 10 lock the values) -100 to +100 system Increment/ decrement system Custom formulas

See Chapters B and C on confidence systems for more information on the various confidence systems and their relative advantages. For mode 3, the number can be followed by a letter indicating how to combine confidence factors: A I D Average values Combine as Independent probabilities Combine as Dependent probabilities

Characters after the first letter are ignored. See Chapters B and C on confidence systems for more information on the method of combining confidence factors. If there is no letter following the "3," the default is to use "A" for the average mode.

K - RULE COMPILER

16

The following example, PROBABILITY SYSTEM: 2 will set the system in the 0-10 confidence mode. PROBABILITY SYSTEM: 3 I will use the -100 to +100 mode with probabilities combined as independent probabilities.

K - RULE COMPILER

17

Rule Compiler Command

Set the Initial Choice Confidence Value INITIAL CHOICE CONFIDENCE: <value>

This option applies only to confidence mode 5, custom formulas. In that mode, choices have an initial confidence value. The default value is 0; however in some cases, other values may be more desirable. The INITIAL CHOICE CONFIDENCE: command allows the default to be changed. The following example, INITIAL CHOICE CONFIDENCE: will set the starting confidence of all choices at 100. 100

K - RULE COMPILER

18

Rule Compiler Command

Set Option to Display Rules as a System Runs DISPLAY RULES: <value>

The value following the DISPLAY RULES: command is used to set whether or not rules will be displayed when the expert system is run. The command is optional; however if it is not used, a default value of "not displayed" will be used. The acceptable values are Y or YES, N or NO. The following example, DISPLAY RULES: YES will cause rules to be displayed during the run. The option to lock rule display off cannot be accessed from the rule compiler since the compiler does not provide for password encryption. To lock rule display off Compile the rules; Read the rules with the EXSYS Professional Rule Editor; Select parameters from the Options pull down menu; Select "Lock Display OFF" in the Rule Display Mode radio buttons and click on "OK; Select SAVE from the FILE pull down menu and select Password Protection.

K - RULE COMPILER

19

Rule Compiler Command

Set Option for How Many Rules to Use in Deriving Information DERIVATION: <value>

The value following DERIVATION: is used to set how many rules are used in the backward chaining to derive needed information. The value is a letter A F N all rules first rule only non-redundant rules

If there is no DERIVATION: command, the default mode is "A," use all rules. Characters after the first character are ignored. The following example, DERIVATION: F DERIVATION: First rule are both accepted and both mean use only the first rule that fires in backward chaining.

K - RULE COMPILER

20

Rule Compiler Command

Define List of Qualifiers and Parameters QUALIFIERS:

This command allows inputting of a list of qualifiers with values and setting of parameters. The qualifiers and their values usually should be defined prior to their being used in the rules. However, the QUALIFIER: statement is optional and the list does not have to be complete. Unless the LIST ONLY command is used, the compiler will build the qualifier list from the qualifiers and their values found in the rules. If the LIST ONLY command is used, any qualifiers or values found in the rules that do not match ones in the list will produce an error message. It is recommended that the LIST ONLY option be used with a complete qualifier list whenever possible to catch any typographical errors that can occur when using text editors. Each qualifier has a number of parameters that can be set. These parameters control actions such as if the qualifier is displayed with the results, the number of values a user can input, how confidence for the qualifier is handled, etc. All parameter commands apply to the qualifier set by Q> previously. Most parameter commands have shorter alternate commands that can be used. The shorter alternates have the same function as the full command. They are just quicker to type. Most parameters have default values that are automatically set when the new qualifier is found. These defaults can be changed with the various parameter commands. It is not necessary to add the parameter command if the default value is appropriate. Multiple qualifiers can follow a single QUALIFIER command. The QUALIFIER list is optional and all qualifiers can be determined from the rules.

Commands: Q> <text>


Indicates the start of a new qualifier. The text that follows the Q> will be used for the qualifier. The text can continue over several lines. The text will be applied to the qualifier until a blank line or another command is encountered. Parameter commands following the Q> command apply to that qualifier until the next Q>. (NO DEFAULT - required)
K - RULE COMPILER

21

V> <text>
Indicates the start of a new value. The text that follows the V> will be used for the value. The text can continue over several lines. The text will be applied to the value until a blank line or another command is encountered. Up to 30 values can be assigned to a particular qualifier. (NO DEFAULT- at least one value required)

ASK CONFIDENCE Alternate: ASK CONF


Sets parameter to have the user asked for a confidence value for his input when he is asked for data on the qualifier. This parameter command applies only to confidence mode system 5. The command is meaningless in other confidence systems. This parameter command has no associated value. If it is present, the user will be asked to supply a confidence value and if it is not present, the user will not be asked for confidence and the default confidence value will be used. (Default=not asked)

DEFAULT CONFIDENCE= <value> Alternate: DEF CONF


Sets the default confidence value to assign in place of asking for a confidence value. This parameter command applies only to confidence mode system 5. The command is meaningless in other confidence systems. If the ASK CONFIDENCE command is not used, the qualifier will be assigned an initial confidence value. The default value to use is 1. This parameter command allows the initial value to be changed. (For example, DEFAULT CONFIDENCE = 0 sets the initial confidence value to 0 for the qualifier.) (Default = 1)

MINIMUM CONFIDENCE = <value> Alternate: MIN CONF


Sets the minimum range of acceptable values of user input of a confidence value for the qualifier. This parameter command applies only to confidence mode system 5. The command is meaningless in other confidence systems. Used only with ASK CONFIDENCE. (For example, MINIMUM CONFIDENCE = -10 sets the lower bound for the user confidence value at -10.) (Default = 0)

K - RULE COMPILER

22

MAXIMUM CONFIDENCE = <value> Alternate: MAX CONF


Sets the maximum for the range of acceptable values of user input of a confidence value for the qualifier. This parameter command applies only to confidence mode system 5. The command is meaningless in other confidence systems. Used only with ASK CONFIDENCE. (For example, MAXIMUM CONFIDENCE = 10 sets the upper bound for user input of a confidence value at 10.) (Default = 100)

DISPLAY AT END Alternates: DISP END, DISPLAY, DISP


Sets the parameter for the qualifier to be displayed at the end with the results. This parameter command has no associated value. If it is present, the qualifier will be displayed and if it is not present, the qualifier will not be displayed. (Default = not displayed)

DEFAULT VALUE = <value> Alternate: DEF VAL


Sets the default value that would be used in place of asking the user to select a value. The default value is used only if values cannot be derived from other rules. If a value can be derived, it will take priority and the default will not be used. The default value for a qualifier is different from the initial value for a variable, which is always used. The default value is very useful for qualifiers that should not be asked of the user, or situations where a default is appropriate. Never use default values for qualifiers on which you want the user to provide input. The value is the number of the value to use as a default. If this command is not used, no default value is assigned and the user will be asked for input. (For example, DEFAULT VALUE = 2 causes the second value in the list to be used in place of asking the user. ) (Default = none - no default value used for the qualifier)

MAXIMUM ACCEPTABLE = <value> Alternates: MAX ACCEPT, MAXIMUM, MAX


Sets the maximum number of list values that the end user can select. This allows the developer to specify that only one value

K - RULE COMPILER

23

can be selected from the list. This is particularly useful in lists which have mutually exclusive values or Yes/No questions. The value is the maximum number of values that the end user can select. If this command is not used, the user can select all values. (For example, MAXIMUM ACCEPTABLE = 1 only allows the end user to select one value from the list). (Default = allow all values)

DISPLAY CONFIDENCE Alternate: DISP CONF


Sets a flag to have the confidence displayed with the qualifier. This parameter command applies only to confidence mode system 5. The command is meaningless in other confidence systems. If this command is present, the final confidence for the qualifier will be displayed with the qualifier in the final display screen. If the command is not present, the confidence will not be displayed. Usually, the qualifier will only have the confidence displayed if it is derived from other rules. (Default=not displayed)

NAME=<name>
Sets the name that is assigned to the qualifier. This name is used to refer to the qualifier in other rules, the command language, etc. By being able to refer to a qualifier by name, rather than by number, you do not have to be concerned about rearrangements of qualifiers that may change the numbering. (For example, NAME=ABCD assigns the name ABCD to the qualifier. (Default=blank)

K - RULE COMPILER

24

The following example, QUALIFIERS: Q> The color is V> red V> white V> blue NAME= color DISPLAY AT END DEFAULT VALUE= 2 /* start of the qualifier list /* qualifier 1

Q> The day is /* qualifier 2 V> Monday V> Tuesday V> Wednesday V> Thursday V> Friday V> Saturday V> Sunday NAME= Day of week MAXIMUM= 1 sets up a qualifier "The color is" with values red, white and blue. The qualifier has an associated name COLOR, and is set to be displayed at the end. The DEFAULT VALUE is set to WHITE, so the end user will never be asked this question; it would be assigned the value WHITE if it could not be derived.All other parameters for qualifier 1 will be set to their default values. The second qualifier is "The day is" with a list of days for values. The associated name is DAY OF WEEK and the end user can select only 1 value from the list.

K - RULE COMPILER

25

Rule Compiler Command

New Qualifiers or Values Found in the Rules


If during the compiling of the rules, the compiler finds a qualifier or qualifier value that is not in the list, there are several alternatives depending on the LIST ONLY and QUALIFIER: commands.

Both LIST ONLY and QUALIFIER: Commands Used


The new qualifier or value will be considered an error. An error message will be displayed and the new qualifier or value ignored. This is the default for rule listings produced from the EXSYS Professional Rule Editor which lists all qualifiers and values and uses the LIST ONLY command. This combination catches any typographical errors that may have occurred during editing with a text editor. It prevents the inadvertent creation of new qualifiers or values. No .RUL or .TXT files will be created.

QUALIFIER: Command Used Without LIST ONLY


The new qualifier or value will be added to the list, but a note will be displayed to the user saying an unrecognized qualifier or value was found and the text displayed. This allows the user to determine if there is a typographical error causing the new qualifier. This is best when the rules have been changed with a word processor, but the list of qualifiers and values has not been modified accordingly.

QUALIFIER: Command Not Used (no qualifier list)


The new qualifier or value will be added to the list and the user will not be notified. If this option is used, be very careful about typographical errors. A single character difference will cause the program to consider two qualifiers as different and to add the new one to the list. If rules are read without a qualifier list 1. Compile the rules with the rule compiler. 2. Read the compiled rules with the Rule Editor 3. Print a listing of the rules from the Rule Editor and examine the qualifier lists for incorrect qualifiers or values produced by typographical errors. NOTE: If a qualifier or value is found in the rules and added to the list, the parameters for the qualifier will be the default values listed above. To have something other than a default value, the qualifier must be in a QUALIFIER: command.
K - RULE COMPILER
26

Rule Compiler Command

Define List of Variables and Parameters VARIABLES:


This command allows the inputting of a list of variables and the setting of various parameters for those variables. The list of variables should be defined prior to being used in rules. Multiple variables can follow a single VARIABLE: command. Variables cannot be created from the rules because the prompt for the variables must be specified. At least the variable name, enclosed in [ ], and the prompt text must be listed prior to using a variable. The only exception is creating text only variables; this is discussed below. Each variable has a number of parameters that can be set. These parameters control actions such as if the variable is displayed with the results, how confidence for the variable is handled, etc. All parameter commands apply to the variable set previously. Most parameter commands have shorter alternate commands that can be used. The shorter alternates have the same function as the full command. They are just quicker to type. Most parameters have default values that are automatically set when the new variable is found. These defaults can be changed with the various parameter commands. It is not necessary to add the parameter command if the default value is appropriate.

Commands: [<var name>] <prompt text>


Defines a new variable. The text that follows the [ ] will be used as the prompt for the variable. The text for the prompt can continue over several lines. The text will be applied to the prompt until a blank line or another command is encountered. All variables, except text only variables, must be defined in the VARIABLE: command prior to their being used in the formulas. The associated prompt text can include RUN( ) commands or other EXSYS internal commands. Also, the text can be a ."text only" that can be flagged for display at the end of a run. (NO DEFAULT - required)

K - RULE COMPILER

27

ASK CONFIDENCE Alternate: ASK CONF


Sets parameter to have users asked for a confidence value for their input when they are asked for data on the variable. This parameter command applies only to confidence mode system 5. The command is meaningless in other confidence systems. This parameter command has no associated value. If it is present, users will be asked to supply a confidence value and if it is not present, users will not be asked for confidence and the default confidence value will be used. (Default=not asked)

DEFAULT CONFIDENCE = <value> Alternate: DEF CONF


Sets the default confidence value to use in place of asking for a confidence value. This parameter command applies only to confidence mode system 5. The command is meaningless in other confidence systems. If the ASK CONFIDENCE command is not used, the variable will be assigned an initial confidence value. The default value to use is 1. This parameter command allows the initial value to be changed. (For example, DEFAULT CONFIDENCE = 0 sets the initial confidence value to 0 for the variable.) (Default = 1)

MINIMUM CONFIDENCE = <value> Alternate: MINCONF


Sets the minimum for the range of acceptable values of user input of a confidence value for the variable. This parameter command applies only to confidence mode system 5. The command is meaningless in other confidence systems. Used only with ASK CONFIDENCE. (For example, MINIMUM CONFIDENCE = -10 sets the lower bound for the user confidence value at -10.) (Default = 0)

K - RULE COMPILER

28

MAXIMUM CONFIDENCE = <value> Alternate: MAX CONF


Sets the maximum for the range of acceptable values of user input of a confidence value for the variable. This parameter command applies only to confidence mode system 5. The command is meaningless in other confidence systems. Used only with ASK CONFIDENCE. (For example, MAXIMUM CONFIDENCE = 10 sets the upper bound for the user confidence value at 10.) (Default = 100)

DISPLAY AT END Alternates: DISP END, DISPLAY, DISP


Sets the parameter for the variable to be displayed at the end with the results. This parameter command has no associated value. If it is present, the variable will be displayed and if it is not present, the variable will not be displayed. (Default = not displayed)

TYPE = <value>
Sets the type of variable. The acceptable values are N for numeric, S for string, or T for text only. The default type for the variable is N (Numeric). Having the wrong type for a variable will produce an error message when the system is run. (For example, TYPE=S sets the variable type as string.) (Default = N)

INITIALIZE = <value> Alternates: INIT


Sets the initial value for a variable. This option assigns a value to the variable when the system starts. A variable that is given an INITIALIZE value will never be asked of the user. Typically, this is only used for counters. The default is to not have the variable initialized. (For example, INIT=0 sets the variable to be initialized to 0 at the start of a run.) (Default = not initialized)

K - RULE COMPILER

29

UPPER LIMIT = <value> Alternates: UPPER LIM, UPPER


Sets the upper limit for acceptable user input of a value for the variable. If the user inputs a value above this limit, it will be rejected and the question reasked. The default is to not have any limits on user input. (For example, UPPER LIMIT=100 sets the upper limit for end user input for the variable to 100.) (Default = no limits)

LOWER LIMIT = <value> Alternates: LOWER LIM, LOWER


Sets the lower limit for acceptable user input of a value for the variable. If the user inputs a value below this limit, it will be rejected and the question reasked. The default is to not have any limits on user input. (For example, LOWER LIMIT=0 sets the lower limit for end user input for the variable to 0.) (Default = no limits)

DISPLAY CONFIDENCE Alternate: DISP CONF


Sets a flag to have the confidence displayed with the variable. This parameter command applies only to confidence mode system 5. The command is meaningless in other confidence systems. If this command is present, the final confidence for the variable will be displayed with the variable in the final display screen. If the command is not present, the confidence will not be displayed. Usually, the variable will only have the confidence displayed if it is derived from other rules. (Default=not displayed)

K - RULE COMPILER

30

The following example, VARIABLES: /* start of variable list

[LENGTH] The length of the beam as measured in feet from the base to the top DISPLAY UPPER LIMIT = 1000 LOWER LIMIT = 0 [ERROR MSG] WARNING The materials may be unsuitable for the project planned DISPLAY TYPE = T [X] RUN(GETLTH) The length of .... /* next variable sets up a variable [LENGTH] with associated prompt "The length of ... ." The variable is set to be displayed at the end and the end user can only input values between 0 and 1000. All other parameters will be set to their default values. The second variable is a text note to the user. It is marked as a "text only" variable. The third variable is [X] with an associated prompt that includes a RUN( ) command.
Rule Compiler Command

Text Only Variables Found in the Rules


In the RULE: section, it is possible to use a Text Only variable without having pre-defined it. If the condition in the rules section starts with T>, the text following will be considered the text associated with a text only variable. If a "text only" variable with this text has been pre-defined, it will be used. However, if there is no matching variable, a new variable will be created, named TEXTVAR#, where # is a unique number, and the text will be assigned to it. The defaults set for the variable will be TYPE=T, DISPLAY AT END. If the identical text is used in subsequent rules, this same variable will also be used. The use of the T> command is discussed in greater detail in the RULES: command section.

K - RULE COMPILER

31

Rule Compiler Command

Define List of Choices CHOICES:

This command allows input of a list of choices the goals the system will try to derive values for. The choices usually should be defined prior to their being used in the rules. However, the CHOICES: statement is optional and the list does not have to be complete. Unless the LIST ONLY command is used, the compiler will build the choice list from the choices found in the rules. If the LIST ONLY command is used, any choices found in the rules that do not match ones in the list will produce an error message. It is recommended that the LIST ONLY option be used with a complete choice list whenever possible to catch any typographical error that can occur when using text editors. Multiple choices can follow a single CHOICE: command. The choice command is optional. The choices can be selected from the rules. Commands:

C> <text>
indicates the start of a new choice. The text that follows the C> will be used for the qualifier. The text can continue over several lines. The text will be applied to the choice until a blank line, another C> or another command is encountered. The following example, CHOICES: /* start of choice list

C> Choice 1 C> Choice 2 C> This is the text for choice number 3, it goes over two lines. C> Choice 4 sets up 4 choices with the text indicated.

K - RULE COMPILER

32

Rule Compiler Command

Use Only Defined Qualifiers, Variables and Choices LIST ONLY

This command causes the rule compiler to use ONLY the qualifiers, variables and choices from the list specified with the QUALIFIER:, VARIABLE: and CHOICE: commands. If a qualifier, variable or choice is found in the rules that does not match one of the predefined values, an error message will be displayed. Even if this command is not used, the program will display a message notifying the user when a new qualifier, variable or choice is created if there was a starting list of acceptable items. LIST ONLY prevents the new item from being added to the list and causes the program to issue an error message.

K - RULE COMPILER

33

Rule Compiler Command

Define a Rule RULE: IF:

The RULE: command or the IF: command indicates the start of a new rule. There can be an optional name for the rule following the RULE: or IF:. The RULE: command is optional, but the IF: command must be used in each rule. The RULE: and IF: commands indicate the start of a rule which has the following structure: RULE: <optional name> /* this line is optional IF: <optional name> if_condition 1 AND: if_condition 2 AND: if_condition 3 AND: ..... THEN: AND: AND: AND: ELSE: AND: AND: AND: else_condition 1 else_condition 2 else_condition 3 ..... then_condition 1 then_condition 2 then_condition 3 .....

NOTE: < note text> REFERENCE: <reference text> The RULE:, NOTE: and REFERENCE: parts are optional. The IF: and at least either a THEN: or ELSE: part are required. It is not necessary to specify a rule name or number. Each condition in the rule, except the first condition in the IF, THEN and ELSE parts, must start with AND: or and:. Spacing and indenting is optional and the compiler will ignore it. The text of individual conditions can carry over multiple lines.

K - RULE COMPILER

34

The conditions that the program uses to build the IF, THEN and ELSE parts are the same as those created in the EXSYS Professional Rule Editor, but in some cases extra syntactical information must be added so that the compiler can tell if the condition is a qualifier, formula or choice. The conditions can wrap over several lines. All lines not starting with AND: or other command word are taken as part of the same condition. There are syntactical notations required in conditions. These have been kept to a minimum to have the rules for the compiler look as much as possible like the rules displayed in EXSYS. 1. Qualifiers with one or more values, must have each value enclosed in { }. 2. A Choice condition must start with >. 3. Text to be assigned to a text only variable must start with T> or ". 4. An EXSYS internal command not assigned to a text only variable (created with the <X> command in EXSYS) must start with X>.

K - RULE COMPILER

35

Rule Compiler Command

Qualifier Conditions in Rules


qualifier [NOT] {value} [or][and] [{value}] [more qualifier text]
Items in [ ] are optional. Items underlined can be repeated multiple times. Items in bold face are the minimum required. In a condition built by using a qualifier and one or more values, EACH of the values used must be in { }. Each time a value is used, it must be enclosed in { }. It is not necessary to mark the "NOT" if the qualifier has already been defined. The program will recognize that the qualifier is one it knows with a "NOT" added and treat it accordingly. If multiple values are used, an optional "OR" or "AND" can be put between values. The "OR" or "AND" is ignored by the program and is optional. In the IF parts, multiple values are ORed and in the THEN or ELSE part the values are ANDed. For example, if we have a qualifier THE COLOR IS with values RED, WHITE and BLUE, we could create conditions such as: THE COLOR IS{RED} THE COLOR IS NOT {BLUE} THE COLOR IS {RED} OR {BLUE} If there is qualifier text following the last value in { }, it will be considered a qualifier using the form that inserts the value text in the middle of the qualifier text. See Section I14 on using qualifiers with values replaced in the middle of the text. For example, the condition THE {HOUSE} IS RED would produce a qualifier THE ____ IS RED with associated value HOUSE. If, during the compiling of the rules, the compiler finds a qualifier or qualifier value that is not in the current qualifier list, there are several alternatives depending on the LIST ONLY and QUALIFIER: commands.
K - RULE COMPILER
36

Both LIST ONLY and QUALIFIER: Commands Used


The new qualifier or value will be considered an error. An error message will be displayed and the new qualifier or value ignored. No .RUL or .TXT files will be created.

QUALIFIER: Command Used Without LIST ONLY:


The new qualifier or value will be added to the list, but a note will be displayed to the user saying an unrecognized qualifier or value was found and the text displayed. This allows the user to determine if there is a typographical error causing the new qualifier. This is best when the rules have been changed with a word processor, but the list of qualifiers and values has not been modified accordingly.

QUALIFIER: Command Not Used (NO qualifier list):


The new qualifier or value will be added to the list and the user will not be notified. If this option is taken, be very careful about typographical errors. A single character difference will cause the program to consider two qualifiers or values different and to add the new one to the list. If rules are read without a qualifier list 1. Compile the rules with the rule compiler. 2. Read the compiled rules with the Rule Editor. 3. Print a listing of the rules from the Rule Editor and examine the qualifier lists for incorrect qualifiers or values produced by typographical errors. Note: If a qualifier or value is found in the rules and added to the list, the parameters for the qualifier will be the default values listed above. To have something other than a default value, the qualifier must be in a QUALIFIER: command.

K - RULE COMPILER

37

Rule Compiler Command

Choice Conditions in Rules


Confidence system 1-4: IF: > choice [:] [-] Probability <test> <value> THEN/ELSE: > choice [:] [-] Probability [=] <value> Confidence system 5, custom confidence formulas: IF: > choice [:] [-] Probability <test> <expression> THEN/ELSE: > choice [:] [-] Probability [=] <expression> Items in [ ] are optional. Items in bold face are the minimum required. 1. In conditions using choices, the statement of the choice must be preceded with a >. Note: The > is not part of the choice text. It is a flag to indicate that the text which follows is a choice. 2. There can be an optional : or - following the choice. These are added only for cosmetic purposes and consistency with the form used in the Rule Editor. 3. The word PROBABILITY has alternate words that can be used: CONFIDENCE CONF. CONF: PROB. PROB: There is no distinction made between "Probability" and "Confidence" and their alternative shorter forms. 4. In the THEN or ELSE part of a rule, an optional = can follow "Probability." This is added only for cosmetic purposes and consistency with the form used in the EXSYS Rule Editor.

K - RULE COMPILER

38

<test> : In the IF part of a rule, a conditional test must follow


"Probability." The acceptable tests are: > greater than < less than <= less than or equal >= greater than or equal = equal <> not equal >< not equal The test is applied between the final derived value of the choice and the value or expression that follows.

<value> : In confidence modes 1-4, the last item in the choice


condition is a value. The value must be within the appropriate range for the confidence system being used: Conf. mode 1 2 3 4 Type Acceptable values yes/no 0 or 1 0-10 0 to 10 (integers) -100 to 100 -100 to 100 (integers) inc/dec IF part: -10,000 to 10,000 THEN/ELSE part: -100 to 100

<expression> : In confidence mode 5, expressions are used in


place of simple values. The expressions can contain variables, confidence variables, etc. See Section C40 on custom confidence formulas for information on this confidence system. For example: IF: > Choice 2: Prob.< 4 THEN: > Choice 1: Probability = 7 The starting > indicates the condition is a choice. If the probability of "Choice 2" is less than 4, then "Choice 1" will be given the value 7. In confidence mode 5, we could have IF: > Choice 2: Prob.< [X]/5 THEN: > Choice 1: Probability = [%Q 1] + 10 If the program finds choices not in its choice list, the choice will be added to the list. If the LIST ONLY option was selected, unrecognized choices will produce an error message. If the CHOICE: command was used, unrecognized choices will produce a note to the user.

K - RULE COMPILER

39

Rule Compiler Command

Formula Conditions in Rules


IF part: <expression> <test> <expression> THEN/ELSE part: <variable> IS GIVEN THE VALUE <expression> or <variable> := <expression>

<expression> : An expression can be any combination of variables,


constants or functions that can be evaluated to a single value. As usual in EXSYS, variables are indicated by text in [ ]. The expression can also use string constants or variables combined with the + operator for concatenation. Do not mix string and numeric items in an expression or you will get an error message when the rules are run.

<test> : The test is a comparison of two values. The acceptable tests


are > < <= >= = <> >< greater than less than less than or equal greater than or equal equal not equal not equal

<variable> : An EXSYS variable name in [ ]. The variable must


have been defined in a VARIABLE: command prior to being used. The phrase IS GIVEN THE VALUE is used to indicate assignment of value in THEN or ELSE parts. It can be shortened to IS GIVEN or := to indicate assignment of value.

K - RULE COMPILER

40

Formulas Starting with "


For normal expressions, there is no change from the standard EXSYS Rule Editor syntax. However, if a formula condition in the IF part involves string variables and starts with a ", the compiler will think it is a "text only" string and will not recognize it as a formula. To force the condition to be taken as a formula, precede it with M>. This will take precedence over the normal syntactical checks for expressions. The "M>" can be used with all formulas, but is only necessary with string expressions starting with ". The following example, IF: "abc"+[Y] <> [X] would not be interpreted correctly, while IF: M> "abc"+[Y] <> [X] would be treated as a string formula and evaluated.

K - RULE COMPILER

41

Rule Compiler Command

Text Conditions in Rules


For text only variables: T> text or "text" or [text only variable name] For commands:

X> command
There are two types of text conditions in rules. The most general is the text associated with a text only variable. This is text which will be displayed at the end of a run if a rule with the text in it fires during the run. Such text has an associated variable name. The EXSYS Rule Compiler can accept either the name of the text variable, if it has been pre-defined, or just the text starting with a T> or ". If the compiler finds text starting with T> or ", it will check to see if the text matches any existing text only variable. If there is a match, that variable will be used. If there is no match, the compiler will create a new variable named TEXTVAR#, where # will be a number, and assign it the text. The variable will be of type "text only" and set for display at the end of a run. A second type of text applies only to EXSYS. It is used only for the text of an EXSYS internal command. In EXSYS it is not necessary to have an associated variable with a command. Such text is indicated by preceding it with X> and then the command. See Chapters C and G on the <X> command for more information on internal commands. The allowable EXSYS commands are STOP end run RESTART start over DISPLAY(...) display file REPORT(...) run a report CLEAR(...) clear out data or rules DB_...(...) interface to dBase III files RUN(...) run an external program The X> form does not create an associated EXSYS variable and it is not downwardly compatible to standard EXSYS. If you use the X> form you will not be able to save data in the standard EXSYS format. For compatibility with standard EXSYS, you can use the T> form for commands in place of the X> form. This will associate a variable with the text. Unless the variable is predefined, it will be set for display at the end of the run.

K - RULE COMPILER

42

Text only variables can only be used in the THEN or ELSE part of a rule. To execute RUN( ) commands in the if part, include the RUN(..) as the first part of the qualifier or variable text without a T> or X>. For example: IF: RUN(GETCOLOR) The color is {red} THEN: T> this is a note that the color selected was red X> RUN(TEST2 [Y] /C) The IF condition has a RUN( ) command as part of the qualifier. This is not a text variable. The RUN( ) will cause the external program GETCOLOR to be run if the qualifier is needed. The returned value from GETCOLOR will set the value of the qualifier. The first THEN condition is a text only string which will be associated with a variable. It will cause the note to be displayed at the end of the run if the rule fires. The second THEN condition, with the X>, will cause the external program TEST2 to be run and passed the value of [X]. This will not be associated with a text variable since it uses the X> form rather than the T> form.

K - RULE COMPILER

43

Rule Compiler Command

NOTE and REFERENCE Text NOTE: <text> REFERENCE: <text>


A rule can have an optional note or reference associated with it. This is text that will be displayed with the rule (NOTE) or if requested (REFERENCE). The text can be up to 1000 characters and can go over several lines. The lines will be concatenated to make the final note or reference. The Note and Reference are optional.

K - RULE COMPILER

44

Rule Compiler Command

Special Cases
The EXSYS Rule Compiler can determine the type of almost all conditions by the following rules: (these rules are in order of precedence)

Qualifiers: Any condition with a { } in it is a qualifier and


the text in { } is a value.

Formulas: Any condition using variables in [ ], except [[ ]]


replacement expressions (see Section I16 on [[ ]] replacement), is considered a formula for testing in the IF part or assignment in the THEN or ELSE part.

Choices: Any condition starting with > is considered a


choice.

Text: Any condition that starts with " , T> or X> is


considered a text string or an EXSYS internal command. This system works correctly for almost all EXSYS expert system rules, and adds the minimum of extra syntax. For example: RULE: color IF: AND: AND: THEN: AND: AND: The item is {A} and {B} [Y] IS GIVEN THE VALUE [X]/2 > The item is identified: PROBABILITY=9 Note: This is the note for the rule Despite minimal syntax information, the EXSYS rule compiler will be able to correctly parse the above rule. The color is {red} or {blue} > Choice 1: PROB.>5 [X] > 10

K - RULE COMPILER

45

However, in some cases it is possible to confuse the compiler. A formula that did not use variables, a formula using string expressions that started with a " or a qualifier that started with '>' might be misinterpreted. These are rare exceptions, but if a statement is being misinterpretwhich should produce an error message - you can override the normal parsing strategy. Starting a condition with Q> or M> forces the program to consider it to be a qualifier or Math/formula respectively regardless of other syntactical indications. The following example, M>"abc" <> [x] Q> > The ... >, will be considered a formula even through it starts with a ". will be considered a qualifier even though the actual text starts with a indicating a choice.

The Q> and M> should be very rarely needed. Their function is only to allow an override of the normal parsing in exceptional situations.

K - RULE COMPILER

46

Rule Compiler Command

Set Space Allocated for Compile


MAXIMUM QUALIFIER = <value> MAXIMUM VARIABLE = <value> MAXIMUM RULE =<value> MAXIMUM CHOICE =<value> MAXIMUM CONFIDENCE =<value> MAXIMUM FORMULA =<value> When the rule compiler reads in the rules, it allows a certain amount of space for the items being read in. Since EXSYS is very compact and efficient, the arrays that are created can handle almost all systems. If the program runs out of space, it will reconfigure the arrays and try again; however this takes additional time. There are two times when it is desirable to change the default setting for the arrays. The first is if the program is being run in a computer with very limited memory and there is not enough room for the large arrays. The second is if the expert system is very large and changing the defaults will speed the compiling process since the program will not have to make two passes. The default values are: Maximum number of qualifiers: 500 Maximum number of variables: 500 Maximum number of choices: 250 Maximum number of rules: 2000 Maximum number of formulas: 1000 Maximum number of confidence formulas: 1000 This is more than enough for most systems. To change the defaults up or down, use the appropriate MAXIMUM command. These commands must appear at the start of the text representation of the ruleswithin the first 20 lines. The MAXIMUM commands are optional and it is unlikely that you will need to use them. Note: It is not necessary to have the exact count of the rules, qualifiers, etc. The number need only be larger than what is needed. The program will tell you and attempt to correct itself if the number is too small or if you run out of memory. The following example, MAXIMUM RULES = 1000 MAXIMUM VARIABLES = 2000 will allow space for 1000 rules and 2000 variables.
K - RULE COMPILER
47

K6: Error Messages


The rule compiler can detect many error conditions and will produce error messages stating what line number the error is in, explain what the error is and then display the line with the error. Since one error can result in the compiler misinterpreting following lines, a single error may result in many error messages. Always correct the first error in the list first. When an error is detected, the program displays the line number of the error and the text. In some cases the error may not be at that exact line, but should be close by. This is especially true with text that wraps over multiple lines. ERROR 1: The EXSYS files created would overwrite this file The filename specified ended in .RUL or .TXT. The Rule Compiler needs to create files with these extensions. To prevent accidentally overwriting the text file, the program will not allow files with .RUL or .TXT to be used, even with the OUT= option. Rename the text file and try again. ERROR 2: File not found The program could not find the specified text file. ERROR 3: Incorrect placement of THEN A THEN: command was found that was not preceded by an IF:. ERROR 4: Incorrect placement of ELSE An ELSE: command was found that was not preceded by an IF:. ERROR 5: Incorrect placement of NOTE A NOTE: command was found that was not preceded by a rule. ERROR 6: Incorrect placement of REFERENCE A REFERENCE: command was found that was not preceded by a rule. ERROR 7: Unrecognized text Text was found in the rule that was not identifiable. Check syntax. ERROR 8: No qualifier specified An attempt was made to set a parameter for a qualifier before the qualifier had been specified. All qualifier parameters apply to the qualifier that immediately precedes them. ERROR 9: No = sign The parameter specified requires an = followed by a value.

K - RULE COMPILER

48

ERROR 10: Qualifier text too long A qualifier is limited to 1000 characters. Check for syntax errors such as no "AND: " causing subsequent conditions to be misinterpreted as part of the same qualifier. ERROR 11: Identical qualifier already exists Two qualifiers in the QUALIFIER: list have identical text. ERROR 12: No space for qualifiers The space reserved for qualifiers has been used up. The compiler will attempt to correct for this, but if it is unsuccessful, use the MAXIMUM QUALIFIER command to increase space. ERROR 13: Qualifier value text too long A qualifier value is limited to 500 characters. Check for syntax errors such as no "AND: " or no closing } causing subsequent conditions to be misinterpreted as part of the same value. ERROR 14: Unknown parameter Text was found that could not be identified. ERROR 15: No variable specified An attempt was made to set a parameter for a variable before the variable had been specified. All variable parameters apply to the variable that immediately precedes them. ERROR 16: Not legal TYPE The type command must be followed by an N, S or T. ERROR 17: No space for variables The space preserved for variables has been used up. The compiler will attempt to correct for this, but if it is unsuccessful, increase the MAXIMUM VARIABLES parameter. ERROR 18: No closing ] The variable specified did not have a closing ]. ERROR 19: Identical variable already exists Two variables in the VARIABLE: list have identical names. ERROR 20: No prompt following variable name The prompt text for the variable must follow the name. ERROR 21: Variable prompt text too long A variable prompt is limited to 500 characters. Check for syntax errors causing subsequent text to be misinterpreted as part of the prompt.

K - RULE COMPILER

49

ERROR 22: No space for choices The space reserved for choices has been used up. The compiler will attempt to correct for this, but if it is unsuccessful, use the MAXIMUM CHOICES command to increase space. ERROR 23: Choice text too long A choice is limited to 500 characters. Check for syntax errors causing subsequent text to be misinterpreted as part of the choice. ERROR 24: Subject text too long A subject is limited to 500 characters. Check for syntax errors causing subsequent text to be misinterpreted as part of the subject. ERROR 25: No subject An expert system must have a subject line. ERROR 26: Author text too long A choice is limited to 100 characters. Check for syntax errors causing subsequent text to be misinterpreted as part of the author. ERROR 27: No author An expert system must have an author line. ERROR 28: Starting text too long Starting text is limited to 1800 characters. Check for syntax errors causing subsequent text to be misinterpreted as part of the text. ERROR 29: Ending text too long Ending text is limited to 1800 characters. Check for syntax errors causing subsequent text to be misinterpreted as part of the text. ERROR 30: External program text too long The initial external program call is limited to 100 characters. Check for syntax errors causing subsequent text to be misinterpreted as part of the text. ERROR 31: Illegal probability mode The probability mode value must be an integer between 1 and 5. ERROR 32: Value not recognized Allowable values are Y, YES, N or NO. ERROR 33: Note text too long Note text is limited to 1000 characters. Check for syntax errors causing subsequent text to be misinterpreted as part of the text. ERROR 34: Reference text too long Reference text is limited to 1000 characters. Check for syntax errors causing subsequent text to be misinterpreted as part of the text.

K - RULE COMPILER

50

ERROR 35: Unrecognized text in rule Text in the rule could not be identified. Check for typographical errors in AND:, THEN:, ELSE:, NOTE: or REFERENCE: commands. ERROR 36: Not enough memory The program was not able to allocate enough memory. If there are "ram disks" or memory resident programs running, delete them. If that does not correct the problem, try setting the MAXIMUM parameters to lower values (or if they are not set, use them to set values lower than the default values). ERROR 37: Condition text too long An individual condition is limited to 1000 characters. Check for syntax errors causing subsequent text to be misinterpreted as part of the text. ERROR 38: Unidentifiable condition in rule The text could not be identified as either a qualifier, formula, choice or text condition. Check for syntax errors such as missing T> or no { } in a qualifier condition. ERROR 39: { not found with qualifier A condition was forced to be considered a qualifier with Q> but it does not contain any values in { }. ERROR 40: No closing } A value in a condition has a { without a matching }. ERROR 41: More than 127 conditions A rule can have a maximum of 127 conditions in the IF, THEN or ELSE part. ERROR 42: Qualifier not in list The LIST ONLY option was used with a QUALIFIER: list. A qualifier was found that did not match any in the list. If the qualifier is correct, add it to the list or remove the LIST ONLY command in the file. ERROR 43: Qualifier value not in list The LIST ONLY option was used with a QUALIFIER: list. A qualifier value was found that did not match any in the list. If the qualifier value is correct, add it to the list or remove the LIST ONLY command in the file. ERROR 44: Value list full A qualifier can only have 30 values in its list. There was an attempt to add more than 30 values.

K - RULE COMPILER

51

ERROR 45: No variable specified for assignment A formula in the THEN or ELSE portion must start with a variable to assign a value to, such as [X] IS GIVEN THE VALUE 5. ERROR 46: No closing ] in variable name A variable in the formula had a [ without a matching ]. ERROR 47: Incorrect assignment statement A formula in the THEN or ELSE part must have an assignment of a value such as "IS GIVEN THE VALUE", "IS GIVEN" or ":=". Check syntax. ERROR 48: Syntax error in Choice condition There is a syntactical problem with the choice. ERROR 49: Choice not in list The LIST ONLY option was used with a CHOICE: list. A choice was found that did not match any in the list. If the choice is correct, add it to the list or remove the LIST ONLY command in the file. ERROR 50: No test condition in Choice condition A Choice condition in the IF part of a rule must have a test condition. ERROR 51: Choice value out of range The value specified for the choice is not in the range allowed for the confidence system chosen. ERROR 52: Confidence can only be used in probability mode 5 A [%...] confidence variable was used in other than confidence mode 5. ERROR 53: Illegal confidence variable A [%...] confidence variable had an incorrect name. Check referenced variable. ERROR 54: Confidence variable not found The variable specified in [%...] could not be found. ERROR 55: Variable not found A variable was referenced in the rules that was not in the list. The variable cannot be automatically added to the rules since it does not have an associated prompt text. Add the variable and its associated prompt to the list of variables. ERROR 56: Not an internal command The command specified in the X> command is not a recognized EXSYS internal command.

K - RULE COMPILER

52

ERROR 57: Text conditions cannot be used in the IF part Text conditions can only be used in the THEN or ELSE part of rules. To add RUN( ) commands in the IF part make them the first part of the text of a qualifier or variable text. ERROR 58: Out of disk space The program ran out of disk space trying to write out the rule files. ERROR 59: Saving in standard EXSYS format impossible Features unique to EXSYS Professional were used. Rules cannot be saved in standard EXSYS form. ERROR 60: Saving in standard EXSYS format will result in loss of some data Features unique to EXSYS were used. Rules can be saved in standard EXSYS form but some parameter data will be lost.

K - RULE COMPILER

53

Chapter L Frame and Table Interface L1: TABLE and NTABLE


The functions TABLE and NTABLE perform a table look-up in a two column ASCII file. Wild card search is allowed. The syntax of the two commands is identical. TABLE will return a string value that can be used in string expressions. NTABLE will return a numeric value that can be used in numeric expressions. Syntax: (N)TABLE("filename" "search string") (N)TABLE(string_exp string_exp) In the second form, the string expressions will be evaluated. The first expression is the name of the file that has the tabular data and the second is the string to search for. The search string can contain '?' and '*' wild cards. A '?' matches any single character. A '*' matches the rest of the string, regardless of length. The match is not case sensitive.

L1.1: Data Table Syntax


The table of data must be an ASCII file with two columns. There can be starting spaces or tabs and any number of spaces or tabs between the columns. The first column is defined to end at the first space or tab after data. Headings can be used and will be ignored unless the search string matches the heading. For example, the following would be legal lines in a table: A56TR4 Mary 3 45.32 555-5555 copper pipe

Note: It is legal to mix various types of data in a single table, as long as the search string defines an individual item. However, for speed of access and maintenance, it is usually better to maintain separate tables for each type of data.
L - FRAME / TABLE
1

The search string is compared to the first column entry. For TABLE, a match will return the rest of the line, minus starting spaces or tabs. For NTABLE, a match will return a numeric value of the rest of the line. Note: For NTABLE, the second column must be numeric data. In the examples above, assume the data is in a file "DATA.DAT": Function: Returns: TABLE("DATA.DAT" "A56TR4") 45.32 as a string NTABLE("DATA.DAT" "A56TR4") 45.32 as a numeric TABLE("DATA.DAT" "MA*") 555-5555 as a string NTABLE("DATA.DAT" "MA*") 555 as a numeric (rest lost) TABLE("DATA.DAT" "3") "copper pipe" as a string It is possible to use tables as a type of array. A series of tables can be accessed by their index to put parameters in a rule. For example: IF [PRICE] > TABLE("price.dat" [S]) and: [AMOUNT] > TABLE("amount.dat" [S]) By simply changing the value of the string variable [S], the values in the rule can be changed. It is also possible to use a numeric variable as the index by using [[ ]] replacement. For example: IF [PRICE] > TABLE("price.dat" "[[N]]") and: [AMOUNT] > TABLE("amount.dat" "[[N]]") The [[N]] will be replaced by the value of the numeric variable [N]. The quotation marks around it are necessary to make it a string in the TABLE function. The table referenced would have the sequential numbers in the first column and the data in the second column, such as 1 2 3 123.45 65.32 96.29

By indexing the value of [N] (either in the rules or the command language), the TABLE value will be replaced by successive table entries.

L - FRAME / TABLE

L2: Frame
FRAME provides a way to handle more complex data than can be handled with TABLE. The TABLE commands are basically limited to simple 2 column look-ups. FRAME allows multiple columns and much more complex search criteria with Boolean operators. FRAME also allows the data table to updated by the rules. Frame also provides inheritance which allows a hierarchical set of frames to be created with data in "parent" frames available to lower level frames.

Syntax:
To read from a frame:
FRAME("filename", test_expression, slot_reference)

To write to a frame:
FRAME("filename", test_expr, slot_ref :=expression)

Filename: Test_expr: Slot_ref:

The name of the FRAME data file. The filename must be in " ". The Boolean expression used to find the desired line in the frame. The desired column in the frame. FRAME looks in the file for a frame which matches the test expression and either writes or reads the slot referenced. This reference must be in $ or # to indicate if it to be handled as a string or numeric. The data to be written into the slot_reference.

Expression:

L2.1: What is a Frame


Frames are another way of storing data. Frames are both similar and different from databases. The format of storing the data is similar. The process of storing and retrieving the data is different.

L - FRAME / TABLE

L2.2: Specifying a Slot


A frame is a collection or grouping of simple data. The simple data can be numbers and/or strings.
Name Mike Address 100 Memory Lane Telephone (299) 458-9827

A frame is similar to a database record (or structure). A frame has slots which hold the data. These are similar to fields. If you have a group of frames with the same format, you can make one frame out of it.
Name Mike Dan Jill Bill Joe Peg Address 100 Memory Lane 201 Penny Lane 832 Jack La Lane 831 Rocky Rd. High Rd 2 Scotland I-40 Freeway Telephone (299) 458-9287 (298) 754-1489 (299) 572-9578 (298) 194-2374 (298) 278-9278 (299) 856-9274

The slots can have sub-slots. The sub-slots can have sub-sub-slots and so on. However, if a slot contains a sub-slot, it must contain at least 2 sub-slots. The slot or field definition part of the frame is called the header. This is everything up to the double lines. Everything following the double line is called the body. Each row of data in the body is called a frame row.

L - FRAME / TABLE

Example:
Item Price Our Cost Sale Price Diameter Dia Units Length Len Units HEADER

Screw

.01

1.90

1/4

inch

2 3/4

inch BODY

Pipe

50.00

150.00

.5

feet

yards

The names of the slots are the words used in the header. A sub-slot has both a name and a full name. The names are case insensitive, so if you have a slot "Inch," it will match with "inch" and "INCH." A full name consists of the name of the slot which the sub-slot is in, followed by a period and the name of the slot, for example, Price.Our Cost, Price.Sale Price, Diameter.Dia, Diameter.Units, Length.Len, Length.Units. To reference a slot of a frame, you can use just its name. However, if its name is not unique then you must use its full name. For example, in the table above, "Sale Price" is unique and it would not be necessary to use "Price.Sale Price." However, "Units" is not unique and it would be necessary to use "Length.Units" or "Diameter.Units." The value in the slot can be evaluated as string value or as a number. To tell the program how you want the value handled, the slot name is preceded and followed by a $ for a string or # for a number. For example, in the first row of the body, #Sale Price# would be a numeric value of 1.9. However, $Sale Price$ would be a string value of "1.90." For strings, leading and trailing spaces are dropped. These values are handled differently in EXSYS Professional operations and value assignments. Notice the 2 3/4 will be evaluated as 2.7500. FRAME will correctly handle fractional notation. Remember in the table above, $units$ is ambiguous since there are 2 slots with that name. You should, therefore, specify $diameter.units$ or $length.units$. You can also retrieve the value of slots which have sub headings. For example, $Length$ will have the value "2 3/4 inch" or "2 yards", depending on which row we select. The value will include all of the sub-heading values.

L - FRAME / TABLE

Notice that, in the frame, the separating lines are missing in the value of $length$. The separating lines have no function in the frame rows. They are crucial in the header. Where the separating lines appear in the header determines what columns hold the data for that slot. Note: The characters $, #, and . have special meaning in a slot reference; they cannot be used in the slot names in the header.

L2.3: Specifying the Frame Row


The frame row that will be used is the first one that passes a Boolean test. The test can be on a numeric or string value of one or more slots. This test expression is the second parameter in the call to FRAME. For example, using the frame above, we could have the following test: $item$ = "screw" This means find the first row in which the string value of the slot "item" has the value "screw." This will be the first row of the body. The following test, #sale price# - #our cost# > 10.00 combines the values of two slots as numeric values. Sub-heading can also be used such as $length.units$ = "yards " Any legal EXSYS Professional test that does not include EXSYS variables can be used. However, EXSYS variables can be embedded in the expression by using [[ ]]. For example, you could use [[X]] == 2 if the value of [X] was "$length.len$." All of the Boolean expressions supported by EXSYS can be used. See section C15.10 for more information. Example: (#sale price#-#our cost#>10.00) AND ($length.units$= "yards")

L - FRAME / TABLE

L2.4: How to Create a Frame


Frames are created with your word processor or text editor. If you use a word processor, make sure it is in "non-document" or ASCII mode. It is necessary to specify the various field widths of the frame slots by drawing boxes around the text in the header. This is usually most easily done with the + - and | keys. However, if your text editor supports ASCII characters over 128, you can draw the boxes using the ASCII characters for drawing lines.

First Line:
The first line of a frame must be at least 3 characters long. It must be all +'s and -'s or a drawn line using extended graphics characters. The length of the space marked with + or - indicates the width of the frame. All other columns outside of the space marked will be ignored. This makes the first line very important.

Header:
The header lines must fit under the first line. Enter the names of the slots or sub-slots, with the field width indicated by the | character. It is important to make sure that the width is adequate to hold any data that may be entered. Continue entering lines with sub-slots until the header is defined. End the header with a line of = characters. The line using = must not have + or | characters in it.

Body:
The data in the body of the frame should line up under the slot names or sub-slot names. It is not necessary to mark the slot widths in the body with |, but it does make the frame easier to read.

Last Line:
The last line must be the same as the first line in the frame.

Comments:
Any data outside of the space marked off by the first line is ignored. Comments can be placed outside of the marked space. This syntax may seem unnecessarily complicated, but the resulting frame is easy to read and understand. The frame is maintained as tabular data and can be created by many database managers or spreadsheet programs. By using the header to define field widths, it is easy to change the frame and quite complex structures can be kept as simple ASCII files without additional field width data.

L - FRAME / TABLE

An example of a frame with comments is:


Customer information +------+-----------------+-----------------+ | name | address | telephone | ============================================ | Mike | 100 Memory Lane | (021) 458-9287 | | Dan | 201 Penny Lane | (043) 754-1489 | | Jill | 832 Jack La Lane| (092) 572-9578 | +------+-----------------+-----------------+ Current as of 1/5/1989

Notice the comments outside of the frame are ignored, both before and after the first and last line and outside the frame width. You can put anything outside the frame as long as it is not confused for the first line of the frame. 1. 2. 3. 4. The first line defines the width and is required. The vertical bars separating the slots are required. The double line separating the header from the body is required. The last line, which is the same as the first line, is required.

The following is an example of a frame with sub-slots:


--------------------------------------------------------| item | price | diameter | length | | |our cost |sale price| dia |units | len |units | ========================================================= screw .01 1.90 1/4 inch 2 3/4 inch pipe 50.00 1500.00 .5 feet 2 yards ---------------------------------------------------------

Notice that only the minimum syntax was used. The use of +'s and extra lines in the header make it easier to read and maintain.
+-------+--------------------+------------+-------------+ | item | price | diameter | length | | +---------+----------+-----+------+------+------+ | |our cost |sale price| dia |units | len |units | ========================================================= | screw | .01 | 1.90 | 1/4 inch |2 3/4 inch | | pipe | 50.00 | 1500.00 | .5 feet | 2 yard | +-------+---------+----------+-----+------+------+------+

L2.5: Inheritance
Inheritance is a powerful capability of FRAME. It allows you to specify a "parent" frame for any other frame. If a search on the test expression fails in all lines of the specified frame, the search will be repeated in the parent frame. This allows data to be split over a set of frames. One frame may have general, or default information while sub-frames have specific information. If a search of the specific information fails, the program will automatically return to the general frame.
L - FRAME / TABLE
8

Suppose you are storing information about animals in the frames. The vast amount of information demands a systematic method of storing that information. Much of the information is the same for groups of animals. For example, almost all mammals are warm blooded, have hair and give live birth instead of eggs. It would be nice if we didn't have to put every feature/attribute of the animal in the frame of that animal. It would be nice if there were a link from a dog frame to a mammal frame such that it could be determined that a dog is warm blooded and have that fact stored only in the mammal frame. This is accomplished using inheritance. To specify the frame you will inherit from, after the frame put ~INHERIT FROM <filename> Data not found in the current frame will be searched for in the file specified. Be sure it appears on a line occurring after the last line of the frame. You can have one file inherit from another file which inherits from yet another file etc. To continue with the mammal example above, we could have a frame MAMMAL with very general characteristics:
+----------------+------------------+---------------+ | Warm Blooded | Body Covering | Live Birth | ===================================================== | YES | Hair | YES | +----------------+------------------+---------------+

~INHERIT FROM ANIMAL

We have defined it to inherit from an even more general frame ANIMAL. We could now have the DOG frame:
+----------------+--------------+ | Number of Legs | Carnivore | ================================= | 4 | YES | +----------------+--------------+ ~INHERIT FROM MAMMAL

If we searched DOG for Number of Legs, we would get 4 directly, but if we searched for "Warm Blooded," there would be no such slot and the call would be repeated for the parent frame mammal. In this case, we have only one line in the body of each frame. But there could be many. Also, we might have a frame for Platypus that would over-ride the slots in the parent frame, by having a specific entry:
L - FRAME / TABLE
9

+----------------+--------------+-------------+ | Number of Legs | Carnivore | Live Birth | =============================================== | 4 | YES | NO | +----------------+--------------+------- -----+ ~INHERIT FROM MAMMAL

If we asked about Live Birth in the Platypus frame, we would find the slot and not inherit from the parent frame.

L - FRAME / TABLE

10

L3: Reading from a Frame


FRAME( "filename", test_expression, slot_reference)

Filename: Test_expr: Slot_ref:

The name of the FRAME data file. The filename must be in " ". The Boolean expression used to find the desired line in the frame. The desired column in the frame. FRAME looks in the file for a frame which matches the test expression and either writes or reads the slot referenced. This reference must be in $ or # to indicate if it to be handled as a string or numeric.

The value found will be returned to EXSYS.

L - FRAME / TABLE

11

L4: Writing to a Frame


FRAME( "filename" , test_expr , slot_ref := expression)

Filename: Test_expr: Slot_ref:

The name of the FRAME data file. The filename must be in " ". The Boolean expression used to find the desired line in the frame. The desired column in the frame. FRAME looks in the file for a frame which matches the test expression and either writes or reads the slot referenced. This reference must be in $ or # to indicate if it is to be handled as a string or numeric. The data to be written into the slot_reference.

Expression:

Writing to a frame is very similar to reading except for the last parameter. Instead of just being a slot designator, there are both a slot designator and an expression to assign to that slot. The assignment can include data from other slots in that row. The assignment is indicated by :=.

L - FRAME / TABLE

12

L5: Examples
Here are some examples: Price Frame:
+-------+--------------------+------------+-------------+ | item | price | diameter | length | | +---------+----------+-----+------+------+------+ | |our cost |sale price| dia |units | len |units | ========================================================= | screw | .01 | 1.90 | 1/4 inch |2 3/4 inch | | pipe | 50.00 | 1500.00 | .5 feet | 2 yard | +-------+---------+----------+-----+------+------+------+

Reading from the Frame:


FRAME("PRICE", #Cost# > 40, $item$) will return the value "pipe" as a string. FRAME("PRICE", $item$ = "pipe", #length.len#) will return the value 2 as a numeric.

Writing to the Frame:


FRAME("PRICE", $item$ = "pipe", #length.len# := 3) will change the length.len value from 2 to 3. FRAME("PRICE", $item$ = "pipe", $item$ := "pipe A") will change the item name for "pipe" to "pipe A."

L - FRAME / TABLE

13

L6: Including FRAME and TABLE in Your Expert System


Frame commands can be included into your expert system rules in a variety of ways.

1. Associated with a qualifier or variable.


A FRAME( ) or TABLE() command can precede the text of a qualifier or variable just like a RUN( ) command. Assume, for example, we have the following qualifier: The color is 1 red 2 blue 3 green Suppose we wanted to store this data in a frame. We could then access the data with a FRAME( ) command. FRAME(...)The color is 1 red 2 blue 3 green Now if this data is needed, EXSYS will automatically get it from the frame. The same thing can be done with a variable. If we have a variable [LENGTH A] with associated text "The length of pipe A," we could store the data in a table: TABLE(...) The length of pipe A The easiest way to add such data acquisition commands is just to enter the qualifier and value text normally, with no FRAME or TABLE command. Once that is done, you will first be asked for an optional qualifier name. Then you will be asked if you wish to associate a data acquisition command with the qualifier or variable. Press <Y> and you will have a menu of possible sources for the data. You can select the one you want with the cursor keys. Select FRAME or TABLE and you will be prompted through the options for the command. By using this approach, it is not necessary to memorize the command syntax because EXSYS will build the command for you.

L - FRAME / TABLE

14

2. Run as the result of a Rule Firing


You may wish to have a FRAME updated when a rule fires. This is done by pressing the <X> key in the THEN or ELSE part. You will be given a list of possible commands. You can select FRAME and you will be prompted through the creation of the command. In the THEN/ELSE part.

3. From the Command Language


You may include FRAME( ) commands anywhere in the command file. Since this file is created with a text editor, you will need to learn the syntax of the commands to use this approach. If you have difficulty writing the command, create a rule in the EXSYS Editor, go to the THEN part, press <X> to get the command menu. Select FRAME and follow the prompts to build the command. Copy this command into your command language file. This would normally be done only to write to the frame.

4. From the Report Generator


You may include FRAME( ) commands anywhere in the report generator file. Like the command file, this file is created with a text editor, you will need to learn the syntax of the commands to use this approach.

L - FRAME / TABLE

15

Chapter M Blackboard Manager M1: Introduction


The Generic Data Blackboard (hereafter referred to as "EXSYSBB") provides a flexible means for expert systems and other applications to store and retrieve small volumes of data. Blackboard is an Artificial Intelligence term that is often applied to databases used to share information between or among expert systems and other programs in a knowledge based application.

M1.1: Recommended uses for EXSYSBB


Call EXSYSBB before running an expert system to make data available to the application. Associate an EXSYSBB call with a specific qualifier or variable to have that data element obtained from the blackboard. Call EXSYSBB from the THEN or ELSE portion of an expert system rule to post new information to a blackboard. Let EXSYSBB provide the data interface between several expert system modules or other programs which run in your application.

M1.2: EXSYSBB Blackboards


EXSYSBB Blackboards are simple database tables consisting of strings of data in ASCII format. EXSYSBB Blackboards do not use a proprietary format and may be read and written by many applications. Physical data format considerations such as a prefix token, suffix token and delimiters need not be stored in the blackboard. These are supplied as runtime parameters when EXSYSBB is invoked. Since formatting information is supplied at invocation, EXSYSBB and its blackboards can be truly generic. You need not code and maintain "translate tables" to convert one application format to another. The documentation of the specific format requirements is in the code, so to speak, because it is part of the invocation call to EXSYSBB.
M - BLACKBOARD MANAGER
1

M1.3: Communication Between EXSYSBB and Your Applications


EXSYSBB receives instructions from the application at runtime via parameters passed on the command line. The expressions consist of command switches and associated data. Please refer to the Command Summary in this manual and the examples used in the demonstration. Data is returned from EXSYSBB to your applications via simple ASCII files. The use of a file for interprocess communication was chosen because it is highly portable across different computer operating systems and applications.

M2: Calling EXSYSBB


EXSYSBB is called with an EXSYS internal command. When calling EXSYSBB from within EXSYS, there are three internal commands: BB_RD(parameters) BB_WR(parameters) BB_DE(parameters) Read from blackboard Write to blackboard Delete data from blackboard

Note: The syntax of the parameters for each command is described in the command section of this chapter. When calling from the operating system, there is only a single command used, but it requires one additional parameter. The other parameters are the same as when calling from within EXSYS. There is also a stand alone executable program called EXSYSBB.EXE. Note: EXSYSBB as a separate executable is not supported in all operating systems. It can be called like any other executable program from the operating system. However, for the three different types of blackboard commands, an extra parameter must be added as the first parameter passed. The other parameters are the same in both calling methods. BB_RD(parameters) BB_WR(parameters) BB_DE(parameters) EXSYSBB(-Q parameters) EXSYSBB(-U parameters) EXSYSBB(-D parameters)

M - BLACKBOARD MANAGER

M3: Including EXSYSBB in Your Expert System


EXSYSBB commands can be included in your expert system rules in a variety of ways.

M3.1: Associated with a Qualifier or Variable


A EXSYSBB command can precede the text of a qualifier or variable just like a RUN( ) command. For example, consider the following qualifier: The temperature is 1 over threshold 2 at threshold 3 below threshold Suppose we knew that a previous program or module had left information in the blackboard about the temperature. We could automatically recover this information by preceding the qualifier text with a blackboard read command (BB_RD): BB_RD(...)The temperature is 1 over threshold 2 at threshold 3 below threshold Now if this data is needed, EXSYS will first check the blackboard. If there is no data the user will be asked for input. The same thing can be done with a variable. If we have a variable [PRESSURE] with associated text "The pressure of pipe A," we can get this from the blackboard by changing the text to BB_RD(...) The pressure of pipe A The easiest way to add such data acquisition commands is to just enter the qualifier and value text normally, with no blackboard command. Once that is done, you will first be asked for an optional qualifier name. Then you will be asked if you wish to associate a data acquisition command with the qualifier or variable. Press <Y> and you will have a menu of possible sources for the data. You can select the one you want with the cursor keys. Select BLACKBOARD and you will be prompted through the options for the command. By using this approach, it is not necessary to memorize the command syntax, because EXSYS will build the command for you.

M - BLACKBOARD MANAGER

M3.2: Run as the Result of a Rule Firing


You may wish to have specific data added to the blackboard when a rule fires. This is done by pressing the <X> key in the THEN or ELSE part. You will be given a list of possible commands. You can select BLACKBOARD and will be prompted through the creation of the command. In the THEN/ELSE part, you would usually use the BB_WR( ) or BB_DE( ) commands.

M3.3: From the Command Language


You may include BB_RD( ), BB_WR( ) or BB_DE( ) commands anywhere in the command file. Since this file is created with a text editor, you will need to learn the syntax of the commands to use this approach. If you have difficulty writing the command, create a rule in the EXSYS Editor, go to the THEN part then press <X> to get the command menu. Select BLACKBOARD and follow the prompts to build the command. Copy this command into your command language file.

M3.4: From the Report Generator


You may include BB_RD( ), BB_WR( ) or BB_DE( ) commands anywhere in the command file. Like the command language, this file is created with a text editor so you will need to learn the syntax of the commands to use this approach.

M3.5: From the Screen Definition Language


You may include BB_RD( ), BB_WR( ) or BB_DE( ) commands anywhere in the screen definition commands. This allows you to run several different options. To get data in some cases, it may be necessary to run the EXSYSBB.EXE form with the RUN( ) command. This allows data to be passed back to another target qualifier or variable. Use in the screen definition language allows you to include blackboard calls in the custom help screens as well as the screen used to ask questions.

M3.6: Called from the Operating System


You can call the blackboard manager from the operating system using the EXSYSBB.EXE form of the commands. This can allow you to put data into the blackboard from a batch file.

M3.7: Called from Other programs


Any program that has the ability to run .EXE programs can call the blackboard manager. You must use the EXSYSBB.EXE form of the command.

M - BLACKBOARD MANAGER

M4: Blackboard Command Window


In cases 1 and 2 in the above list, the blackboard call can be built using the blackboard command window .
Operation: Blackboard File Attribute String Value String Optional Success String Optional Failure String Optional Prefix String Optional Suffix String Eliminate Other References READ WRITE DELETE

The meaning of the fields in this window is explained below.

M - BLACKBOARD MANAGER

M5: Reading From a Blackboard


Commands:
Within EXSYS: BB_RD( -A'attribute' optional_parameters) From operating system: EXSYSBB -Q -A'attribute' optional_parameters

Optional Parameters: -B, -F, -N, -P, -R, -S, -T, -V


See the parameter section for details. The Blackboard file must already exist. The default blackboard file GDB.DAT will be used unless the -B option is used.

M - BLACKBOARD MANAGER

M6: Writing to a Blackboard


Commands:
Within EXSYS: BB_WR( -A'attribute' optional_parameters) From operating system: EXSYSBB -U -A'attribute' optional_parameters

Optional Parameters: -B, -M, -V See the parameter section for details. If the Blackboard file does not already exist, it will be created. The default blackboard file GDB.DAT will be used unless the -B option is used.

M - BLACKBOARD MANAGER

M7: Deleting Data from a Blackboard


Commands:
Within EXSYS: BB_DE(-A'attribute' optional_parameters) From operating system: EXSYSBB -D -A'attribute' optional_parameters Optional Parameters: -B, -V See the parameter section for details. The Blackboard file must already exist. The default blackboard file GDB.DAT will be used unless the -B option is used.

M - BLACKBOARD MANAGER

M8: Attributes and Values


The blackboard file is made up of strings of data. These are more general forms of EXSYS qualifier/value combinations or variables. This generalized structure of EXSYSBB makes it very flexible. Data is written to the blackboard as text string. The data written can be an attribute (indicated by -A) or an associated value (indicated by -V). If a value is used, it will be appended to the attribute string. For example: BB_WR(-A'Pressure') will write the string "Pressure" to the blackboard. BB_WR(-A'Pressure' -V'347') will write the string "Pressure 347" to the blackboard. We could just as easily write the full string with BB_WR(-A'Pressure 347') but this could cause multiple references to "Pressure." By using the -M option to eliminate multiple references, we can be sure there is only a single reference to pressure. Strings can also be written to the blackboard by any other program or just a text processor. When data is read from the file, the same attribute or value notation is used, but usually the value will be the data returned. For example, if we use the read command, BB_RD(-A'Pressure') it will return any value that was associated with the string "Pressure." This allows data to be left in the blackboard by a program or expert system module and picked up by another program.

M - BLACKBOARD MANAGER

If values are used with the read commands, the match will be made on both the attribute and value. For example, if there was a blackboard that contained the string "The color is red" and we used BB_RD(-A'The color is') then it would return "red." However, if we used BB_RD(-A'The color is' -V'red') the test would be true, but no data would be returned. In this case, you should use the -T and -F options to tell the program what to return if the test is true or false. In the following example, BB_RD(-A'The color is' -V'red' -T'1' -F'0') would return 1 if the attribute or value pair was found and 0 if it is not. See the Parameters section for details on the various commands parameters that can be used.

M - BLACKBOARD MANAGER

10

M9: Parameters
Post String -A'string expression'
The -A switch allows you to specify a string in the blackboard you want to post to the blackboard or to search for on the blackboard, such as "senior discount rate." You must always specify an attribute string when calling EXSYSBB. For example: BB_WR(-A'Process 1 complete') will write the string "Process 1 complete" to the default blackboard GDB.DAT. BB_RD(-Btest.bb -A'Process 1 complete') will check the blackboard file test.bb for the string "Process 1 complete." If it is found, any associated values will be returned in the file GDB.RTN. BB_DE(-Btest.bb -A'Process 1 complete') will check the blackboard file test.bb for the string "Process 1 complete." If the string is found, it will be deleted.

Specify File -Bfilename


The -B switch allows you to specify the name and path of the blackboard file you wish to use. If not specified, EXSYSBB assumes the default blackboard of "GDB.DAT." For example: BB_WR(-Bbbfile1.out

-A'green')

will use the file bbfile1.out as the blackboard file instead of the default blackboard GDB.DAT.

M - BLACKBOARD MANAGER

11

Delete -D
The -D switch tells EXSYSBB to delete an attribute from a blackboard with value information supplied by you through the use of the other command line switches. This parameter is only needed when calling EXSYSBB from the operating system. When calling from within EXSYS, use the internal command BB_DE Note: If a -V'(value)' is supplied only the specific attributes found with that specific value are deleted. For example: EXSYSBB -D -A'Problem Found' will delete the string "Problem Found" from the default blackboard file.

Failure Return String -F'string expression'


The -F switch allows you to specify a string to be returned to the return file if a query you submit to the blackboard fails to result in a return value. It is optional. See also -T and -N. This allows you to be certain that some value will be returned. Example: BB_RD(-A'Pressure' -F'0.0') will check the blackboard for the string pressure and return the value associated if there is one. If the string pressure is not found, the value 0.0 is returned.

Eliminate Other References -M


The -M switch during a write operation to the blackboard causes EXSYSBB to seek and eliminate any other references to the attribute involved in this update transaction. It is useful for eliminating multiple references to a blackboard attribute and should be used whenever the value relevant to a particular attribute is to be considered unique.

M - BLACKBOARD MANAGER

12

Note: -M is valid only if the blackboard already exists and may not be specified when creating a new blackboard. For example, suppose we have a blackboard with the line Pressure 555 We want to change the pressure value to 111. If we just use: BB_WR(-A'Pressure' -V'111') the blackboard file will contain Pressure 555 Pressure 111 There are some cases where such multiple reference information is useful, but in this case we will want a unique value. To do this we eliminate multiple references to the attribute with BB_WR(-A'Pressure' -V'111' -M) This will eliminate the old reference and the blackboard will now have just Pressure 111

Failure Leaves Empty File -N


The -N switch during a query tells EXSYSBB to leave an empty return file on your disk in the event of a failed query. If you do not use the -N option, no file will be created in the event that your query fails to result in a return value. See -F for another alternative.

Prefix String -P'string expression'


The -P switch causes an item to be written with the string following this switch used as a prefix. This is needed to tell EXSYSBB what sort of token your application would like associated with the information when it reads it out of the return file. See also -S.

M - BLACKBOARD MANAGER

13

For example, suppose you wanted to read the value of the attribute "Pressure" into variable [P]. Normally, you would just associate the blackboard call with the variable [P], but you could alternatively call EXSYSBB as an external program and use EXSYSBB -Q -A'Pressure' -P'[P] ' This if the blackboard contained the string "Pressure 546," this would return "[P] 546."

External Form Query -Q


The -Q switch tells the program to query an existing blackboard and return the results according to your instructions as defined by use of other switches. This is used only when calling EXSYSBB.EXE from the operating system. It is not needed when using the EXSYS internal command BB_RD.

Return File Name -Rfilename


The -R switch tells EXSYSBB to use the associated string as a return file for query data. If not specified, EXSYSBB uses the name "GDB.RTN". Note: If you are calling the commands from within EXSYS, the reading of the return file is handled automatically and the -R option should not be used. For example, EXSYSBB -Q -A"The color is" -Rtest.dat will return the value associated with the attribute "The color is" in the file test.dat, rather than the default file GDB.DAT.

Suffix String -S'string expression'


The -S switch causes an item to be written with the string following this switch as a suffix. This may be needed to tell EXSYSBB what sort of delimiters such as commas, quotation marks, etc. are required by an application. See also the -P switch.
M - BLACKBOARD MANAGER
14

For example, if you want to append the string "XXX" to a value, you could use EXSYSBB -Q -A"The color is" -S'XXX' This option is rarely needed, but allows compatibility with the maximum number of applications.

Successful Query Return String -T'string expression'


The -T switch during a query tells EXSYSBB to return the associated string instead of a blackboard value if the query is successful. See -F, which is the counterpart to -T. In the following example, BB_RD(-A'The color is' -V'red' -T'1' -F'0') would return 1 if the attribute or value pair were found and 0 if it were not found.

External Form Update -U


The -U switch tells EXSYSBB to update a blackboard with attribute and value information supplied by you through the use of the other command line switches. This is used only when calling EXSYSBB.EXE from the operating system. It is not needed when using the EXSYS internal command BB_WR. Note: If the -M switch is invoked during update, the blackboard file must already exist. If -M is not used, EXSYSBB will create the blackboard file if it does not already exist.

M - BLACKBOARD MANAGER

15

Supplemental Switch -V'string expression'


The -V switch allows you to specify a supplemental switch to the -A switch. Its function depends on what operation is being performed: Reading: If the -V switch is present in a read command (BB_RD), EXSYSBB searches for an exact match of attribute string (-A) and value string (-V). In the following example, BB_RD(-A'The color is' -V'red' -T'1' -F'0') would return 1 only if the specific value "red" was found. If the -V switch is absent during a query, EXSYSBB searches and returns all values associated with the specified attribute. Writing: If the -V switch is present during a write command (BB_WR), the value string is posted to the blackboard along with the attribute. For example, BB_WR(-A'The color is' -V'red') will write "The color is red" to the blackboard.

M - BLACKBOARD MANAGER

16

M10: External Call Values (demons):


If, during the process of returning values during a read operation, EXSYSBB encounters a value expression which begins with an exclamation point (!), it will pass the value expression out to your operating system's command processor for immediate execution instead of returning it in the return file. Following execution, EXSYSBB continues the query operation. Note: Processing an external call requires enough system memory to run the program. For example, suppose we had a blackboard file with the line Command !dir If we read this line with BB_RD(-A'command'), instead of having the string !dir returned, the DIR command will be executed as if it was typed in from DOS. This can also be used to run executable programs or batch files. One technique is to have several executable commands added to the blackboard file without the -M option so there are multiple references. For example, if we have the commands BB_WR(-A'RUN PROGRAM:' -V'!DIR') BB_WR(-A'RUN PROGRAM:' -V'!EXSYSP TEST') and later we do a read with BB_RD(-A'RUN PROGRAM:'), the blackboard manager will first do a "DIR" command and then run EXSYSP with the knowledge base test. This option allows one call to the blackboard manager to leave a command that will not be executed until a later call. This allows very complex strategies with external programs to be utilized.

M - BLACKBOARD MANAGER

17

M11: Operating Modes


Trace Operation
You can turn the EXSYSBB trace on during Normal operation by setting the environment parameter GDBTRACE=Y before calling EXSYSBB. See your operating system manual if you are not familiar with the SET function.

Interactive Operation
Invoke EXSYSBB without command line parameters and it will turn on a trace function, display a sign-on message and prompt you for a command line.

M - BLACKBOARD MANAGER

18

M12: Error Messages


GDB ERROR: No attribute was specified in command line. Either you did not include the -A parameter or EXSYSBB could not see it because of errors in the single quotation mark delimiters. GDB ERROR: Invalid switch character in command line. You included a switch that is not supported by EXSYSBB. GDB ERROR: Invalid character in command line. EXSYSBB found an invalid character (such as a control character) in the command line. GDB ERROR: Unable to open command file. EXSYSBB could not find your operating system's command processor. GDB ERROR: Unable to read command file. EXSYSBB encountered an error trying to access the operating system's command processor. GDB ERROR: Unable to open return file. EXSYSBB could not open GDB.RTN or the file name you specified. Check for sufficient disk space, and presence of a preexisting file that is "read only." GDB ERROR: Unable to open working file. EXSYSBB could not open a work file needed for blackboard processing. Check for sufficient disk space, and presence of a preexisting file that is "read only." GDB ERROR: Unable to open blackboard file. EXSYSBB could not find GDB.DAT or the file name you specified. GDB ERROR: Specify Update, Query or Delete. EXSYSBB found more than one of the -U, -Q, -D switches set, or none set. GDB ERROR: Missing single quotation mark delimiter from command line. EXSYSBB could not find the leading quotation mark delimiter for the switch named in the message.

M - BLACKBOARD MANAGER

19

M13: Common Errors


1. Error in the single quotation mark delimiters: One of the two required quotation marks has been left off; you are using quotation marks with a switch that does not require them; you are using double quotation marks (") by mistake. 2. You forget to specify the -Q, -U or -D switch when calling from the operating system. 3. You mixed case in attributes, values, and other strings. Some calling programs may convert all command line arguments to upper case. Use the interactive mode to check, if you suspect this is a problem.

Other kinds of errors:


EXSYSBB needs about 128K of free memory at runtime. If you do not have sufficient memory available, DOS may crash. The test for this condition is that EXSYSBB runs fine stand alone but crashes either consistently or intermittently when called from your application. Before you suspect a memory problem, double check that you are calling EXSYSBB correctly. If you do not have EXSYSBB in your application's path, your application may crash or report an execution error. If you are keeping EXSYSBB in a different path, it's always a good idea to specify the full drive and path.

M - BLACKBOARD MANAGER

20

Chapter N LINDO Interface N1: Introduction


The LINDO interface in EXSYS Professional is designed to allow incorporation of LINDO's powerful linear and integer programming techniques into an expert system. It is particularly well-suited for expert systems developed for scheduling, resource optimization, or other problems where an optimal solution must be found. The interface is designed to be easy to implement and transparent to the end user. However, the developer must understand both EXSYS and LINDO to use the programs effectively. This manual assumes that the user knows how to build LINDO models and run LINDO. For information on using LINDO, see the LINDO user manuals. EXSYS uses a file similar to the report generator file to generate a LINDO model. This model is then run by LINDO automatically. The results of the LINDO run are read back into specified EXSYS variables. With the command language, LINDO can be run repetitively with some parameters varied by the expert system rules. This allows both non-numeric heuristics and linear optimization to be incorporated into the solution of the problem. In addition to the expert system capabilities, EXSYS effectively wraps the flexible user interface and report generator around LINDO. LINDO is extremely powerful. It may be difficult, however, for untrained users to understand the meaning of the output. Now, linear programming can combine with EXSYS's many ways of getting user input (including graphics), the flexible report generator to format output and the inference engine to interpret the meaning of the results provided by LINDO. In this way, complex LINDO models can be created based on data input by the user, and complicated LINDO results can be interpreted with an expert system to produce easy to understand reports.

N - LINDO INTERFACE

N2: Calling the LINDO Specification File


EXSYS supports the internal command LINDO(...). This command can be used in any place where a RUN(...) command could be used: 1. 2. 3. 4. Associated with a qualifier or variable In the THEN or ELSE part of a rule In the Command Language In the Report Generator

The following is the proper command syntax: LINDO(filename options) The "filename" is the name of the LINDO specification file. This file has the commands to build the LINDO model and to read data back into EXSYS variables. The model will be built and run automatically. The results will be read back into specified EXSYS variables. The "options" allow overriding the automatic sequence of the LINDO command. The following list describes what the LINDO options are and what they do: /I Causes LINDO to be run in an interactive mode. LINDO is normally run with no user interaction. The model automatically generates an output file and LINDO terminates. In interactive mode, the command file will be created and can be loaded and run, but all of the interactive LINDO commands will be available for examining the model. This is useful to examine results, make modifications in the model or test the system during development. Usually, once the development is completed, the /I would be removed. Causes the LINDO command file to be written, but not executed. The option /W=filename causes the command file to be created in the file "filename." The default file name is LINDOCMD.TMP. This option is useful for creating a model, using the model to run LINDO on another computer and then returning the results to the starting computer. Causes the LINDO results file to be read, but without building a command file or executing LINDO. The option /R=filename causes the data to be read from the file "filename." The default file name is LINDORET.TMP. This option is useful for reading data created if LINDO is run on another computer. UNIX Note: With UNIX computers, all / are replaced by -. For example, /I becomes -I.
N - LINDO INTERFACE
2

/W

/R

N2.1: LINDO Specification File


The LINDO specification file in EXSYS has two parts. The first specifies how to build a LINDO model and incorporate EXSYS data into the model. The second part specifies what LINDO return data should be read into specified EXSYS variables. The ~RESULTS command indicates the start of the second section. All commands prior to ~RESULTS build a model which is executed when the ~RESULTS command is reached. All commands after the ~RESULTS command tell EXSYS what data to take from LINDO and what EXSYS variables to assign it to. Within the section building the model, a conditional test can be used to customize the model based on the values of various parameters. The LINDO specification file has the following syntax: ~TEMP=path ~LINDO=filename model commands ~IF expression model commands ~ELSE model commands ~ENDIF model commands ~RESULTS data commands Optional Optional

~TEMP=path
EXSYS will create two temporary files during the LINDO run. One contains the LP model and the other the results of the LINDO run. The names of these files are LINDOCMD.TMP and LINDORET.TMP. These names cannot be changed, but the directory they are in can be changed. If there is no ~TEMP command, the files will be created in the default directory. If there is a ~TEMP command, the files will be created in the directory specified by the path. This is useful for creating the temporary files on a RAM disk to improve performance. The ~TEMP command is optional, but if it is used, it must appear before any model commands. The following example ~TEMP=d: would create the temporary files on drive D, which could be a RAM disk.
N - LINDO INTERFACE
3

~LINDO=filename
EXSYS will call LINDO after the model is built. It expects LINDO.EXE to be in the default directory. If LINDO is somewhere else, or renamed, you must include a ~LINDO command to tell EXSYS where LINDO is. This is not a path, but a full file specification. The following applies, for example, if LINDO.EXE is in a directory called LINDO: ~LINDO=/LINDO/LINDO.EXE

N - LINDO INTERFACE

N3: Model Commands


Model commands are lines in the file that will be used to build the LINDO model. They will be put in the file LINDOCMD.TMP exactly as they appear with two exceptions: embedded EXSYS variables will be replaced by their values and embedded expressions will be replaced by their values. Embedded EXSYS variables are represented by the variable name enclosed in either single or double [ ]. Embedded expressions are any legal EXSYS expression enclosed in <? ?> . The expression or variable will be evaluated and inserted in the model at the point specified. Variables and expressions can be either string or numeric. This allows EXSYS data to be easily incorporated into the LP model. The <? ?> notation for expressions can be used anywhere a [[ ]] expression for a variable can be used. The expression inside the <? ?> will be evaluated and the value calculated placed in the string. Any text on a line following the characters /* will be considered a comment and not put in the model. For example, suppose we have EXSYS variables [NUM] and [PRICE], with values 5 and 35 respectively. The model commands MAX 2X+[NUM]Y /* the goal to maximize ST 3X + <? [PRICE]/[NUM] ?> Y < 100 would generate LP model commands MAX 2X+5Y ST 3X + 7Y < 100 String variables may also be used. We could have a string variable [S] whose value would be "MIN" or "MAX" depending on the rules. Then we might have [S] 2X+5Y

which would be converted to MAX 2X+5Y or MIN 2X+5Y depending on the rules in the expert system.
N - LINDO INTERFACE

N4: ~IF test expression, ~ELSE, ~ENDIF


When building the model, it may be desirable to include certain model commands only if some criterion is met in the expert system. This is easier than having many LINDO specification files. If the ~IF command is used, it is followed by any legal EXSYS expression. The expression can use numeric or string data, but must return TRUE or FALSE. Qualifiers can be included with the QCHK function (QCHK returns TRUE or FALSE already). The following are examples of legal expressions: [X] > 0 [S] != "abcd" sin([X]*[X]) < tan([Y]) QCHK(15, 1) If the test expression is true, the model commands immediately following the ~IF will be used. If the test expression is false, and there is an ~ELSE, the model lines following the ~ELSE will be used. If there is no ~ELSE, the lines after the ~ENDIF will be used. Every ~IF command must have a matching ~ENDIF command. ~IF commands can be nested, provided there is an ~ENDIF for each ~IF. For example, suppose we again have the EXSYS variables [NUM] and [PRICE] with values 5 and 35 respectively. The model commands, MAX 2X+[NUM]Y ST ~IF ([PRICE] < 30) 3X + 8Y < 100 ~ELSE ~IF ([NUM] < 7) 3X + 7Y < 18 ~ELSE 4X + 7Y < 20 ~ENDIF ~ENDIF for [NUM]=5 and [PRICE]=35, will generate the following: MAX 2X+5Y ST 3X + 7Y < 18
N - LINDO INTERFACE
6

N5: ~Results
The ~RESULTS command tells EXSYS 1. That the model is complete 2. To run LINDO on the model 3. That the commands that follow are data commands There must be a results command unless the /R option was used.

N6: Return Data Commands


Data commands provide an easy way to get LINDO results back into EXSYS variables. The syntax for the data command is [EXSYS Variable name] = LINDO data ID The EXSYS variable name is any numeric EXSYS variable, such as [X] or [NUM]. The LINDO data ID is an identifier of a particular item of data returned by LINDO. EXSYS will find the item of data specified and assign the value to the EXSYS variable. There can be as many data commands as needed.

N6.1: LINDO Data ID


There are many LINDO data IDs and all have abbreviated forms:

LP OPTIMUM FOUND AT STEP


Abbreviated forms: STEP, OPT FOUND STEP, OPTIMUM FOUND AT STEP This ID returns the number of the step at which the optimum was found. For example: [N] = OPT FOUND STEP

N - LINDO INTERFACE

OBJECTIVE FUNCTION VALUE # or name


Abbreviated forms: FCT VAL, FUNCTION VALUE This ID returns the objective function value for the function specified by number or name. This example, [F1] = OBJECTIVE FUNCTION VALUE 3 would return the value of objective function number 3.

VARIABLE VALUE LINDO var name


Abbreviated forms: VAR VAL, VAR VALUE This ID returns the VALUE column for the specified LINDO variable. For example: [N VAL] = VARIABLE VALUE N

VARIABLE REDUCED COST LINDO var name


Abbreviated forms: VAR RC, VAR REDUC COST This ID returns the REDUCED COST column for the specified LINDO variable. For example: [N RC] = VAR RC N

VARIABLE CURRENT COEF LINDO var name


Abbreviated forms: VAR CUR COEF, VAR CURRENT COEF This ID returns the CURRENT COEF column for the specified LINDO variable. This example: [N CC] = VAR CURRENT COEF will return the CURRENT COEF for variable N. N

N - LINDO INTERFACE

VARIABLE ALLOWABLE INCREASE LINDO var name


Abbreviated forms: VAR ALL INC, VAR ALLOWABLE INC This ID returns the ALLOWABLE INCREASE column for the specified LINDO variable. This example: [N AI] = VAR ALL INC N

will return the allowable increase column for variable N.

VARIABLE ALLOWABLE DECREASE LINDO var name


Abbreviated forms: VAR ALL DEC, VAR ALLOWABLE DEC This ID returns the ALLOWABLE DECREASE column for the specified LINDO variable. This example: [N AD] = VAR ALL DEC N

will return the allowable decrease column for variable N.

ROW SLACK # or name


Abbreviated forms: ROW SL This ID returns the SLACK OR SURPLUS column for the specified ROW. This example: [X] = ROW SLACK cost

would return the SLACK for the row labeled "cost."

ROW DUAL PRICE # or name


Abbreviated forms: ROW DP This ID returns the DUAL PRICE column for the specified ROW. This example: [X] = ROW DP cost

would return the DUAL PRICE for the row labeled "cost."

N - LINDO INTERFACE

ROW CURRENT RHS # or name


Abbreviated forms: ROW RHS This ID returns the CURRENT RHS column for the specified ROW. This example: [X] = ROW CURRENT RHS cost

would return the CURRENT RHS for the row labeled "cost."

ROW ALLOWABLE INCREASE # or name


Abbreviated forms: ROW ALL INC, ROW ALLOWABLE INC This ID returns the ALLOWABLE INCREASE column for the specified ROW. This example: [X] = ROW ALL INC cost

would return the ALLOWABLE INCREASE for the row labeled "cost."

ROW ALLOWABLE DECREASE # or name


Abbreviated forms: ROW ALL DEC, ROW ALLOWABLE DEC This ID returns the ALLOWABLE DECREASE column for the specified ROW. This example: [X] = ROW ALL DEC cost

would return the ALLOWABLE DECREASE for the row labeled "cost."

ITERATIONS
Abbreviated forms: ITER This ID returns the number of iterations. For example: [I] = ITER

N - LINDO INTERFACE

10

NO SOLUTION
This ID returns 1 if no solution was found or 0 if a solution was found. This can be used as a check before displaying results. For example: [OK] = NO SOLUTION

N - LINDO INTERFACE

11

N7: Sample EXSYS / LINDO Interface


The following very simple problem demonstrates how an expert system can be used with LINDO. This demo assumes an understanding of LINDO models and results. For information on using LINDO, see the LINDO Users Manual and reference books. Suppose we have an EXSYS expert system with the variables [PROFIT X] and [PROFIT Y], which represent the profit gained from product X and product Y. The expert system will calculate these values based on market trends, supply, or other factors that would govern the profitability of the products. What we want to do is select the number of X and Y to manufacture each day to maximize the total profit, which is the sum of X times the profit from X plus Y times the profit of Y. In LINDO notation, with EXSYS variables included, this is MAX [PROFIT X] X + [PROFIT Y] Y

There are various constraints on manufacturing the products due to production capability. It takes 4 units of production capacity to manufacture an X product and 3 units of production capacity to manufacture a Y product. We have only 10 units of production available per day. In the LINDO model for the problem, this will be represented as 4X + 3Y < 10 where X and Y represent the number of product X and product Y we should manufacture per day under current market conditions. Also, because of supply limitations, we have another constraint on production of: 3X + 5Y < 12

To create an interface between EXSYS and LINDO 1. Write an expert system to derive the value of [PROFIT X] and [PROFIT Y] based on various factors. 2. Once the value is derived, call LINDO to find the optimum point of operation. There are many ways this could be done. One simple way is to use the command language to force executions of the rules to derive the values of [PROFIT X] and [PROFIT Y] and then call LINDO.

N - LINDO INTERFACE

12

The command file would look like RULES [PROFIT X] RULES [PROFIT Y] LINDO(FIND_OPT.LIN) REPORT(FIND_OPT.RPT) The first line invokes all rules that will derive a value for [PROFIT X]. The second does the same for [PROFIT Y]. The third line calls LINDO using the LINDO specification file FIND_OPT.LIN (this could have any name). We then call the report generator to display the results. 3. Write the LINDO specification file, in this case FIND_OPT.LIN. This contains the model and instruction on what data to return to EXSYS variables. In this case, the specification file would read MAX [PROFIT X] X + [PROFIT Y] Y ST 4X + 3Y < 10 3X + 5Y < 12 ~RESULTS [X PER DAY] = VAR VALUE X [Y PER DAY] = VAR VALUE Y [TOTAL PROFIT] = FUNCTION VALUE 1 The first line says to maximize the profit of X times the number of X produced plus the profit of Y times the number of Y produced. The EXSYS variables [PROFIT X] and [PROFIT Y] will be replaced automatically by the values calculated by the expert system before the model is run. The ST in the second line is LINDO notation that indicates the start of the constraints. Lines 3 and 4 are the constraints on manufacturing X and Y in LINDO notation (These lines could also contain EXSYS variables if desired). The ~RESULTS indicates the end of the LINDO model commands and the start of commands to return results to EXSYS. After the model is run, these commands will be used to parse the LINDO results file. The 6th line will assign the EXSYS variable [X PER DAY] the optimum number of X to be produced as calculated by LINDO, based on the model. This will be in the VARIABLE VALUE column of the LINDO results in the row X. We also do the same for the EXSYS variable [Y PER DAY]. The final line assigns the EXSYS variable [TOTAL PROFIT] the value calculated by LINDO for the maximum profit at the optimum point of operation. This is in the OBJECTIVE FUNCTION VALUE column of the LINDO results for formula 1.

N - LINDO INTERFACE

13

4. Write a report specification to format and display the values returned. A very simple one would be FILE TEMP "OPTIMUM POINT OF OPERATION" " " "Current Profitability:" [PROFIT X] [PROFIT Y] " " "Optimum Point of Production" [X PER DAY] [Y PER DAY] " " "------------------------------------" [TOTAL PROFIT] CLOSE DISPLAY TEMP This would output the profitability calculated by the expert system, the optimum number of X and Y to produce and the total profitability. It uses the technique of creating a file and then immediately displaying it. 5. Run the system. Suppose that the expert system calculates a value of 2 for [PROFIT X] and 3 for [PROFIT Y]. When we build the LINDO model, these values will be put in it to produce MAX 2X + 3Y ST 4X + 3Y < 10 3X + 5Y < 12 LINDO will use this model to calculate the optimum values for X and Y. This will be put in a temporary file, which EXSYS will parse for the information request to be assigned to EXSYS variables. The values 1.272727 and 1.636364 will be assigned to [X PER DAY] and [Y PER DAY], respectively. The [TOTAL PROFIT] variable will be given a value of 7.4545.

N - LINDO INTERFACE

14

Using the report generator to format these results, the end user will see the following: OPTIMUM POINT OF OPERATION Current Profitability: Profit from product X = 2 Profit from product Y = 3 Optimum Point of Production Number of X to produce per day = 1.272727 Number of Y to produce per day = 1.636364 -----------------------------------Total profit per day = 7.4545 The user did not have to build an LP model or understand the results file produced by LINDO. The user only had to answer the questions in the expert system. The EXSYS/LINDO interface did the rest.

N - LINDO INTERFACE

15

Chapter O Utility Programs O1: Compressing Edited Files


Note: The effects of SHRINKP are irreversible so always run SHRINKP on a backup copy of the knowledge base, never on your only copy. When you are developing an expert system knowledge base it is frequently necessary to edit rules, correct typos, etc. This leads to some wasted space in the .TXT file. The utility program SHRINKP.EXE compresses the .TXT file by eliminating no longer needed text and then rearranging the file so that the order allows the most rapid access to the text. SHRINKP also eliminates all unused variables and formulas. It is not necessary to run SHRINKP very often, but once a knowledge base has been fully developed it is a good idea to use SHRINKP to put the base in its best possible form. To use SHRINKP, click on the SHRINKP icon and select the file to shrink. SHRINKP needs extra space on the disk while it is rearranging the data. The disk must have enough space on it for an extra copy of the .TXT and .RUL files you are shrinking. SHRINKP will remove any unused formulas or variables and renumber the variables that remain. If your expert system calls an external program for multiple variables, be sure to check that the numbers of the variables receiving data from the external program are still correct. You may have to modify the external program to reflect the new variable numbers or pass the data by variable name rather than number.

O - UTILITY PROGRAMS

O2: Rule Organizer


Note: The effects of FASTERP are irreversible so always run FASTERP on a backup copy of the knowledge base, never on your only copy. The time it takes for a set of rules to execute in backward chaining is highly dependent on the order and arrangement of the rules and the amount of backward chaining required for derivations. In most knowledge bases, the rules are not arranged in such a way that the program runs as fast as possible. In small knowledge bases this is not a problem, since the rules will still execute very quickly. In very large knowledge bases, however, there can be a significant delay in running the rules if they are arranged poorly. The utility program FASTERP will rearrange the rules in a BACKWARD CHAINING knowledge base to make it run faster. The difference can be very significant. In one test of a large set of rules, FASTERP was able to improve execution speed by a factor of 20. Note: FASTERP will have no beneficial effect on forward chaining systems and may even create a rule order inappropriate to forward chaining. To run FASTERP, click on the FASTERP icon. The rearranged rules will then be stored in a new file, written over the old version (Always run FASTERP on a backup copy, just in case). Once the rules have been rearranged, your expert system may ask you questions in a different order than it did previously; however, the program should come to the same conclusions. If, after running FASTERP, the program reaches different conclusions with the same input data, there is a logic error in the rules or an incomplete set of rules. Examine how the conclusions were reached in each case to see where the difference occurred. The following are errors that can cause differences: 1. The "use only first rule" option was chosen and there are rules that allow the same input data to result in different values being assigned to a qualifier depending on which rule is found first. 2. The rules allow the same input data to have valid rules that give a 0 and a 10 to the same choice. The first one found locks the value. 3. Calculations with numeric variables can be dependent on the order in which the calculations are executed.
O - UTILITY PROGRAMS
2

It is possible to use FASTERP to find errors in the logic of the rules. If after running FASTERP, the same data produces different results, there is probably an error of logic that is in both the old and new rule arrangements. You may find FASTERP useful as a rule checking utility. Experiment with it. If speed is a major factor in your expert system, arrange the rules to use the FORWARD and NOBACKWARD options. This will be MUCH faster than any backward chaining arrangement, even if you optimized with FASTERP.

O3: Moving Files Between Operating Systems


The EXSYS Professional programs running on MS-DOS, UNIX and VAX/VMS computers all use the same knowledge base structure. It is therefore possible to move knowledge bases between operating systems without modification. Unfortunately, it is sometimes difficult to get an identical copy of the .RUL and .TXT files when they are moved between machines. More importantly, the alignment of elements of data structures is different on some machines. In order to avoid these problems, the recommended approach is to print the rule in rule compiler format. This produces a simple ASCII text file. Move this file along with any .CMD, .SCR, .HLP, .CFG etc. files to the target machine. Re-compile on the target machine using the EXSYS Rule Compiler.

O - UTILITY PROGRAMS

O4: Pager
Note: PAGER is not supported on all operating systems PAGER is used in the report generator when you want to print or display a file with headers and page numbers and/or separated into pages. You would generate and close a file with the report generator. This file would contain the information used by PAGER. You would then call the PAGER program from the report generator to generate the file with the page breaks and headers. The syntax is PAGER input_file output_file left_margin body_length [page_length] PAGER reads the input file and generates the output file with page breaks and margins. input_file output_file left_margin File to read; generated with the report generator. File with page formatting. Column number where the first character of the line starts. Use a value of 1 for no margin. Number of lines to be printed in the body of the page. Must be greater than 0. Total number of lines on a page. If set, this will write blank lines to fill the rest of the page instead of form feeds. The page length must be greater than the number of lines in the header or it will print pages with only a header. The page length should be greater than the body length + header length. This parameter is optional.

body_length page_length

Commands can also be put in the input_file to change the parameters set during formatting. This allows sections of the report to be formatted in different ways. The page header and page number commands can only be set as commands in the input_file. The syntax for the commands in the input_file are
O - UTILITY PROGRAMS

>>left_margin=# >>body_length=# >>start_page_header >>end_page_header >>page_number

Change the left margin. Change the body length. Start the definition of a page header. End the definition of a page header. Print page number.

Note: All commands must start at the beginning of a line except >>PAGE_NUMBER.

Right Margin
The right margin is not set by PAGER. It is up to you to make sure the lines are not too long. If you are using the report generator, you can insure this by using the WIDTH command in EXSYS.

Headers
If you do not define a header, PAGER will not insert any page breaks. You can define a header at any time. You can change it at any time. A header is defined when PAGER encounters text starting with >>start_page_header. The text following this command, up to a line starting with >>end_page_header, will be used as the header for each page. You can include the page number in the header by using the command >>page_number anywhere in the header text. The ">>page_number" will be replaced by the actual page number in the formatting. For example: >>start_page_header Expert System Report EXSYS Inc. PAGE: >>page_number ___________________________________________ _ >>end_page_header If you do not want a header printed but you do want page breaks then define a header that has no text or blank lines.

Lines Per Page


If the number of lines printed on the page so far exceeds the body_length, then PAGER will break the page. If you specified the page_length, then it will fill the rest of the page with blank line; otherwise, it will print a form feed.

O - UTILITY PROGRAMS

If you do not specify a page_length or a header and print more than a page of text, then the page numbers will not be accurate. This is because PAGER cannot tell if it has reached the end of a page. It cannot go by body length because, without a header, there is no body. You can change the margins, header or body length at any time. If you change the body length, it will not go into effect until the next top of page.

Page Break
You can force a page break anywhere by putting a form feed in the file. To do this from the report generator use "@@012" (include the quotation marks). Do not put a form feed in a header (it causes an infinite printout). Do not put any text between a form feed and the end of that line (it will not be printed). You may put text before a form feed but if this file is viewed on the computer screen, it could have a line that runs off the screen. It will print correctly, however.

O - UTILITY PROGRAMS

O5: EX_TIME
Note: EX_TIME is not supported on all operating systems The Utility EX_TIME is used when you want a formatted time or date displayed. You can display the time as either a string or a numeric. You can control the format of the output time/date string by passing EX_TIME a format string. The reserved command words occurring in the format string will be substituted for the appropriate value. All the other characters in the format string will be unchanged. The syntax of the call is EX_TIME format_string [time_in_seconds] EX_TIME writes to the file return.dat. The output is the time value formatted by the format_string specified. format_string time_in_seconds The commands that specify how to format the output string. The time value to format in seconds. This parameter is optional. If it is not specified then the current time is used.

Format_strings are made up of command words and any other text which is not a command word. Command words are replaced by their value. All other text is repeated exactly as it appears and in the same place in the string. The following are command words recognized in the format string: Month month Mon mon Month# month# The full month name, capitalized. For example, August The full month name, not capitalized. For example, august The abbreviated month name, capitalized. For example, Aug The abbreviated month name, not capitalized. For example, aug The number of the month, with leading 0's. For example, 08 The number of the month, without leading 0's. For example, 8
O - UTILITY PROGRAMS

Weekday weekday Day day Day# day# year year# sec# seconds min# hour# hour am_pm Am_pm

The full day name, capitalized. For example, Tuesday The full day name, not capitalized. For example, tuesday The abbreviated day name, capitalized. For example, Tues The abbreviated day name, not capitalized. For example, tues The number of the day, with leading 0 if proper. For example, 05 The number of the day, without leading 0's. For example, 5 The full numbers for the year. For example, 1989 The shortened number of the year. For example, 89 The number of seconds past the last minute. For example, 05 The number of seconds since 1970. For example, 113457705 The number of minutes past the last hour. For example, 35 The number of hours. For example, 12 The number of hours military time. For example, 24 Either am or pm. not capitalized. For example, am Either AM or PM capitalized. For example, AM

For example, suppose the time is October 13, 1989 at 5:00pm. EX_TIME "hour#:min# month#/day#/year#" would return "5:00 10/13/89." EX_TIME "Month day#, year at hour#:min#" would return "October 13, 1989 at 5:00." EX_TIME "Weekday the day#, hour# am_pm" would return "Friday the 13, 5 pm."

O - UTILITY PROGRAMS

To use EX_TIME from within EXSYS, call it like any other external program. The formatted string will be returned in return.dat to a variable. For example, you could have a string variable [DATE] with an associated call to EX_TIME to get a formatted time string RUN(EX_TIME ......) This could be used from the report generator or anywhere the formatted string was needed. It could be embedded in other strings using the [[ ]] parameter replacement. EX_TIME can also be used with the results of the EXSYS function AGE which returns the number of seconds since a variable value was set.

O - UTILITY PROGRAMS

O6: Repeat
Note: REPEAT is not supported on all operating systems. The utility REPEAT will perform the command N times where you specify the command and N. The syntax of the call is: REPEAT num_times_to_repeat command_to_repeat

REPEAT will execute the command as many times as specified by num_times_to_repeat. Here is an example: REPEAT 3 "COPY REPORT.DOC PRN > NUL" This copies the report to the printer 3 times and doesn't print the "1 file(s) copied" message by redirecting it to NUL. One problem you may encounter is that DOS sometimes modifies parameters passed to programs. It will delete characters like ". It will change characters like ; into a space. It will convert a parameter with spaces into many parameters. To pass a string containing a space, put the entire parameter in quotes as shown above.

O - UTILITY PROGRAMS

10

O7: EXSQ - Report File Squeezer


Note: EXSQ is not supported on all operating systems.

Introduction
The purpose of EXSQ is to reformat and squeeze down reports generated by the EDITXSP expert system editor so that they are more readable and require less paper. The results are also suitable for formal documentation needs, including Copyright applications. EXSQ requires as input a report generated with the EDITXS "PRINT" option, which was directed to a disk file rather than straight to the printer. EXSQ supports Epson dot matrix printers, Hewlett-Packard laserjet printers and IBM dot matrix printers.

How to use EXSQ


If you simply invoke EXSQ by typing its name at the DOS prompt, it will come up in an interactive mode, requesting the file name and your type of printer. Alternatively, you can specify all needed information on the command line, as follows: EXSQ filename options "Filename" is the name of the EXSYS report you want to squeeze. The following are available options: /E (for Epson dot matrix printers) /H (for Hewlett Packard laserjet printers) /I (for IBM dot matrix printers) If your printer is not one of the above, place it in a compatibility mode that matches one of the above. Note about HP Laserjets: After printing a squeezed report file, your "form feed" light may stay on. This should not cause any problems. EXSQ leaves the laserjet set for courier font, 10 characters per inch horizontal, 6 lines per inch vertical. EXSQ will generate the file SQ.PRN, which contains the squeezed version of the report with control characters for the printer.

O - UTILITY PROGRAMS

11

Note: EXSQ never removes the SQ.PRN file; if the file exists, it always appends the existing file. Therefore, you can squeeze a bunch of rule bases and print them out all at once. It's up to you to delete the sq.prn file whenever appropriate. The SQ.PRN file can be copied to the printer. The format control codes for the printer are already embedded in the file. To print the file, just enter COPY SQ.PRN PRN

Demonstration
You may try out EXSQ on a sample rule base report by entering the following command line at the DOS prompt (replace "/p" with /E, /H, or /I, as explained in "How to use EXSQ"): EXSQ SAMPLE.PRN /p When EXSQ finishes, you may print the results either with the DOS PRINT command or via the COPY statement as below (put your printer in EPSON mode): COPY SQ.PRN PRN

O - UTILITY PROGRAMS

12

Chapter P SQL Commands Introduction


Standard Query Language (SQL) is a method of manipulating and viewing information stored in databases. SQL language was developed by IBM in the mid-1970s. This language is independent of the database system that resides on the user's computer. EXSYS Professional has a SQL interface that allows the developer to issue SQL commands to a large number of commercial database products. The currently supported databases are:
ALLBASE Betrieve Clipper Database Manager DB2 DB2/2 DB2/6000 dBase II, III, IV,V Excel 5.0 Excel .XLS files FoxBase FoxPro Gupta SQLBase IMAGE/SQL INFORMIX INGRES InterBase Microsoft SQL Server NetWare SQL Oracle Paradox PROGRESS SQLBase SQL/400 SQL/DS Sybase SQL Server Sybase System 10 Teradata Text files XDB

Note: EXSYS Products use third party libraries for the database support. The above list will grow. See the READ.ME on your distribution disks for the databases currently supported.

P1: Installation
The EXSYS interface to the databases is made through a third party library of functions from Intersolv (Q+E Software). The connection to the database is made through the Q+E DLL (dynamic link libraries) which must be installed on your computer. There are two groups of DLLs related to SQL. A base group of DLLs is required for EXSYS tools to load and run - even if a system does not call for an SQL interface. These DLLs are loaded during the normal EXSYS install procedure.

P - SQL COMMANDS

In addition to the DLLs provided with EXSYS, an ODBC compliant DLL for the specific database used is required. Because of licensing restrictions, this ODBC layer is NOT provided with EXSYS. The ODBC DLL layer may be obtained from Intersolv as their "ODBC Pack" which includes the DLLs for all the databases, or the DLL for a specific database may be obtained from Intersolv. ODBC compliant DLLs from other companies are also supposed to work that is the whole idea of ODBC - however, EXSYS Inc. recommends using the ODBC DLLs from Intersolv. An ODBC compliant DLL for the specific database being used must be present to make use of the SQL commands in EXSYS. Intersolv has a variety of licensing arrangements for distribution of the specific database DLLs within a company. Intersolv can be reached at:

Intersolv 5540 Centerview Drive, Suite 324 Raleigh, NC 27606 TEL: (919)859-2220

If your application does NOT make use of the EXSYS SQL commands, all required DLLs are provided with the EXSYS software and can be distributed with your application.

IMPORTANT NOTE: Unless specific arrangements are made with Intersolv, you are not licensed to distribute the Q+E "ODBC Pack" DLLs to others.

P - SQL COMMANDS

Installation:
Copy all DLL files from the EXSYS Professional Ver. 5.0 diskettes to the \WINDOWS\SYSTEM directory. Install the Q+E ODBC Pack software according to the manufacturer's instructions. To define a Data Source: Click on the ODBC icon in the WINDOWS Control Panel. Under DATA SOURCES, choose ADD. Under ADD DATA SOURCE, select database type. Under ODBC <database type> DRIVER SETUP: Enter <database type source name>* in DATA SOURCE NAME. Enter a working directory, if known. Enter other information as appropriate. CLOSE/EXIT all the way out. * Database type source names are found in the READ.ME on your distribution disks.

P1.1: SQL Interface Technical Support


The Q+E Database Driver Reference provides details on the connection to various commercial databases and SQL commands supported. If you have any difficulty using the SQL commands contact EXSYS Tech Support first. EXSYS will determine if a problem is in the EXSYS software or in the Intersolv Q+E product. If the problem is in the connection between the Intersolv DLL and your database, it may be more efficient for you to contact Intersolv directly. Intersolv will provide direct support only to licensed users of their DLL, so this another reason to obtasin your ODBC layer from Intesolv.

P1.2: Backward Compatibility


While the DLLs required for EXSYS Professional Ver. 5 and EXSYS RuleBook PLUS have changed, the actual EXSYS SQL Interface commands have NOT. SQL commands or command files created for EXSYS Professional Ver. 4 or earlier should work the same way in Ver. 5. If any differences are encountered, it is probably due to differences in the way the Intersolv ODBC connects to your database or to EXSYS. If you find any differences in system function, call EXSYS technical support for assistance.

P - SQL COMMANDS

P2: SQL Commands


The SQL interface in EXSYS has two basic modes of operation: 1. Associating an SQL call for a single element of data with an EXSYS variable. This is done with a single EXSYS command that can be associated with a variable or used in the command language. 2. Issuing an SQL command which may produce multiple records which may each have multiple fields. Since multiple items of data are returned, the data can not be directly assigned to a single EXSYS variable. In this case, a series of commands in the command language enables you to sequentially read the data and assign it sequentially to the same EXSYS variable, or to multiple variables. The commands to do this can only be issued from the command language.

P2.1: Reading a Single Item of Data into a Single EXSYS Variable


SQL_READ_ONE("Connection String", "SQL Command", "Format string", [EXSYS VAR to Assign Value to])

Reads a single value from a data base with an SQL call. This should be used when limited SQL access in needed, or to associate an SQL call with a variable. This command is also designed to return only a single value. Only the first column of the first record returned will be assigned to the variable - even if there are multiple records returned. For multiple record assignments, use the other SQL commands. This command is most useful when used as a data acquisition command associated with a variable. It is the only SQL command that is practical to use this way. Connection String The SQL connection string. This identifies the database, server, or password. This is currently the same connection string in the command SQL_CONNECT() command. The SQL command to issue. This must be a legal SQL command for the database that has been opened. See the Q+E Database Driver Reference for legal SQL commands for each supported database. The format string for the returned data. See the Intersolv documentation provided with their "ODBC Pack" on formats supported for specific databases.

SQL Command

Format String

P - SQL COMMANDS

EXSYS Variable

This is the EXSYS variable to assign the data to. If the EXSYS variable is a string variable, the data will be assigned as a string. If it is a numeric variable, the value will be converted to a numeric value and stored. The EXSYS variable name must be in square brackets.

The SQL_READ_ONE command can be associated with a variable by using it as a data acquisition command. To do this, precede the prompt text of the variable with the SQL_READ_ONE command. Be sure that the EXSYS variable specified in the SQL_READ_ONE command matches the variable it is a data acquisition command for. The command can also be used independently in the command language to assign data. Since this command, connects and disconnects from the data base each time, it is much less efficient than multiple SQL reads during a single connection. If many items of data are to be read, it is better to connect to the data base, make multiple reads and then disconnect.

P2.2: SQL Commands that Return Multiple Items of Data


SQL commands can often return multiple items of data and multiple fields. To sequentially read this data and assign it to EXSYS variables requires a series of operations. You must: 1. Connect to the database desired. 2. Issue an SQL command that will return data. 3. Make one of the records of returned data the currently active record. 4. Assign a field from the returned data to an EXSYS variable. 5. Repeat step 4 until all of the data needed for the expert system processing is assigned and run the expert system rules. 6. If necessary return to step 3 and make another record of returned data active, read more data and continue processing. 7. When all of the data needed from the SQL command has been processed, indicate that the SQL command is done. You may then issue another SQL command and continue processing. (This is important for releasing resources.) 8. Indicate that the connection to the database is no longer needed. (This is important for releasing resources.)
P - SQL COMMANDS

These operations are performed in the EXSYS command languages, although step 5 can also be used as a data acquisition command associated with a variable. EXSYS supports simultaneous connections to multiple databases and simultaneous SQL commands. In order to specify which database or SQL command is being referred to, EXSYS variables are used to carry identifier information. When you connect to a database or issue an SQL command, a value is put in a special EXSYS variable. This variable is then used in other commands to specify the database or SQL command.

P3: Connecting to the Database


SQL_CONNECT("Connection String", [EXSYS VAR for DB ID]) Connects to the database. Connection String sets the connection parameters and selects the type of database. [EXSYS VAR for DB ID] is used by other commands. Connection String The SQL connection string. This identifies the database, server, and/or password. See the following information on connection strings and the Intersolv documentation provided with their "ODBC Pack" for details on connection strings for each database. This is an EXSYS variable that will be assigned a value to use as an identifier for the database opened. This identifier will be valid until the database is closed. This variable does not need a value before the call is made.

[EXSYS VAR for DB ID]

P - SQL COMMANDS

P3.1: Connection Strings


When you connect to a database, a connection string must be specified to tell EXSYS the specific database being used. Some data bases also require other optional parameters. For the current list of connection strings and their associated databases (for Version 5.0 ODBC), see the READ.ME file on your EXSYS distribution diskettes. For example, if you wanted to connect to Paradox, the connect command would be: SQL_CONNECT("PARADOX", [ID]) The name of the database must be exactly as listed above, and must be in quotes. Some databases allow / require additional information to be specified. See the Q+E Database Driver Reference for details on your specific database. The user ID, server and password can be specified by adding options to the connection string with the database name: User ID: Password: Server: -U:name -P:password -S:server

For example, suppose we were connecting to Oracle running on a server and we wanted to specify our user ID and Password: SQL_CONNECT("ORACLE -U:myname -P:mypass -S:server", [ID]) Many of the more powerful databases require the server, user ID and password. If you do not know the user ID, or do not want to hard code a password into the expert system, you can use the -DIALOG option. This will cause a dialog to appear when the SQL_CONNECT is executed. The dialog will prompt the user for their password, etc. The -DIALOG command can be used in conjunction with other options. For example, you might specify the server with a -S:server but not specify the user or password. This would look like: SQL_CONNECT("ORACLE -S:server - DIALOG", [ID])

Some databases may support other options in the connection string. These are added into the string with no prefix. For details on the specifics of connecting to each of the databases supported, see the Q+E Database Driver Reference.
P - SQL COMMANDS
7

P4: Executing an SQL Command


SQL_EXEC([EXSYS VAR for DB ID], "SQL Command", [EXSYS ID for Ret Data]) Makes the call to the specified database to select record(s). This command only selects the appropriate records. It does not make any specific record active. [EXSYS VAR for DB ID] This is the EXSYS variable that was assigned a value in the SQL_CONNECT() command. It identifies the database that the SQL call is being made to. An SQL command appropriate for the database selected. See the Intersolv documentation for their "ODBC Pack" for the SQL commands supported for each of the databases. This is an EXSYS variable that will be assigned a value to use as an identifier for the data returned from the specific SQL command. This identifier will be valid until the SQL command is closed. This variable does not need a value before the call is made.

SQL Command

[EXSYS ID for Ret Data]

P4.1: Selecting the Next Record of Returned Data


SQL_NEXTREC([EXSYS ID for Ret Data], [EXSYS Test Flag Var]) This command makes the next record of the data returned by the SQL call into the active record. The fields in this record can then be accessed with the SQL_VALUES command. If no previous commands have been executed to set an active record, the first record that was returned by the SQL command will be made active. [EXSYS Test Flag Var] will be 0 on successfully reading the record. [EXSYS ID for Ret Data] This is the EXSYS variable that identifies the specific SQL command that returned data. This identifier was set by the SQL_EXEC() command.
8

P - SQL COMMANDS

[EXSYS Test Flag Var]

This is an EXSYS variable that will be assigned a value of 0 if the command was successfully executed. A non-zero value indicates that there are no more records to read or an error occurred. If there was an error, a separate error message will be displayed. Testing for a non-zero value can be used in a WHILE loop in the command language to indicate that all records have been processed.

P4.2: Selecting the Previous Record of Returned Data


SQL_PREVREC([EXSYS ID for Ret Data], [EXSYS Test Flag Var]) This command makes the previous record of the data returned by the SQL call into the active record. The fields in this record can then be accessed with the SQL_VALUES command. If no previous commands have been executed to set an active record, the command will fail. [EXSYS Test Flag Var] will be 0 on successfully reading the record. The command SQL_REC_OPTIONS must have been called immediately after SQL_EXEC for this command to be active. [EXSYS ID for Ret Data] This is the EXSYS variable that identifies the specific SQL command that returned data. This identifier was set by the SQL_EXEC() command. This is an EXSYS variable that will be assigned a value of 0 if the command was successfully executed. A non-zero value indicates that there are no more records to read or an error occurred. If there was an error, a separate error message will be displayed. Testing for a non-zero value can be used in a WHILE loop in the command language to indicate that all records have been processed.

[EXSYS Test Flag Var]

P - SQL COMMANDS

P4.3: Selecting a Random Record of Returned Data


SQL_RANDREC([EXSYS ID for Ret Data], recnum, [EXSYS Test Flag Var]) This command makes a random record of the data that was returned by the SQL call into the active record. The fields in this record can then be accessed with the SQL_VALUES command. [EXSYS Test Flag Var] will be 0 on successfully reading the record. The command SQL_REC_OPTIONS must have been called immediately after SQL_EXEC for this command to be active. [EXSYS ID for Ret Data] This is the EXSYS variable that identifies the specific SQL command that returned data. This identifier was set by the SQL_EXEC() command. The number of the record to make active. This should be a value between 1 and the total number of records returned by the SQL_EXEC command. This is an EXSYS variable that will be assigned a value of 0 if the command was successfully executed. A non-zero value indicates that there are no more records to read or an error occurred. If there was an error, a separate error message will be displayed. Testing for a non-zero value can be used in a WHILE loop in the command language to indicate that all records have been processed.

recnum

[EXSYS Test Flag Var]

P4.4: Finding the Number of Records of Returned Data


SQL_NUMREC([EXSYS ID for Ret Data], [EXSYS VAR for number of records]) Returns the number of records returned by the SQL statement into [EXSYS VAR for number of records]. The command SQL_REC_OPTIONS must have been called immediately after SQL_EXEC for this command to be active.

P - SQL COMMANDS

10

[EXSYS ID for Ret Data]

This is the EXSYS variable that identifies the specific SQL command that returned data. This identifier was set by the SQL_EXEC() command. This is an EXSYS variable that will be assigned the number of records returned by the specified SQL command.

[EXSYS Var for number of records]

P4.5: Creating Random Access Buffers for Returned Data


SQL_REC_OPTIONS([EXSYS ID for Ret Data]) Sets up buffers for many data bases to support SQL_RANDREC, SQL_PREVREC, and SQL_NUMREC. This may require significant amounts of disk space for large sets of records. This command must be called immediately after SQL_EXEC. If this command fails, an error message will be displayed. DO NOT use this command unless SQL_RANDREC, SQL_PREVREC, or SQL_NUMREC are required. SQL_NEXTREC does not require this command. [EXSYS ID for Ret Data] This is the EXSYS variable that identifies the specific SQL command that returned data. This identifier was set by the SQL_EXEC() command.

P4.6: Releasing the Data Returned from an SQL Command


SQL_END_SQL([EXSYS ID for Ret Data]) Ends commands for data associated with the SQL command associated with [EXSYS ID for Ret Data]. Memory used for files / data associated with the SQL command will be released. After this command is executed, the EXSYS variable [EXSYS ID for Ret Data] should not be used until another SQL_EXEC reassigns it a value. [EXSYS ID for Ret Data] This is the EXSYS variable that identifies the specific SQL command that returned data. This identifier was set by the SQL_EXEC() command.
11

P - SQL COMMANDS

P4.7: Disconnecting from a Database


SQL_DISCONNECT([EXSYS Var for DB ID]) Disconnects from the database associated with [EXSYS VAR for DB ID] which was obtained from SQL_CONNECT. After this command is executed, the EXSYS variable [EXSYS VAR for DB ID] should not be used until it is reassigned a value with another SQL_CONNECT command. [EXSYS VAR for DB ID] This is the EXSYS variable that was assigned a value in the SQL_CONNECT() command. It identifies the database that the SQL call is being made to.

P4.8: Reading a Specific Field of Returned Data


SQL_VALUES([EXSYS ID for Ret Data], column number, format, [EXSYS Var for Data]) This command assigns the data in a specified field (column) of the active record in the data returned by the SQL command. The value is stored in [EXSYS VAR for Data]. If [EXSYS VAR for Data] is a string variable, the value will be stored as a string. If [EXSYS VAR for Data] is numeric, the value will be converted to numeric. "Format" allows formatting of date strings and should only be used with EXSYS string variables. The most general format string is "". [EXSYS ID for Ret Data] This is the EXSYS variable that identifies the specific SQL command that returned data. This identifier was set by the SQL_EXEC() command. The column (field) number of the data to be assigned. Numbers start at 1. A format string to specify the formatting of data. See the Q+E Database Driver Reference. The most general format string is "". Format strings other than "" should only be used when assigning data to an EXSYS string variable.
P - SQL COMMANDS
12

column number

format

[EXSYS Var for Data]

This is the EXSYS variable that will be assigned the data. If the variable is a string variable, the value assigned will be converted to a string. If it is a numeric, it will be converted to a numeric.

P4.9: Reading the Name of a Column of Returned Data


SQL_COL_NAME([EXSYS ID for Ret Data], column number, [EXSYS VAR for Data]) Returns the name of the specified column (field) in the records returned by the SQL command. This value is stored in [EXSYS VAR for data], which must be a string variable. [EXSYS ID for Ret Data] This is the EXSYS variable that identifies the specific SQL command that returned data. This identifier was set by the SQL_EXEC() command. The column (field) number that you want the name of. Numbers start at 1. This is the EXSYS variable that will be assigned the data. The variable MUST be a string variable.

column number [EXSYS Var for Data]

P4.10: Reading the Number of Columns of Returned Data


SQL_NUM_COLS([EXSYS ID for returned data], [EXSYS Var for Data]) Returns the number of columns (fields) in the records returned by the SQL command. Value is stored in [EXSYS Var for Data], which must be a numeric variable. [EXSYS ID for Ret Data] This is the EXSYS variable that identifies the specific SQL command that returned data. This identifier was set by the SQL_EXEC() command. This is the EXSYS variable that will be assigned the number of columns (fields) . The variable MUST be a numeric variable.
13

[EXSYS Var for Data]

P - SQL COMMANDS

P5: Transactions
Many SQL databases support transactions. This allows a series of SQL commands to be executed that would modify the database, but not have the modification actually made until the commands are committed. If for some reason, a decision is made to not actually change the database, the commands can be canceled without changing the actual database. Note: Not all databases support transactions. To execute transactions: 1. Call SQL_BEGIN_TRANS() 2. Execute SQL commands. 3. If the changes are to be made execute a SQL_COMMIT before closing the database. If the changes are to be canceled, execute a SQL_ROLLBACK.

P5.1: Beginning a Transaction


SQL_BEGIN_TRANS([EXSYS VAR for DB ID]) Marks the start of a transaction with the database associated with [EXSYS VAR for DB ID] . Any modifications to the database will not be actually made until a SQL_COMMIT is encountered. A SQL_ROLLBACK will cancel all modifications made following the SQL_BEGIN_TRANS. An error will produce an error message. [EXSYS VAR for DB ID] This is the EXSYS variable that was assigned a value in the SQL_CONNECT() command. It identifies the database that the SQL call is being made to.

P5.2: Committing a Transaction


SQL_COMMIT([EXSYS VAR for DB ID]) Commit modifications made to the database associated with [EXSYS VAR for DB ID]. All modifications made following the SQL_BEGIN_TRANS will be made to the database. An error will produce an error message. [EXSYS VAR for DB ID] This is the EXSYS variable that was assigned a value in the SQL_CONNECT() command. It identifies the database that the SQL call is being made to.
14

P - SQL COMMANDS

P5.3: Canceling a Transaction


SQL_ROLLBACK([EXSYS VAR for DB ID]) Cancel modifications made to the database associated with [EXSYS VAR for DB ID]. All modifications made following the SQL_BEGIN_TRANS will be canceled. An error will produce an error message. [EXSYS VAR for DB ID] This is the EXSYS variable that was assigned a value in the SQL_CONNECT() command. It identifies the database that the SQL call is being made to.

P6: Using SQL Commands


Reading a single item of data into an EXSYS variable
Use the Data Acquisition command to associate a SQL_READ_ONE command with the EXSYS variable. Select "Data Acquisition" from the dialog box for adding / editing variables. Select "SQL Interface" and a dialog box will be displayed. Select the database type. Enter any required options for that database, and the SQL command to execute. Normally the SQL command will be a SELECT command. The first item of data returned by the SQL command will be assigned to the EXSYS variable. If string data is being returned, be sure that the EXSYS variable is a string variable.

Using the SQL commands in a Command File


Frequently SQL SELECT commands return multiple records. Stepping through these records is a procedural operation, so it is done in the Command Language. In the .CMD file, connect to a data base with the SQL_CONNECT command. Execute an SQL command with the SQL_EXEC command. If the command was a SELECT command, you may then step through the returned data one record at a time and apply the expert system rules to the data. For example: 1 2 3 4 SQL_CONNECT("PARADOX", [DB ID]) SQL_EXEC([DB ID], "SELECT * FROM ACCTS WHERE DAYS_LATE >30", [CMD ID]) SQL_NEXTREC([CMD ID], [TEST FLAG]) WHILE ([TEST FLAG] == 0)
P - SQL COMMANDS
15

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

SQL_VALUES([CMD SQL_VALUES([CMD SQL_VALUES([CMD SQL_VALUES([CMD SQL_VALUES([CMD SQL_VALUES([CMD

ID], ID], ID], ID], ID], ID],

1, 2, 3, 4, 5, 6,

"", "", "", "", "", "",

[NAME]) [ACCT NO]) [MAX]) [MIN]) [AVG]) [DAYS LATE])

CLEAR R ALL CLEAR Q ALL CLEAR C ALL RULES ALL REPORT SQLDEMO.OUT SQL_NEXTREC([CMD ID], [TEST FLAG]) WEND SQL_END_SQL([CMD ID]) SQL_DISCONNECT([DB ID]) Note: The line numbers are not part of the command file and are included here only to allow easy reference to a line.

In this example, line 1 connects to the Paradox database DLL. The variable set in line 1, [DB ID] will be used in subsequent SQL_EXEC commands. Line 2 executes an SQL SELECT command to return data. The EXSYS variable [CMD ID] will be used in subsequent commands to refer to this data. Line 3 sets the next (in this case the first) record of data returned by the select command. The test flag variable [TEST FLAG] will be set to 0 if there was data returned and the commands enter the While loop in line 4. Lines 5-10 assign data to specific EXSYS variables. Lines 11-13 clear out all previous data and the rules are run in line 14. A report of the results of the system for the first record of data is output by line 15. Line 16 attempts to make the next record of data active. If there was another record of data returned by the SQL command in line 2, the value of [TEST FLAG] will be set to 0 and the While loop in line 4 will repeat. When the last record of data had been analyzed, the value of [TEST FLAG] will not be 0 and the while loop will end. Line 18 releases the memory associated with the SQL command from line 2. Line 19 disconnects EXSYS from the database.

P6.1: Some Basic SQL Commands


The following commands are the some of the basic commands used in SQL. Not all databases support all commands. There are MANY more commands supported by powerful database programs. Consult your database documentation and the Intersolv documentation that came with the Q+E Database Driver Reference for details on supported commands for specific databases.
P - SQL COMMANDS
16

SELECT
The SELECT command is used to retrieve records from the database. All databases support this command to some extent. Paradox and dBase, among others, fully implement it. The basic form of the command is: SELECT {* | field, ...} FROM filespec [additional clauses] One or more fields can be specified. Additionally, clauses can be used to further refine the search. One common, and useful, clause is WHERE. For example: SELECT * FROM dbname WHERE field > x

This command will return all fields of all records where a specified field value is greater than x. SELECT supports aggregate functions such as MIN, MAX, and AVG. Thus, the total of a particular column, where certain conditions are met, can be returned.

INSERT
The INSERT command is used to add new records to the database. The basic form is: INSERT filespec (field, ...) VALUES (expr, ...) One or more fields and values (expressions) can be specified.

UPDATE
The UPDATE command is used to change records in the database. The basic form is: UPDATE [WHERE filespec SET | CURRENT OF] field=expr, ...

One or more fields and values can be specified.

P - SQL COMMANDS

17

DELETE
The DELETE command is used to delete records in the database. The basic form is: DELETE FROM filespec [WHERE | CURRENT OF]

CREATE TABLE
This command is used to create new database files. The basic form is: CREATE TABLE def, ...) filespec (field def, field

DROP TABLE
This command is used to delete database files. The basic form is: DROP TABLE filespec

P - SQL COMMANDS

18

Chapter Q ExDesign Custom Screen Design Program Q1: Introduction


ExDesign is a versatile and easy-to-use utility for creating EXSYS Professional GUI custom screens for data input, custom help and hypertext screens. ExDesign allows the user to avoid having to create EXSYS Custom Screens "by hand", using a text editor. This helps anyone who wishes to create an EXSYS Custom Screen to avoid having to memorize EXSYS Custom Screen Language syntax. As one selects and places the chosen Custom Screen Objects on the ExDesign Work Screen, the program automatically generates the correct syntax in the custom screen file. Also, the user can directly manipulate the position and size of these objects as they refine their design. Other Attributes can be adjusted via pull-down menus and dialog boxes. ExDesign is also useful for modifying or updating existing EXSYS Custom Screens. It has built-in facilities for checking the syntax of the existing screens in a pre-created screen file as they are loaded. This makes it a useful debugging aid.

Q2: Master System Help


Help is available at any time from the main work screen by selecting Help under the Change menu. This calls the Master System Help function. Click on the topic desired and a summary of the syntax for the command will be displayed. Help may also be activated on the Macintosh by selecting the "About ExDesign" menu item (or on other platforms, the "About" menu item under File) and clicking on the Help button.

Q3: File Menu


This menu is used whenever the user needs to create a new screen file, load an existing one or save the currently loaded screen file. It is also used to load another screen in an existing file or add a new screen to a file of existing screens. Finally, it is also used to exit the program.
Q - ExDesign Custom Screen Design Program
1

Q3.1: New
This menu option is used to create a new custom screen file. Until one or more screens are added to the new file, it will be empty. The first thing that ExDesign will require from the user in order to create this file, will be the filename. A window appears immediately after selecting this feature which contains an edit box provided for this purpose. If the filename is typed in with no extension, the program will provide the default .SCR extension. If it is desired that another extension be used, (for example .HLP when creating an EXSYS Custom Help file,) then it must be provided by typing the full name of the file to be created into the edit box. The Open button can then be selected to open a file with the name provided. If the user changes their mind, and decides not to pursue this option further, they can select the Cancel Button. ExDesign will display a message stating that no file was opened, and then return to the main work screen. If the user happens to select a filename that already exists in the current working directory, a window will appear with a message asking if they wish to erase the existing file or cancel the action and return to the main work screen. If they choose to erase the existing file, its contents will be lost. If the user wishes to check the contents of the file before it is erased, they must use the Cancel button to return to the main work screen and then resume by selecting the File Open Menu. If the user wishes to select another working directory in which to open the new screen file, then they should use the scroll bar to move to the end of the list of file and directory names in the list box. If the desired directory is a subdirectory of the current directory, select it when it appears and click on the Open button. That directory will now become the current directory. If the user selects the [..] listing and then clicks on Open, the current directory will be replaced by its parent directory. They can also switch to a directory on another drive by selecting the drive name in the list box and then clicking on the Open button. This process can be continued, even combining the above procedures, until the current directory is set to the one desired. However, when the desired directory is reached, the user will need to enter a valid filename in the edit box, before they can continue to the next step: entering a screen identifier for their first new screen. One may, at any time, exit the process and return to the main work screen by selecting the Cancel button. Once a valid filename has been entered and that file has been opened, then it is necessary to specify an identifier for the first screen that is to be created. A window will appear for this purpose, containing an edit box where the user will need to type in the correct syntax for the screen identifier. This syntax is described in Chapter I of the EXSYS Pro manual.
Q - ExDesign Custom Screen Design Program
2

NOTE: Make sure that the screen identifier begins with a "~" character. Once this screen identifier has been input, click on the OK button. ExDesign will then return to the main work screen where one may begin to create the new screen. It is possible, however, to abort the process by selecting the Cancel button, which will cause ExDesign to display an error message and then exit the program.

Q3.2: Open
This menu option is used to open a existing screen file. The first thing that ExDesign will require from the user in order to open this file will be the filename. A window appears immediately after this feature is selected which contains an edit box provided for this purpose. If the filename is typed in with no extension, the default .SCR extension will be added by the program before it attempts to load the file. If it is desired that another extension be used, (for example .HLP when creating an EXSYS Custom Help file), then it must be provided by typing the full name of the file to be created into the edit box. The Open button can then be selected to open a file with the name provided. If the user changes their mind, and decides not to pursue this option further, they can then select the Cancel Button. ExDesign will then display an message stating that no file was opened, and then return to the main work screen. The way to select another working directory, from which to open the new screen file, varies among the various operating systems. In MS-Windows, use the scroll bar to move to the end of the list of file and directory names displayed in the list box. If the desired directory is a subdirectory of the current directory, select it when it appears and click on the Open button. That directory will now become the current directory. If the user selects the [..] listing and clicks on Open, the current directory will be replaced by its parent directory. It is also possible to switch to a directory on another drive by selecting the drive name in the list box and then clicking on the Open button. This process can be continued, even combining the above procedures, until the current directory is set to the one desired. However, once the desired directory is reached, it will be necessary to enter a valid filename in the edit box. This must be done before one can continue to the next step: entering a screen identifier for the first new screen. Alternatively, the user may select any of the screen files listed in the list box and then select Open. In either case, ExDesign will then attempt to load the indicated file. Also, if, for example, the desired filename cannot be found and it is decided to exit the process before clicking on the Open button, one may return to the main work screen by selecting the Cancel button.

Q - ExDesign Custom Screen Design Program

Once the user has entered a valid filename and that file has been opened, then it will be necessary to select an identifier from the list box of existing screens for the screen that one wishes to edit. If the screen identifier for an existing screen is selected, ExDesign will check the syntax of the custom screen commands as it attempts to execute each command and thereby display that screen object on the main work screen. If it finds a syntax error, it will display a window, indicating the line in the file that it was attempting to execute when it encountered the error. After the user clicks on the OK button, the program will be unable to continue with the selected screen, and ExDesign will abort. If one wishes to add a new screen to the screen file, then the entry "** ADD NEW SCREEN **" should be selected. This entry appears at the end of the screen identifier list. Once this entry is selected, a window will appear containing an edit box enabling the user to enter the new screen identifier. The syntax for EXSYS custom screen identifiers is described on pp. I-5 through I-7 of this manual. (NOTE: Make sure that the screen identifier begins with a "~" character.) Once this screen identifier has been input, select the OK button. ExDesign will then return to the main work screen where the user may begin to create the new screen. If, however, it is decided to abort the process by selecting the Cancel button before inputting a screen identifier, ExDesign will display an error message and then exit the program. If the user has been editing a particular screen file, and wishes to begin editing another screen in that file, (or add a new screen to the file,) then they should follow the above procedures, beginning with selecting the File Open Menu. Using either the procedure for the list of filenames or the edit box provided, give the name of the current file, just as it was originally entered. Then, at the Screen Identifier list box, select the Screen Identifier desired, or "**ADD NEW SCREEN**" to create a new screen and add it to the current file.

Q3.3: Save
This menu option will save the current file using the name under which it was opened. It allows no interaction, and will simply save the file, no questions asked. It is the quickest and easiest way to periodically save the work that has been done in the current ExDesign editing session.

Q - ExDesign Custom Screen Design Program

Q3.4: SaveAs
This menu option enables the user to save the current file under a name that they specify. Either a new name or the current name can be used. By specifying a path that is different than the current directory, the file can even be saved in another directory, even on another drive. Simply, type the name that one wishes to use, with or without a new path, in the edit box in the window that appears. When this is completed, select the OK button. The process may be aborted by selecting Cancel and the program will return to the main work screen without saving the file.

Q3.5: Print
To print the screen file produced, save the screens created, exit ExDesign and print directly from the operating system.

Q3.6 Exit
This menu option enables the user to exit the program and return to the Windows Program Manager. If no changes have been made to any of the screens in the current screen file, it will immediately exit the program. If, however, any of the screens in the current file have been changed since the file was last saved, a dialog box will appear asking the user if they want to discard those changes and exit, or if they want to save them before exiting. The Cancel button will cause ExDesign to return to the main work screen and the user may resume editing, without any other effects upon the screens in the current screen file.

Q3.7: About
Selecting this option brings up a dialog box stating the current version number of the program. If the Help button on this dialog box is selected the Master System Help function will be requested.

Q3.8: Adding a New Screen


To add a new screen, select "New Window" under the "Windows" menu.

Q - ExDesign Custom Screen Design Program

Q4: Object Menu


ExDesign provides two types of objects that can be placed on an EXSYS Custom Input Screen, control objects and graphical objects. Control objects are those that are capable of sending input data to EXSYS when they are activated during EXSYS run. This category includes Push Buttons, Radio Buttons, Check Boxes, Edit Boxes, Slide Bars and Mouse Regions. Graphical objects are objects that are drawn on the EXSYS Custom Screen at runtime, but are not capable of returning data to EXSYS, such as rectangles, ovals and lines. The only time that it is recommended that one control object overlap another control object is when overlaying mouse regions to cover a complex shaped region of the screen. These overlapping mouse regions should all have the same return string. Control objects of other types should not be overlapped at any time. You may however overlap control and graphical objects, and the control objects will always be displayed "on top" of the graphical objects. You may also overlap graphical objects with other graphical objects of any type. In this case, the last graphical object to be drawn, corresponding to the last command line in the appropriate sequence in the EXSYS Custom Screen file, will be the one that is displayed "on top". Note: Each and every EXSYS Custom Screen should contain at least one Push Button, Radio Button or Check Box with the "Return Immediate" option selected. This function is commonly implemented by placing an "OK" or "Continue" Button somewhere on each screen. Once an object is placed on the screen, it can appear in one of two modes: 1. The actual display of the button, oval etc. or 2. A manipulator box that enables you to resize and move the item. You can switch between the two modes by clicking on the item. The manipulator box mode appears as a rectangle with small black boxes at the corners and sides. When the item is in this mode, you can: 1. Resize the box Position the cursor on any of the small black boxes. Push the left mouse button (or on Macintosh, the only mouse button) down and hold it down. Move the cursor. The size of the box will follow the cursor. The corner boxes allow both height and width to be changed at the same time. The side boxes only change one dimension. When the box is the desired size, release the mouse button.
Q - ExDesign Custom Screen Design Program
6

2. Move the box Position the cursor inside of the rectangle. Push the left mouse button (or on Macintosh, the only mouse button) down and hold it down. Move the cursor. The box will follow the cursor. When the