| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (12 out of 17)

Invoking Rules using Relations

Relations can cause forward chaining to rules under the following circumstances:


Note: When G2 evaluates whether a relation exists between two items, G2 does not backward-chain to rules that can establish a relation.

Using Whenever Rules to Detect Relatedness

You can create a whenever rule to detect that two items have become related irrespective of the relation involved. The grammar is:

For example:

A whenever rule that detects a relation event fires every time any relation is made. Thus if two items become related by one relation, and then by another, a becomes related to rule fires twice, once for each relation established.

Using Whenever Rules To Detect Cessation of Relations

You can create a whenever rule to detect that two items have ceased to be related irrespective of the relation involved. The grammar is:

For example:

Deleting an item that participates in a relation does not invoke any whenever rules checking for a ceases to be related to event, because the item no longer exists.

Invoking Rules When a Relation is Created

When you create a relation by using a conclude action, G2 detects this event as part of processing, which causes forward chaining to rules.

You test when one or more relations is created by using this syntax in the antecedent of a rule:

In this example, the generic if rule on the left concludes a new a-member-of relation, if N is connected to R. When G2 detects the creation of this relation, G2 invokes the generic whenever rule on the right.


Invoking Rules when a Relation is Deleted

When you delete a relation by using a conclude action with the word not, G2 also detects this event during processing, which also causes forward chaining to rules.

You test when one or more relations is deleted by using this syntax in the antecedent of a rule:

For example, the generic if rule on the left deletes the relation named a-member--of, which invokes the generic whenever rule on the right.



Note: Deleting a relation by deleting an item that is participating in the relation does not cause forward chaining to rules.

For a description of whenever rules and the events they can detect, see Whenever Rules.

Invoking Rules that Test whether a Relation Exists

You can test whether a relation exists, in the antecedent of a rule. When G2 detects the creation or deletion of the relation, G2 invokes this rule via forward chaining.

You test for the existence of one or more relations by using this expression in the antecedent of a rule, which returns true or false:

For example, the generic if rule on the left concludes a new a-member-of relation, if N is connected to R. The rule on the right tests for the existence of this relation. G2 invokes this rule when the relation is created.


To test whether N is not related to the parent-network of R, you would use:

Invoking Rules that Refer to Items with Relations

You can use an expression in the antecedent of a rule to refer generically to a class of items that participate in a relation. When G2 detects the creation or deletion of the relation, G2 invokes this rule via forward chaining.

You refer generically to a class of items that are related to one or more items by using this syntax in the antecedent of a rule:

In this example, the rule on the left concludes the a-member-of relation, which triggers the rule on the right that refers generically to any node that is a-member-of the parent network of the router.


Invoking Rules that Refer to Variables with Relations

You can use an expression in the antecedent of a rule to refer generically to a variable that participates in a relation. When the variable receives a value or an expiration time, G2 invokes this rule via forward chaining.

You refer to variables that are related to items by using the same syntax as outlined in Invoking Rules that Refer to Items with Relations.

For example, the rule on the left concludes a value for the variable N. router via the relation named a-member-of, where NODE is a subclass of the system-defined symbolic variable class. When the relation is created, the rule concludes a value for the variable, which invokes the rule on the right that refers generically to the variable that is participating in the relation.


| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (12 out of 17)

Copyright © 1997 Gensym Corporation, Inc.