defrelation [Macro]


Purpose

The defrelation macro defines or redefines a binary or n-ary relation.

Syntax

defrelation name &optional documentation
&key is is-primitive implies domain domains range arity predicate function
inheritance-link inheritance-method annotations identifier kb characteristics

Arguments

The name argument is a symbol. If name is null, the relation is given a system-generated name.

The documentation argument is a string which attaches a comment to the relation being defined. This string can be retrieved by calling the Lisp documentation function with variable as the doc-type argument. The is and is-primitive arguments are relation-forming expressions (see Remarks below) that define the relation---that is, they specify a condition that is both necessary and sufficient for a tuple to satisfy the relation. These arguments are identical except that is-primitive introduces primitiveness into the definition. If neither argument is provided, then the relation is assumed to be a primitive specialization of the built-in relation Binary-Tuple or N-Ary-Tuple.

The implies argument is a relation-forming expression (see Remarks below) that attaches a rule to the relation---that is, it specifies a condition which is necessary for a tuple to satisfy the relation.

The domain and range arguments are concept-forming expressions (see defconcept Remarks). Supplying these arguments is equivalent to using :domain and :range expressions in the implies argument.

The domains argument is only used in the definition of n-ary relations. It is a list of concept-forming expressions whose length is equal to one less than the arity of the relation being defined. Supplying this argument is equivalent to using a :domains expression in the implies argument. The arity argument is an integer which specifies the arity of an n-ary relation. A relation with an arity of n has n-1 domains and one range.

The predicate argument consists of a two-variable lambda list followed by a body of Lisp expressions (more variables are required for n-ary relations). When the variables are bound to objects, the Lisp expressions can be evaluated to determine whether the relation being defined holds between those objects. This test supercedes the definition given in the is or is-primitive argument.

The function argument consists of a one-variable lambda list followed by a body of Lisp expressions (more variables are required for n-ary relations). When the variable is bound to an object I, the Lisp expressions can be evaluated to generate other objects which are linked to I by the relation being defined. This function supercedes the definition given in the is or is-primitive argument.

The inheritance-link argument is the name of an inter-concept link across which annotations are inherited. Typically, this link is the metarelation direct-subrelations. For example, if relation R is declared to have the direct-subrelations inheritance link, and concept B is a subconcept of A, then when (R A x) is asserted, Loom will infer (R B x).

The inheritance-method argument is either :nearest-neighbor or :union. The :nearest-neighbor option indicates that annotations are inherited across inheritance-link only from the nearest concept (e.g., the most-specific superconcept) which has such annotations. The :union option indicates that annotations are inherited transitively across the inheritance link.

The annotations argument is a list of facts to be asserted about the relation being defined. Each element of the list is either a concept-name or an expression of the form (RelationName instance), where instance is either a constant or a symbol that identifies a Loom instance.

The identifier argument is the name under which the relation will be interned in the :instances partition of its knowledge base. This argument defaults to name.

The kb argument is a string or symbol that names the knowledge base in which the relation is to be interned. This defaults to the current knowledge base.

The characteristics argument is a keyword or list of keywords which specify various characteristics of the relation. Relations may have the following user-settable characteristics:

Relations may also have the following Loom-assigned characteristics:

Value

The defined or redefined relation is returned.

Remarks

Negation and disjunction are not yet supported in relation definitions.

There should only be one is or is-primitive keyword argument.

Relations referenced in the is or is-primitive clause should not refer (directly or indirectly) to the relation being defined, since cycles are not permitted in definitions.

Currently, Loom automatically makes a relation closed-world if any of the following conditions hold:

If a relation definition refers to a concept or relation that has not yet been defined, that concept or relation is immediately created by Loom.

In normal operation, a newly-defined relation is immediately classified, provided that all the concepts and relations it references have been classified.

  relation-expr ::= 
      RelationName | 
      ( :AND relation-expr+ ) | 
      ( {:DOMAIN | :RANGE} concept-expr ) | 
      ( :DOMAINS concept-expr concept-expr+ ) | 
      ( :INVERSE relation-expr ) | 
      ( :COMPOSE relation-expr+ ) | 
      ( :SATISFIES ( ?Var ?Var+ ) query-expr ) ;
The relation-forming expressions that appear in the is, is-primitive, and implies arguments above have the following syntax:

The relation-forming operators have the following semantics:

The auxiliary-definition keyword arguments have the following semantics:

Examples

(defrelation nil "Loom assigns name") ==> |R|BINARY-TUPLE_4
(defrelation r0) ==> |R|R0
(defrelation r1 :is-primitive r0)
(defrelation r2 :is (:and relative friend))
(defrelation r3 :is (:and president (:domain Corporation)))
(defrelation daughter :is (:and child (:range Female)))
(defrelation husband :is (:inverse wife))
(defrelation grandparent :is (:compose parent parent))
(defrelation r* :is (:satisfies (?x ?z)  
                       (:or (r ?x ?z)
                            (:for-some ?y (:and (r ?x ?y)
                                                (r* ?y ?z))))))
(defrelation s0 :implies (:and super (:range Concept)))
(defrelation s1 :domain Person)      
(defrelation spj :arity 3 :domains (Supplier Part))
(defrelation s2 :range Number)
(defrelation s3 :predicate ((n1 n2) (> n1 n2)))
(defrelation s4 :function ((n1 n2) (+ n1 n2)))
(defrelation s5 :inheritance-link direct-subrelations
                :inheritance-method nearest-neighbor)
(defrelation s6 :annotations (Verb (past "-ed")))
(defrelation s7 :identifier age-as-relation :kb user-kb)
(defrelation s8 :characteristics (:single-valued :closed-world))

See Also

Last modified: Dec 28 1995