next up previous
Next: Interface Attributes Up: Facts Previous: Types of facts

Fact Functions

Facts may have a functional expression attached to them. This is the way we incorporate functional programming into Milord II. A fact with such an expression attached to it will get its value as the result of the evaluation of the expression.

Possible applications of fact functions could be: interfaces with other programs (windows, networks, statistics, etc), or procedural computations.

   figure2955
Figure 7: Syntax of function definition.

The function attribute (see Figure 7) of a fact is programmed in Common Lispgif with some extensions, it is a S-expression. This S-expression is considered to be evaluated inside an environment that contains variables, with the same name of the facts declared into a module, bound to the fact's value. It means that any fact name appearing in a S-expression will be considered as a local variable and its evaluation will return the current fact value.

The meaning of the two Milord II predefined functions is:

Type:
This function applied to a fact name of the current module returns the type of that fact in the following form: for boolean, many-valued, numeric and class types, the symbols boolean, many-valued, numeric and class respectively; for fuzzy types, a list containing the keyword fuzzy and the membership function in list form, for instance (fuzzy (37 38 43 43)); similarly for set and linguistic types, a list containing the parameters used to declare the concrete type, for instance for a linguistic type ((l "low" (37 37.3 37.6 38)) (m "medium" (37.6 38 38.5 39)) (h "high" (38.5 39 43 43)))

Linguistic_terms:
This function returns the set of linguistic terms of the current module in list form.

It is necessary to know the internal representation of the values of facts depending on their type. This is useful to manipulate the values of facts in a function attribute and to know which is the value format that a function must return depending on the type of the fact that contains it. We remind you that a fact with a functional expression attached to it will have the result of the evaluation of such expression as value.

Boolean:
It is a list of two elements: (false_etiq, false_etiq) for No; and (true_etiq, true_etiq) for Yes. false_etiq and true_etiq are respectively the first and the last element of the list of linguistic terms declared in the local logic of the module.

Numeric:
It is a real number.

Many-valued and Fuzzy:
It is a list of two elements (etiq_1, etiq_2) where etiq_1 and etiq_2 are elements of the list of linguistic terms and tex2html_wrap_inline6329 ; where tex2html_wrap_inline6331 is the total order defined implicitly when declaring the linguistic terms.

Set and Linguistic:
It is a list containing lists of two elements: the first is an atom representing the name of an element of a set fact or the linguistic value of a linguistic fact; and the second is a pair representing an interval of linguistic terms as in many-valued and fuzzy types. For instance for the fact fever: ((low (false false)) (medium (possible true)) (hight (possible true))). This list contains the elements in the same order as declared in the type attribute.

Now we can see an example of function declaration of the Terap-IA\ [6] applicationgif. The value of the clearance_of_creatinina can be obtained by means of the following expression.

displaymath6333

We can see the declaration of the fact creat_clear that contains a function attribute to compute its value.

Creat_clear= Name: "Clearance of creatinina"
             Type: numeric
             Function: (let* ((true (first (linguistic_terms)))
                              (male (equal (second (first sex))
                                           (list true true))))
                         (- 140 (/ (* age weight (if male 1.0 0.8))
                                   72)))

In this function age and weight are numeric facts, and sex is a set fact of type (male, female).


next up previous
Next: Interface Attributes Up: Facts Previous: Types of facts

Josep Puyol-Gruart
Thu Oct 23 15:34:13 MET DST 1997