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

Creating a Relation

You can create a relation between:

Using Conclude to Create Relations

You use a conclude action with the following syntax to create a relation between two relation items or classes:

To conclude a relation value:

The first item serves as the relation source, and the second item serves as the relation target. In general, the first item returns an instance or class of the First-class, the second item returns an instance or class of the Second-class.

The exception is a symmetric relation, where the expressions can be items of the first or second class. See the note under Defining a Symmetric Relation.

The not statement breaks an existing relation, while the now statement establishes a new relation by breaking an existing one when doing so violates the relation's cardinality. If you do not specify either not or now, you can only conclude a relation between items when it does not violate the relation's cardinality.

You can conclude all types of relations by using this syntax. Here are some examples of concluding different types of relations:

Relation type Example of conclude statement
one-to-one
conclude that node-1 is not-responding-on network-1
one-to-many
conclude that node-1 is the-server-for every node
many-to-one
conclude that every node is a-part-of network-8
many-to-many
conclude that every node is a-component-of every network

Example of Creating a Relation Between Two Items

For example, this action button creates a relation between computer-1 and computer-2, which are both instances of the COMPUTER class. In the relation definition, First-class and Second-class both specify the COMPUTER class.


Notice that the relation type is one-to-one. This means that you cannot conclude another relation named in-communication-with between computer-1 and another computer, since doing so would violate the relation's cardinality.


Note: If you attempt to conclude a relation between an item that is already participating in a one-to-one relation of the same name, G2 signals an error.

Example of Creating a Relation Between an Item and a Class

You can create a relation between more than one instance of a class by using an expression that returns a class instead of an item. (Note that you can also create multiple conclude statements to accomplish the same thing.)

For example, this button creates a relation between computer-1 and every instance of the COMPUTER class.



Note: In this example, G2 also concludes a relation between computer-1 and itself, because the relation source is also an instance of the second class.

You can only conclude a relation when doing so does not violate the relation definition's cardinality.


Note: If you attempt to conclude a relation that violates the relation's cardinality, G2 signals an error.


Tip: Use an alternative form of the conclude action to break existing relations before concluding a new relation, when concluding the relation violates the relation's cardinality.

G2 creates, at most, one instance of a particular relation between the same two items. Thus, if you conclude a relation between two items when a relation of that name already exists between the items, G2 does not create another relation.

You can conclude multiple instances of different relations between the same two items.

Using a Sequence to Conclude a Relation

You can also conclude a relation between items by using a sequence.

To use a sequence for creating a relation:

where the sequence of relationships consists of one or more structures of relation names and the items to which the relation applies. Each structure in relationships contains these subattributes:

Subattribute Type Description
relation-name-reference
symbol
The name of the relation, which can be either the Relation-name or the Inverse-of-relation of the relation.
related-items
sequence
A sequence of items with the relation-name-reference relationship to the item-of-interest.

Example of Creating a Relation with a Sequence

As an example, a KB includes two relation definitions, married-to and a-daughter-of. Three objects exist, george, bill, and edna. Using the conclude action without a sequence, you could create two relations for edna:

To conclude the same relationships by using a sequence, use an action such as this:


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

Copyright © 1997 Gensym Corporation, Inc.