2
50 trendsin analytical chemistry, vol. 4, no. ,2,1985 coordinator of robotics at the Faculty of Applied Sciences, De- partment of Robotics, Vrije Universiteit Brussel, Pleinlaan 2, 1050 Brussels, Belgium. Y. Michotte obtained her Ph.D. in Phar- maceutical Sciences at the Vrije Universiteit Brussel in 1976. Pharmaceutical and biomedical analysis and statistics belong to her major field of interest. She is at the Pharmaceutical Institute, Department of Pharmaceutical and Biomedical Analyses, Laar- beeklaan 103,109O Brussels, Belgium. PROLOG, an artificial intelligence language D. L. Massart and J. Smeyers-Verbeke, Brussels, Belgium tion that permits the query, while ‘carboxyl’ is the in- put data for the search of the data bank. Lines 3 and 4 give the answers supplied by PROLOG. In view of the interest in artificial intelligence and expert systems, a few of these Computer Corners will be devoted to one of the two principal languages available at this moment, namely PROLOG. The in- tention is to give an idea about how such a language works and not to give complete directions on how to use PROLOG. This will be done in a progressive way. First very simple programs will be given, which will then become slightly more complex in the fol- lowing Corners. All these programs are meant as il- lustrations of the language and are not intended for practical use. The small program given above is written in a sim- ple version of micro-PROLOG (a product supplied by Logic Programming Associated, 10 Burntwood Close, London SW18 3JU, U.K.). This version of micro-PROLOG contains standard micro;PRO- -LOG and an extension, called SIMPLE, which per- mits the use of sentences, closer to the natural lan- guage than the so-called clauses used in standard PROLOG. With this version of PROLOG comes a book’, which is a very good tutorial for PROLOG. The object of programming in PROLOG or other artificial intelligence languages is the handling of knowledge, i.e. data and relationships between data. For this reason, the style of programming in PRO- LOG is very different from that of BASIC, PAS- CAL, FORTRAN or other imperative pro- gramming languages. One of the most marked dif- ferences is that the clear-cut separation into the pro- gramming-stage and the running stage, which we are used to with BASIC, etc., does not necessarily exist anymore, nor the distinction between ‘program’ and ‘input-data’. This can be illustrated by the following, very simple, sequence of PROLOG lines and an- swers: Sentences are one of the bases of this version of micro-PROLOG. There are two types of sentences, simple sentences such as the one in line 1 above and conditional sentences. In this first corner on PRO- LOG, we will consider only simple sentences. Sim- ple sentences can take two forms, the binary form such as acetylsalicylic-acid contains-function carboxyl and the unary form such as carboxyl strong-acidic-function add(acetylsalicylic-acid contains-function carboxyl) which (x:x contains-function carboxyl) acetylsalicylic-acid no (more) answers The first line defines at the same time the relation- ship contains-function and gives data which fulfill this relationship. It is at the same time data and pro- gram. Line 2 is a query, entered by the programmer, to get out all substances that contain the function carboxyl. Again this line contains elements of pro- gramming, since ‘which’ can be viewed as an instruc- To understand what purpose these sentences serve let’s suppose we want to construct a program that contains details about the structure of some drugs. The program must be able to retrieve these data and make some conclusions about the acid-base charac- ter of the substances and how best to dissolve them. The acid-base functions of drugs are always weak but some are stronger than others and a useful way to decide about how to dissolve a drug is to make a distinction between the stronger acidic or basic func- tions (called ‘strong’ for simplicity) and the weaker ones (called ‘weak’). In this Corner we will show how the data base is constructed and how data can be retrieved from it. After loading PROLOG and SIMPLE, one types in the data and the relationships between these data, using the add statement and the sentences that de- 0165-9936/85/$02.00. @ Elsevier Science Publishers B .V

PROLOG, an artificial intelligence language

Embed Size (px)

Citation preview

Page 1: PROLOG, an artificial intelligence language

50 trends in analytical chemistry, vol. 4, no. ,2,1985

coordinator of robotics at the Faculty of Applied Sciences, De- partment of Robotics, Vrije Universiteit Brussel, Pleinlaan 2, 1050 Brussels, Belgium. Y. Michotte obtained her Ph.D. in Phar- maceutical Sciences at the Vrije Universiteit Brussel in 1976.

Pharmaceutical and biomedical analysis and statistics belong to her major field of interest. She is at the Pharmaceutical Institute, Department of Pharmaceutical and Biomedical Analyses, Laar- beeklaan 103,109O Brussels, Belgium.

PROLOG, an artificial intelligence language

D. L. Massart and J. Smeyers-Verbeke, Brussels, Belgium

tion that permits the query, while ‘carboxyl’ is the in- put data for the search of the data bank. Lines 3 and 4 give the answers supplied by PROLOG.

In view of the interest in artificial intelligence and expert systems, a few of these Computer Corners will be devoted to one of the two principal languages available at this moment, namely PROLOG. The in- tention is to give an idea about how such a language works and not to give complete directions on how to use PROLOG. This will be done in a progressive way. First very simple programs will be given, which will then become slightly more complex in the fol- lowing Corners. All these programs are meant as il- lustrations of the language and are not intended for practical use.

The small program given above is written in a sim- ple version of micro-PROLOG (a product supplied by Logic Programming Associated, 10 Burntwood Close, London SW18 3JU, U.K.). This version of micro-PROLOG contains standard micro;PRO- -LOG and an extension, called SIMPLE, which per- mits the use of sentences, closer to the natural lan- guage than the so-called clauses used in standard PROLOG. With this version of PROLOG comes a book’, which is a very good tutorial for PROLOG.

The object of programming in PROLOG or other artificial intelligence languages is the handling of knowledge, i.e. data and relationships between data. For this reason, the style of programming in PRO- LOG is very different from that of BASIC, PAS- CAL, FORTRAN or other imperative pro- gramming languages. One of the most marked dif- ferences is that the clear-cut separation into the pro- gramming-stage and the running stage, which we are used to with BASIC, etc., does not necessarily exist anymore, nor the distinction between ‘program’ and ‘input-data’. This can be illustrated by the following, very simple, sequence of PROLOG lines and an- swers:

Sentences are one of the bases of this version of micro-PROLOG. There are two types of sentences, simple sentences such as the one in line 1 above and conditional sentences. In this first corner on PRO- LOG, we will consider only simple sentences. Sim- ple sentences can take two forms, the binary form such as

acetylsalicylic-acid contains-function carboxyl and the unary form such as

carboxyl strong-acidic-function

add(acetylsalicylic-acid contains-function carboxyl) which (x:x contains-function carboxyl) acetylsalicylic-acid no (more) answers

The first line defines at the same time the relation- ship contains-function and gives data which fulfill this relationship. It is at the same time data and pro- gram. Line 2 is a query, entered by the programmer, to get out all substances that contain the function carboxyl. Again this line contains elements of pro- gramming, since ‘which’ can be viewed as an instruc-

To understand what purpose these sentences serve let’s suppose we want to construct a program that contains details about the structure of some drugs. The program must be able to retrieve these data and make some conclusions about the acid-base charac- ter of the substances and how best to dissolve them. The acid-base functions of drugs are always weak but some are stronger than others and a useful way to decide about how to dissolve a drug is to make a distinction between the stronger acidic or basic func- tions (called ‘strong’ for simplicity) and the weaker ones (called ‘weak’). In this Corner we will show how the data base is constructed and how data can be retrieved from it. After loading PROLOG and SIMPLE, one types in the data and the relationships between these data, using the add statement and the sentences that de-

0165-9936/85/$02.00. @ Elsevier Science Publishers B .V

Page 2: PROLOG, an artificial intelligence language

trends” analytical chemistry, vol. 4, no. 2,1985

scribe the data and their inter-relationships. A small data-bank might consist of:

add(acetylsalicylic-acid contains-function car- boxyl)

add(salicylic-acid contains-function carboxyl) add(salicylic-acid contains-function fenol) add(propanolo1 contains-function secundary-ali-

phatic-amine) add(feno1 weak-acidic-function) add(carboxy1 strong-acidic-function) add(secundary-aliphatic-amine weak-basic-func-

tion) Querying the data-base can now be done as follows:

(1) If one wishes to verify whether or not a certain fact is correct: use of is. Suppose one wants to verify whether salicylic acid contains or does not contain a fenol function, then one would type in

is (salicylic-acid contains-function fenol) and get the answer:

YES The question

is (acetylsalicylic-acid contains-function fenol) would yield:

NO (2) If one wishes to retrieve a fact: use which. If

one wants to know which functions are present in sa- licylic-acid, one types:

which (x: salicylic-acid contains-function X) and the computer returns:

carboxyl fen01 No (more) answers

To know which substances contain fenol, the query would be

which (XX contains-function fenol) and the answer

salicylic-acid

Computer Corner - Contributions

Contributions of between 400 and 900 words are welcome in the categories described below and should be sent to the appropriate contributing editor.

Information on hardware, general software, software tips, and interfacing should be sent to:

TrAC Computer Corner B. G. M. Vandeginste, Depart- ment of Analytical Chemistry, University of Nijmegen, Toernooiveld, 6525 ED Nijmegen, The Netherlands.

Information on chemical applications, software and math- ematical tools for improving information content should be sent to:

TrAC Computer Corner, D. L. Massart, M.-R. Derde, Vrije Universiteit Brussel, Fakulteit der Geneeskunde en der Farmacie, Farmaceutisch Scheikunde, Laarbeeklaan 103, B-1090 Brussels, Belgium.

51

No (more) answers If one would like to know all the pairs of data for whom a relationship contains-function exist, one would type:

which (xy:x contains-function y) and obtain

acetylsalicylic-acid carboxyl salicylic-acid carboxyl salicylic-acid fenol propanolol secundary-aliphatic-amine No (more) answers

Clearly constructing and using small data-bases with PROLOG is not difficult at all. In fact, you know now enough micro-PROLOG to do it! The con- struction of data-bases can be carried out in a still more efficient manner. This will be the subject of one of the following corners.

References 1 K. L. Clark and F. G. McCabe, Micro-PROLOG: Pro-

gramming in Logic, Prentice-Hall International, New Jersey, 1984.

D. L. Massart and J. Smeyers-Verbeke are at the Farmaceutisch Instituut, Vrije Universiteit Brussel, 103 Laarbeeklaan, B-1090

Brussels, Belgium.

m AUXILIARY AIR fume hoods conserve u E

to 60% of heated OI conditioned air normally exhausted t rough the hood.

m COMPLETE LINE OF HOODS-Air By-Pass, Induced Air 01 Auxiliary Air models. Portable Hoods, Canopy Hoadr. Tisruc Culttire Hoods. Sizes from 24” to 144” wide.

m COMPLETE LINE OF SERVICES-Plumbing, electrical, venting All rizes of exhourt fans, base cabinets and work surface8 are available.

Request New 80-RS Catalog Describing Complete Line of Hoods & Accessories. Toll Free 1-800-821-3504

MO. 6405 l- (8 16) 796-2900

Circle no. 172 on advertising enquiv form