0% found this document useful (0 votes)
95 views12 pages

KAPPA2

The document discusses the features and functions of the KAL language used in Intellicorp's Kappa-PC 2 software. It describes the main categories of KAL functions, including knowledge handling, control structures, windows, lists, strings, logical operations, math, and file functions. Example functions listed include MakeClass, GetValue, PostMessage, AppendToList, FormatValue, Or, +, OpenReadFile, and WriteLine.

Uploaded by

Carlos Lorusso
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views12 pages

KAPPA2

The document discusses the features and functions of the KAL language used in Intellicorp's Kappa-PC 2 software. It describes the main categories of KAL functions, including knowledge handling, control structures, windows, lists, strings, logical operations, math, and file functions. Example functions listed include MakeClass, GetValue, PostMessage, AppendToList, FormatValue, Or, +, OpenReadFile, and WriteLine.

Uploaded by

Carlos Lorusso
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 12

Intellicorp’s Kappa-PC 2

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.0 THE KAL LANGUAGE


There are around 250 KAL functions within Kappa which are broken up into groups:-
(i) Knowledge
(ii) Control
(iii) Windows
(iv) List
(v) String
(vi) Logical
(vii) Maths
(viii)File

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

AppendToList Adds one or more items to the end of a list


Average Averages the items in a list; the items should all be numbers
ClearLIst Clears a list of all its contents, so that it becomes empty
EnumList Evaluates an expression for each element of a list
GetElemPos Gets the location of an item within a list
GetNthElem Retrieves the item occupying a given location in a list
InsertNthElem Insets a new item before a given location in a list
LengthList Gets the number of items in a list
Max Returns the maximum value of the items in a list; the items should all be
numbers
Member? Checks if an item is a member of a list
Min Returns the minimum value of the items in a list; the items should all be
numbers
Multiply Multiplies the items in a list; the items should all be numbers
RemoveFromList Removes the fist occurrence of an item from a list
RemoveNthElem Removes the item occupying a given location in a list and compresses the
list accordingly
SelectList Selects the first element from a list that matches a given pattern
Sum Sums the items in a list; the items should all be numbers

1.5 String

FormatValue Formats values according to ANSI C standard


# Appends 2 text strings and produces a new text string
#= Compares 2 text strings

1.6 Logical

And Checks if all the argument values are TRUE


FirstValue Returns the value of the first argument that does not evaluate to NULL
Not Returns the logical negation of a value
Null? Checks whether an expression evaluates to NULL
Or Checks if any of the argument values are TRUE

1.7 Math

^ Raises a number to a given power


!= Determines if 2 numbers are not numerically equal
* multiplies a given set if numbers
+ Adds a set of numbers
- Subtracts one number from another
/ Divides one number by another
< Determines if one number is less than another
<= Determines if one number is less than or equal to another
~= Determines if 2 numbers are equal to within a 5% accuracy
== Determines if 2 numbers are numerically equal
> Determines if one number is greater than another
>= Determines if one number is greater than or equal to another

1.8 File

CloseReadFile Closes a file previously opened with the function OpenReadFile


CloseWriteFile Closes a file previously opened with the function OpenWriteFile
OpenReadFile Opens a file for subsequent file reading operations
OpenWriteFile Opens a file for subsequent file writing operations
WriteLine Writes an ASCII line in a pre-opened file that consists of each argument
separated by a space. Writes only one carriage return at the end of the
line
2.0 CREATE A USER INTERFACE

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

The Tool Box should open. If it does not,


· Select Tool Box 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.

2.1 Main Image Object Slots


Text: user inputs a piece of text which is displayed in the text box
Title The text which is displayed on the screen
Justification Your text can be Left-justified, right-justified or centred in the text book
FileName The Text Box can display the contents of a selected file.

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

Bitmap: the user can display a bitmap using this option.


Filename The name of the bitmap file which is to be displayed 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.

2.2 Tips for the User Interface

1. Images can be aligned quite easily by


· selecting the Image Adjuster option from the Options menu

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

3.0 W RITING FUNCTIONS


User-defined functions are written by combining KAL functions to perform user-defined operations.
Functions are used to carry out procedural details such as opening and closing windows, performing
calculations, checking for slot values during problem-solving - the list is endless.

Functions can be written directly at the KAL Interpreter but this takes practice. Alternatively you may
create new functions from the Edit Tools window

· Left click on Functions icon in the Edit Tools


· Select New from the small menu which appears
· Enter a valid Function name (no other function with that name, cannot begin with a
number etc)
The Function Editor appears in all its glory.
3.1 Function Editor Menu Options

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.

3.2 User Inputs for a Function


Arguments: Similar to any function, a function within Kappa can be passed arguments which can be
used in the body of the function and passed out again when processing is completed
Body: The user enters the required KAL code which performs the desired functionality for the function.

3.3 Tips for writing Functions

· 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

Remember, in Kappa as in other OO environments you may have:-


External methods: which other objects can send messages to
Internal methods: which the external messages send messages to in order to carry out internal
validation exercises etc.
Monitors: methods which are directly attached to a slot in the object. In Kappa remember we can
have If Accessed, When Needed, After Change and Before Change monitors.

4.1 Method Editor

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

Edit, Search, Options


Edit: Similar functionality to the Class Update menu featured In the previous tutorial
Search: allows you to look for a String within the method, Rename a String within the method and go
directly to a specified line number.
Options: All functions, rules, goals, methods etc have comments which allow you to document your
knowledge base. The Show Comment option opens up the Comment window for editing/viewing.

4.2 User Input to Methods


Arguments: As with functions, arguments can be passed into a method. For example when sending a
message to a hypothetical object called Person which has a Method called Give_Pay_Rise - this
method may expect an argument which relates to the actual amount the Person is being given for a
Pay Rise. In order to activate the method the following message is sent:

SendMessage(Person, Give_Pay_Rise, 100).


[Format: SendMessage(Object, MethodName, ArgumentList)]
and within the arguments slot you would use an argument such as Pay which can then be used
throughout the body of the method and be given the value 100 (the value passed in as an argument)
.
Body: The body of a method is written using standard KAL functions.

4.3 Tips for writing methods

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.

5.0 W RITING RULES


You may write any number of rules within your knowledge base. Remember the structure of the rules
remains the same if a forward chaining or a backward chaining inferencing strategy is selected.
You may create rules directly from the KAL Interpreter or use the Rule icon within the Edit Tools
window and selecting the New menu option which appears when the Rules icon is selected.

5.1 Rule Editor Options


Update, Edit, Search, Options: similar to the Function editor menu options described above.

5.2 User Inputs to Rules

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,

· you may enter, x|Person as the Patterns entry and

· 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.

6.0 INFERENCING IN KAPPA

You may inference across the Object Hierarchy using Forward or Backward Chaining. Each
inferencing strategy has its own peculiarities.

6.1 Forward Chaining

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

Format SetForwardChainMode(ruleChainMode, agendaMode)


Purpose Modifies the default conflict resolution mode for both rule selection and agenda
item selection.
Arguments ruleChainMode - the rule resolution strategy to be used during forward
chaining. Must be one of the following values:

SELECTIVE (default) follow a single path of reasoning to its conclusion.


DEPTHFIRST follow all paths of reasoning exhaustively, one at a time.
BREADTHFIRST follow all paths of reasoning exhaustively, in parallel.
BESTFIRST similar to DEPTHFIRST, but uses rule priorities.

agendaMode (optional)- the agenda item resolution strategy to be used during


forward chaining. Must be one of the following values:

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.

Format BackwardChain (<[NOASK]>,goalName, <ruleName or ruleList>)


Purpose Requests that the inference engine search the rules using the backward chaining
mechanism to resolve a goal.
Arguments <[NOASK]> (optional) - backward chaining will NOT query the user for values that
cannot be inferred from the knowledge base.

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.

6.2.1 Writing Goals


Kappa is rather restrictive in its use of goals. A goal generally refers to a slot value and whether or
not its value has been inferred or it set to a specific value. For example, the body of a valid goal may
be:

KnownValue?(Person:Name);

6.3 Tips for Inferencing


The Inference Browser graphically shows the progress of the problem solving, as the rules are
evaluated. The inference engine can ask the user for the values of slots that it cannot deduce
exclusively from rules.

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.

You might also like