KAPPA2
KAPPA2
Having looked at the main features of Kappa we will now look in more depth at
1. The KAL Language
2. How to create an operational User Interface with active buttons etc.
3. How to write Functions
4. How to Write Methods
5. How to Write Rules
6. Inferencing in Kappa
1.1 Knowledge
Classes
Class? Determines if a class exists by a given name
DeleteClass Removes a class from the current knowledge base
MakeClass Creates a class in the current knowledge base
RenameClass Gives a new name to an existing class
Instances
Delete Instance Removes an instance from the current knowledge base
Instance? Determines if an instance exists by a given name
MakeInstance Creates an instance in the current knowledge base
MoveInstance Moves an Instance to another section of the object hierarchy
RenameInstance Gives a new name to an existing instance
Methods
SendMessage Sends a message and activates a method within an object
Object Hierarchies
AreAll? Loops over all the instances of a class and checks if they all match a given
pattern
CountAllInstances/ Returns a count of all the instances/subclasses of a given class and all of its
Subclasses subclasses etc.
CountInstances Returns a count of the immediate instances of a class
CountSubClassess Returns a count of the immediate subclasses of a class
EnumSubClasses Loops over all subclasses of a class, and their subclasses etc. and performs a
given action
ForAll Loops over all the instances of a class, and performs a given action
GetDepth Returns the depth of the hierarchy below a given class
GetInstanceList Stores the name of the immediate instances of a given class in a multiple-
values slot
GetParent Returns the class of an instance or the superclass of a class
GetSubClassList Stores the names of the immediate subclasses of a given class in a multiple-
valued slot
IsAKindOf? Determines if a class lies in the inheritance path of another object
IsThereAny? Loops over all the instances of a class, and returns the first one that matched a
given pattern
SelectSubClass Loops over all subclasses and their subclasses etc and returns the first one that
matches a given pattern
Slots
AskValue Asks the user for a slot value for a single-valued slot
Assert Adds an object:slot pair to the agenda/working memory of the forward chainer
GetValue Retrieves the value from a slot
KnownValue? Determines if a value exists in a slot
MakeSlot Creates a slot in an object
RenameSlot Gives a new name to an existing slot
ResetValue Removes the current value from a slot, and replaces it with NULL or an
inherited value
SetValue Stores the value in a slot
Slot? Determines if a slot exists in an object
+= increments the value of a slot by a value
= Sets the value of a single-valued slot equal to a particular value
Goals
DeleteGoal Removes a goal from the current knowledge base
Rules
ActivateRule Adds a rule to the list of rules (that is, the rule set) to be considered by the
inference engine
Assert Adds an object:slot pair to the agenda of the forward chainer
BackwardChain Requests that the inference engine search the rules using the backward
chaining mechanism to resolve a goal
DeactivateRule Removes a rule from the rule set and from the active rules list, if it is there,
so that it is no longer considered by the inference engine
ForwardChain Initiates forward chaining until an end condition is encountered
ResetForwardChain Empties the agenda of the forward chainer
SetForwardChainMode Modifies the default conflict resolution mode for both rule selection and
agenda item selection
1.2 Control
Beep Requests the operating system to sound a single beep
Date Retrieves the current date
Execute Executes an external program
Exit Closes a Kappa session and returns to the operating system
Time Returns the current time of day
Block Control
For Repeats evaluation of an expression a given number of times
If Conditionally evaluates an expression
Let Evaluates an expression with temporary arguments
While Repeats evaluation of any expression until another expression returns
FALSE
{} Evaluates a set of expressions sequentially
1.3 Window
User Interface
PostBusy Posts or removes the Kappa-Pc “Please wait” message
PostInputForm Posts a pop-up window with several input slots for the user to fill
PostMenu Posts a pop-up menu from which the user selects one option
PostMessage Posts a pop-up window with a message to the user and waits for a reply
PostMultipleSelection Posts a dialogue box from which the user can select several options
Window
HideWindow Hides one of the Kappa windows
IconifyWindow Shrinks a Kappa window to an icon
MaximizeWindow Displays a Kappa window in full screen mode
ShowWIndow Pops up an shows a Kappa window
ActiveImages
ClearTranscriptImage Clears all text from a transcript image
DeleteImage Deletes the instance associated with a graphical image
DisplayFile Displays the text from a file inside a transcript image
DisplayText Displays a character string inside a transcript image
HideImage Hides an image so that it no longer appears in the Session window
ResetImage Updates the initial characteristics of a graphical image using the slot
values represented in the associated image object, and redraws the image
in the Session window
SaveTranscriptImage Writes the text from a transcript image into an already opened file
ShowImage Shows a hidden image in the Session window
UpdateImage Updates the physical appearance of some graphical images to reflect the
values they monitor
1.4 List
1.5 String
1.6 Logical
1.7 Math
1.8 File
In order to create a user interface you can use the pre-defined SESSION window or create a new
instance of the KSession object in the object hierarchy.
In order to select a user interface window, click on the Session window in the main Kappa Window:
this opens the window to allow you to start designing your screens. As I mentioned in the previous
tutorial, you need to enter Layout Mode in order to activate the screen design options.
· Select a Session window from the Session icon in the Main Kappa Window
· Select Layout Mode from the Options menu option
In order to design your interface you need to select an interface image from the Tool Box and place
the selected image on the Session window.
· Left click on an image in the Tool Box. The icon should change shape to a + which
indicates that the image is waiting to be placed.
· Left click on a blank area within the Session window to place the image.
Once the image has been placed you need to edit the image object slots by double clicking on the
image in order specify for example the text which needs to be displayed if a Text Box is selected.
Button: a button has a predefined function attached to it which is activated when the user clicks on
the button during runtime.
Title The title of the button which appears on-screen
Action The name of the function which is activated when the button is selected in run-time
FileName The name of the file (usually a bitmap file) which is displayed instead of a textual
title.
Edit Box: the user may enter a value into this edit box which is attached to an object and slot. When
the user inputs a value here it is automatically entered into the objects slot.
Owner The name of the object
OwnerSlot The name of the slot
Style Can be a single line
Transcript Image: This allows the user to display a file or a piece of text
Title The name of the transcript Image which appears on screen
Drawing: the user can draw an image using KALs inbuilt draw functions but I would doubt you need
this for your assignment so we will move swiftly on.
The following images have very similar slot options as each are attached to an object:slot pair within
the knowledge base.
State Box: A state box is attached to a slot which has a set of allowable values. The actual value of
the slot is the highlighted item in the state box.
SingleListBox: the programmer can define a range of values for a slot. The user may select one of
these options which becomes the value of the slot.
MultipleListBox: the programmer can define a range of values for a slot. The user may select a
number of these options which become the value of a multivalued slot.
CheckBoxGroup: the programmer can define a range of values for a slot. The user may select a
number of these options which become the value of a multivalued slot.
RadioButton Group: the programmer can define a range of values for a slot. The user may select a
number of these options which become the value of a multivalued slot.
ComboBox: This is a combination of a text box with a range of values from which one can be
selected for a slot.
Title The name of the image object (this can be left blank
Owner The name of the object which is affected by the image
OwnerSlot The actual slot within the named object which changes as a result of the user
selecting one of the Allowable Values on screen
AllowableValues The range of values which are allowable for entry to the slot mentioned above.
The user selects an allowable value and this becomes the value of the slot
Meter: a meter is again attached to a numeric slot and displays the value of the slot in a meter form.
Title The name of the image object (this can be left blank)
Owner The name of the object which the meter image represents
OwnerSlot The actual slot within the named object whose value is displayed through the
meter.
MinValue The minimum value for the meter i.e. the value on the LHS
MaxValue The maximum value for the meter i.e. the value at the RHS
Units Title The Title of the units displayed within the meter e.g. kgs, $s etc.
Graph: a graph can be displayed based on user input for the X,Y axis, co-ordinates etc. but you will
probably not need this for the assignment
Slide Bar: a slide bar is again attached to a slot and when the user slides the slides during a
consultation the value of the slot is changed accordingly.
Title The name of the slide bar image (this can be left blank)
Owner The name of the object which is the slidebar image represents
OwnerSlot The actual slot within the named object whose value is displayed through the
slidebar.
MinValue The minimum value for the meter i.e. the value on the LHS
MaxValue The maximum value for the meter i.e. the value at the RHS
Units Title The Title of the units displayed within the meter e.g. kgs, $s etc
Orientation The Slide bar can be displayed horizontally or vertically
Check Box: the programmer can define a range of values for a slot. The user may select one of
these options which becomes the value of the named slot.
Title The name of the check box image (this can be left blank)
Owner The name of the object which is the checkbox image represents
OwnerSlot The actual slot within the named object whose value is changed when the user
checks the checkbox.
1. You may change the colour of objects and the fonts in which text is displayed by clicking on the
Title and Body buttons when you are editing the image’s options in Layout Mode.
2. Interface screens can be copied but beware - if a screen is copied and all its objects when you
change an image in one screen it is copied automatically to the other screen.
So these are the basic facilities for creating a User Interface. The remainder of this document will
deal with how to write:
1. Functions
2. Methods
3. Rules
4. Goals
Functions can be written directly at the KAL Interpreter but this takes practice. Alternatively you may
create new functions from the Edit Tools window
Update: Similar functionality to the Class Update menu featured In the previous tutorial but also
allows you to check the syntax of your function at any time.
Edit: Similar functionality to the Class Update menu featured In the previous tutorial
Search: allows you to look for a String within the function, Rename a String within the function and go
directly to a specified line number.
Options: All functions, rules, goals etc have comments which allow you to document your knowledge
base. The Show Comment option opens up the Comment window for editing/viewing.
· Compound Statement: When you have more than one line in a function and within a compound
statement, the body of the compound question and the entire function must be surrounded by
curly brackets i.e. {}
For example,
{
PostMessage(“Hello World”);
PostMessage(“Isn’t Kappa lovely”);
};
· All lines within a function (and indeed rules, goals, methods and the KAL Interpreter) must be
followed by a semi-colon i.e. ‘;’ except when you are using an IF..THEN..ELSE statement as
in other languages, there should be no semicolon before the ELSE statement. For Example,
If a And B Or c
Then {d; e}
Else c;
· You may access/retrieve the value of a slot by simply using the Object:Slot formalism. For
example, the GetValue KAL function retrieves the value of a name Object:Slot Pair
GetValue(Person:Name); or
GetValue(Person, Name);
This code will examine the Person Object and access and output the value of the Name slot.
4.0 W RITING OBJECT METHODS
Update
Check Syntax: the user may check the KAL syntax of the method at any time
Break: put a break point within the method (I think - never used it!)
Close: closes the method editor
Exit: closes the method editor and asks the user if he/she would like to save any changes if any have
been made between closure and the last Save operation
When a Method is defined as a monitor (see above) you may enter ‘x’ as an argument into the
Arguments field. In this case ‘x’ is the name of the Slot the monitor is attached to.
The term Self can be used within the body of the Method which translates into the name of Object in
which the Method is defined.
Patterns: When using an OO approach to knowledge representation, the rules are used to inference
across objects within the object hierarchy. The Patterns field allows you to define the range of
relevant objects which should be inferenced over by this rule. For example,
· within the body of the rule use the symbol ‘x’ which relates to a class or subclass of type
Person, therefore if the following is entered as the If clause of the rule, If x:Name #=
Maureen this limits the inference engine from looking at the Name slot of objects other
than those which are subclasses or instances of the Person object.
Priority: You may enter a priority value for conflict resolution between -30,000 - +30,000
If: This field contains all the IF conditions of the rule. The use of And and Or is permitted within the IF
condition list. An If condition must be followed by a semi-colon.
Then: This field contains the conclusions of the rule. If there is more than one conclusion, then the
lines within the THEN field must be surrounded by curly brackets and be followed by a semi-colon.
You may inference across the Object Hierarchy using Forward or Backward Chaining. Each
inferencing strategy has its own peculiarities.
In order to commence forward chaining you may enter an Object:Slot pair into the Working Memory.
Within Kappa the Working Memory is called the Agenda. Therefore to update the Agenda, use the
Assert command. Having inserted something into the Agenda you may begin Forward chaining. For
example,
...
{
Assert(Person:Name);
ForwardChain();
};
Alternatively, if you do not wish to enter anything onto the Agenda, you may use the
ForwardChain([NOASSERT])
The ForwardChain KAL function can be used in a variety of ways (see the On-LIne Help)
You may also define a Rule set or a list of rules to be examined during inferencing.
ForwardChain(Goal1, Rule1, Rule4,Rule7); or
ForwardChain(Goal1,Global:TestingRules); (rule set whose individual rules are held as slot
values of the TestingRules slot I Global)
You may also define the Mode of Inferencing which relates to the search strategy which is
implemented during problem-solving. The inferencing strategy can be controlled by using
SetForwardChainMode
IGNORE Skips an agenda item if there is an more recent version of the same item on
the agenda.
NOIGNORE Processes each item on the agenda in turn, whether or not it is repeated later
on the agenda.
6.2 Backward Chaining
In order to commence backward chaining you must use the BackwardChain function and have a goal
defined.
goalName - the name of the goal that must be resolved, (that is, that must
evaluate to TRUE).
ruleName or ruleList (optional) - a single rule or a list of rules to be considered by the inference
engine. Can be specified as an object:slot pair with a value that is a list of rules. If no rules are
specified, the inference engine uses all the rules that are in the knowledge base.
KnownValue?(Person:Name);
That is basically all you need to know about Kappa for your assignment. We will be doing a few more
examples in class so it should be a breeze.