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

Expressions Involving Relations

G2 provides the following expressions involving relations.

Event Expressions

This expression detects the creation or deletion of a relation:

For information on using this expression to forward chaining to rules, see Invoking Rules When a Relation is Created and Invoking Rules when a Relation is Deleted.

Logical Expressions

This expression tests for the existence of a relation and produces a truth-value that indicates whether one item participates in a relation of the specified kind with another item:

For example:

For information on using this expression to forward chain to rules, see Invoking Rules that Test whether a Relation Exists.

Relation Participation Expressions

Two expressions return information about relation participation as:

Obtaining the Relationships of an Item

Items include a hidden attribute, relationships. When you refer to the this attribute, G2 returns a sequence of structures describing the relations in which the given item is participating.

To refer to the relationships of an item:

The sequence returned by this expression consists of structures, each consisting of two subattributes:

If the item-of-interest is not participating in any relationships, the expression returns none. For a complete description of this expression, see Referring to The Relationships of an Item.

Obtaining Items Participating in a Relation

You can refer to a relation's items-in-this-relation hidden attribute. G2 returns a sequence of the items participating in the relation.

To refer to the items participating in a relation:

If no items are participating in the given relation, G2 returns the symbol none.

As an example of using this expression, in a KB with a married-to relation definition, you could create relations between four objects with this conclude action:

Such an action results in four items participating in the married-to relation:

A reference to:

returns this sequence of symbols:


Generic Item References

This generic reference returns the class of items that is related to any item or class:

With the the quantifier, this generic reference expression produces the one and only item of the specified class (or any of its subclasses) that participates in a relation of the specified kind with the specified item. With the any quantifier, this expression produces the set of items of the specified class (or any of its subclasses) that participate in relations of the specified kind with the specified item. For example:

For information on using this generic reference to forward chain to rules, see Invoking Rules that Refer to Items with Relations and Invoking Rules that Refer to Variables with Relations.

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

Copyright © 1997 Gensym Corporation, Inc.