COGENT Online
CONTENTS
COGENT Help

Editing Rules, Conditions, and Source Elements

Introduction

The rule editor is displayed when the user edits a rule, condition definition, or source element. The appearance of the editor depends on which of these three kinds of elements is being edited, in that menu items and toolbar buttons that are not appropriate to the given element will not be available. For example the Add Condition menu item is not available when a source element is being edited (source elements do not have conditions).

We shall first show how to use the editor on a rule and then explain the differences that appear when editong conditions definitions or source elements.

Editing Rules

Figure 1: The Rule Editor As It Appears When Editing a Rule

Selection of the Current Condition and Action

The user may select one action and one (sub-)condition, to be current. The current action and (sub-)condition are enclosed in red boxes. In the figure above the first condition and the second action are current.

To select the current action, click at a point that lies on the action but which is not in one of its editable fields. For example the first action in Figure 1 could be selected by clicking on the words "send" or "to". Note that clicking to the left of the first word in an action or to the right of the last word will not select it. Clicking anywhere outside a condition or action will result in there being no current action or current condition.

The current (sub-)condition is selected in the same way as the current action. However if a condition consists of a set of sub-conditions prefixed with a qualifier then either the the whole condition or any of its sub-conditions may be selected to be the current condition. In figure 2 below the sub condition not item is in working memory has been selected.

Figure 2: selection of a subcondition.

To Insert a New Condition or Action ...

Select the type of action required from the Add Action menu. A new action will then be inserted with appropriate fields (e.g. the destination of a send action) left blank for the user to fill in. By default the new action will be added at the end of the rules list of actions. This default behaviour can be changed by changing the
insertion mode. New conditions are inserted in a similar manner by selecting the appropriate condition type from the Add Condition menu. The position of the new condition is determined, as for actions, by the insertion mode. However if the current condition is a member of a set of sub-conditions preceded by a qualifier, as in Figure 2, then the inserted condition will also be a member of that set of sub-conditions and will be in the scope of their qualifier, being inserted as the first, or last sub-condition in that scope or preceding or following the current sub-condition depending on which insertion mode has been selected.

To Delete the Current Action or Condition ...

Select the menu items Delete->Current Condition or Delete->Current Action or click on the corresponding buttons in the rule editor's toolbar. If the current condition is a member of a set of sub-conditions preceded by a qualifier, as in Figure 2, then that sub-condition is removed but neither the qualifier nor any of the other sub-conditions in its scope are affected.

To Add a Qualifier to the Current Condition ...

Select the desired qualifier from the Add Qualifier menu. At the moment the only way to create a set of conditions prefixed with a qualifier is to add a qualifier to a single condition, and then add new sub-conditions using the Add Condition menu as explained above.

To Delete the Qualifier of the Current Condition ...

Select Delete Qualifier from the Rule Edit menu or click on the corresponding button in the toolbar.

Editing Source Elements

When a source element is being edited, menu items and buttons used for editing actions have the same effect as when editing rules. However menu items and buttons used for editing conditions are unavailable since source elements do not have conditions.

Editing Condition Definitions

A condition definition consists of a set of prolog-like rules of the form <head> :- <body>. The body of each rule is a list of conditions. An example of a condition definition might be:
max(X,Y,Z) :- 
	X>=Y, 
	Z = X, 
	!.
max(X,Y,Z) :- 
	Y>=X, 
	Z = Y, 
	!.
When editing a condition definition the "current condition", which is enclosed in a red box, may be either a complete rule, or one of the conditions in the body of the rule. There is (obviously) no current action.

To Add a Rule To A Condition Definition...

Select the Add Condition->New Rule menu item, or the corresponding toolbar button. The body of the newly inserted rule will be of the form call ... with the term to be called left blank. In most cases you will want to replace this body with something else of your own choosing. The only reason for using a call as the default body is that it is usually easier to edit a rule if it already has a body, and call seems as good as anything else.

The position at which the new rule appears is determined by the current insertion mode.

To Add A New Condition to the Body of a Condition Definition...

Select the desired condition from the Add Condition menu. The position of the newly inserted condition is determined by the insertion mode in a more or less obvious way. The only complication occurs when a complete rule has been selected as the "current condition". In this case the new condition will be added at the beginning of the rule's body iff the current insertion mode is Insertion as first element, otherwise it will be added to the end of the body.

Facts

A fact is a rule with no body, for example pi(3.14159). To create a fact select Add Condition->New Rule menu item, or the corresponding toolbar button, then delete the single condition in the newly created rule's body.

To convert a fact into a rule, select the fact as the "current condition", decide what is to be the first condition in the body of the rule, and select that condition from the Add Condition menu.

Insertion Modes

The rule editor has five insertion modes which may be selected from the Rule Edit menu, or by clicking on the appropriate buttons in the toolbar. The choice of insertion mode determines where a newly inserted (sub-)condition or action will appear:

The Rule Editor Toolbar

Each button on the rule editor toolbar corresponds to a menu item, as follows:

ButtonAction PerformedEquivalent Menu Item
Cancel all edits and closes editor File->Cancel Edits and Quit
Insert a new rule into a condition definition Add Condition->New Rule
Delete the current condition Rule Editor->Delete Current Condition
Delete the current action Rule Editor->Delete Current Action
Remove the qualifier from the current condition Rule Editor->Delete Qualifier
Set insertion mode to before Rule Editor->Insertion Before Current Element
Set insertion mode to after Rule Editor->Insertion After Current Element
Set insertion mode to last Rule Editor->Insertion As Last Element
Set insertion mode to first Rule Editor->Insertion As Firstlement
Set insertion mode to subclause Rule Editor->Insertion As Subclause

COGENT Online
CONTENTS
COGENT Help