An Efficient Easily Adaptable System
for Interpreting Natural Language Queries 1
David H. D. W a r r e n
and
Fernando C. N. Pereira
A r t i f i c i a l I n t e l l i g e n c e C e n t e r S R I I n t e r n a t i o n a l 3 3 3 R a v e n s w o o d A v e n u e M e n l o P a r k , C A 9 4 0 2 5This paper gives an overall account of a prototype natural language question answering system, called C h a t - 8 0 . C h a t - 8 0 has been designed to be both efficient and easily adaptable to a variety of applications. The system is implemented entirely in Prolog, a programming language based on logic. With the aid of a logic-based grammar formalism called extraposition grammars, C h a t - 8 0 translates English questions into the Prolog subset of logic. The resulting logical expression is then transformed by a planning algorithm into efficient Prolog, cf. "query optimisation" in a relational database. Finally, the Prolog form is executed to yield the answer. On a domain of world geography, most questions within the English subset are answered in well under one second, including relatively complex queries.
1. Introduction
This p a p e r d e s c r i b e s the results of a t h r e e - y e a r r e s e a r c h p r o j e c t carried out b y the t w o of us. T h e p r o j e c t was d i r e c t e d t o w a r d s the goal of p r o v i d i n g practical c o m p u t e r s y s t e m s that will answer questions e x p r e s s e d in precisely d e f i n e d subsets of n a t u r a l lan- guage. T h e results of o u r w o r k are i n c o r p o r a t e d in a running p r o t o t y p e system, called " C h a t - 8 0 " .
T w o issues h a v e p a r t i c u l a r l y i n f l u e n c e d the a p - p r o a c h we h a v e taken, n a m e l y efficiency a n d portabili- ty. G i v e n the p r a c t i c a l o b j e c t i v e , we w a n t e d to achieve rapid, interactive question answering, and we w a n t e d the techniques to be easily a d a p t a b l e to a vari- ety of applications, with as m u c h of the i m p l e m e n t a - tion c o d e as possible b e i n g a p p l i c a t i o n i n d e p e n d e n t (cf. Konolige 1979).
T h e r e has b e e n no intention to try to handle unres- tricted natural language. G i v e n the c u r r e n t state of the art, we a c c e p t t h a t users of a p r a c t i c a l n a t u r a l language question answering s y s t e m will h a v e to learn h o w to use a restricted natural language subset rele-
1 This work was carried out in the Department of Artificial Intelligence, University of Edinburgh, Scotland.
v a n t to the particular application. T h e i m p o r t a n t issue is w h e t h e r t h e y will find this m o r e c o n v e n i e n t t h a n a m o r e f o r m a l q u e r y language. W e b e l i e v e t h a t , f o r m a n y purposes, a suitable n a t u r a l language subset will be m u c h p r e f e r r e d , on g r o u n d s of conciseness a n d ease of typing alone (see the e x a m p l e s in A p p e n d i x III, f o r instance). It is fair to say t h a t o u r o b j e c t i v e is to so c o n s t r a i n natural language t h a t it b e c o m e s a formal, b u t user-friendly, q u e r y language.
T h e s t a r t i n g p o i n t f o r o u r w o r k was a q u e s t i o n answering s y s t e m for a small subset of Spanish imple- m e n t e d b y V e r o n i c a D a h l 1 9 8 1 , 1 9 7 9 , following the a p p r o a c h a d v o c a t e d b y C o l m e r a u e r 1978. We w e r e particularly a t t r a c t e d to C o l m e r a u e r ' s a p p r o a c h for the clear insight it gives into s o m e of the essential p r o b - lems involved in c o n s t r u c t i n g a practical natural lan- guage a n s w e r i n g s y s t e m , especially the p r o b l e m of c o r r e c t l y i n t e r p r e t i n g d e t e r m i n e r s . In addition, it p r o v e d v e r y e a s y to a d a p t D a h l ' s p r o g r a m to English ( a n d to a different d o m a i n ) . This was due in large p a r t to the fact t h a t the s y s t e m is i m p l e m e n t e d in P r o - log ( R o u s s e l 1975; W a r r e n , P e r e i r a , a n d P e r e i r a 1977), a p r o g r a m m i n g l a n g u a g e b a s e d on f i r s t - o r d e r logic. T o be m o r e specific, the s y s t e m is largely m a d e
Copyright 1982 by the Association for Computational Linguistics. Permission to copy without fee all or part of this material is granted provided that the copies are not made for direct commercial advantage and the Journal reference and this copyright notice are included on the first page. To copy otherwise, or to republish, requires a fee and/or specific permission.
David H.D. Warren and Fernando C.N. Pereira An Efficient Easily Adaptable System
up of rules of the m e t a m o r p h o s i s g r a m m a r (MG) for- malism ( C o l m e r a u e r 1978), which m a p directly into the Prolog subset of logic. MGs are an extension of a simpler f o r m a l i s m to which we have given the n a m e definite clause g r a m m a r s (DCGs) (Pereira and W a r r e n 1980).
We called the a d a p t e d p r o g r a m " C h a t " . W h e n running compiled under DEC-10 Prolog ( W a r r e n 1979; Pereira, Pereira, and W a r r e n 1978), C h a t ' s speed at analysing English s e n t e n c e s p r o v e d v e r y s a t i s f a c t o r y (under a tenth of a second of CPU time per sentence). T h e r e f o r e this s e e m e d a promising a p p r o a c h f r o m the point of view of b o t h efficiency and portability. H o w - ever, we f o u n d that C h a t has a n u m b e r of s h o r t c o m - ings, the m o s t serious of which is that the p r o c e s s of answering a question, o n c e it has b e e n analysed, is m u c h too inefficient for any significant application.
We h a v e t h e r e f o r e w r i t t e n an entirely n e w p r o - gram, C h a t - 8 0 , which, like the original Chat, is imple- m e n t e d entirely in Prolog. T h e main ways in which C h a t - 8 0 differs f r o m its f o r e r u n n e r are:
• the semantics given to determiners, and the rules f o r determining their scopes,
• the process of planning and executing a query, • the rather wider c o v e r a g e of English,
• the use of extraposition grammars (XGs) in place of MGs to handle c e r t a i n " t r a n s f o r m a t i o n a l " a s p e c t s of English,
• the w a y the natural language analysis is p e r f o r m e d in three s e p a r a t e phases r a t h e r t h a n one.
In order to test the a p p r o a c h on a nontrivial d o - main, C h a t - 8 0 includes a d a t a b a s e of facts a b o u t world g e o g r a p h y , and a small v o c a b u l a r y of English words sufficient for querying the database. This d o - main has the advantage, for d e m o n s t r a t i o n purposes, that the facts in the d a t a b a s e are generally c o m m o n knowledge, so it is easier to a p p r e c i a t e w h a t is entailed in answering different queries. T h e d a t a b a s e contains basic facts a b o u t the world's countries (over 150 of t h e m ) , o c e a n s , m a j o r seas, m a j o r rivers, and m a j o r cities. The largest relation, ' b o r d e r s ' , r e p r e s e n t s all pairs of countries, oceans, or m a j o r seas that are adja- cent, and contains t h e r e f o r e o v e r 850 tuples. It should be emphasised that the d a t a b a s e is itself i m p l e m e n t e d as ordinary Prolog; it t h e r e f o r e resides within the nor- mal DEC-10 virtual m e m o r y .
C h a t - 8 0 processes a question in three main stages: English translation logic planning Prolog execution answer c o r r e s p o n d i n g r o u g h l y to: " W h a t d o e s the q u e s t i o n m e a n ? " , " H o w shall I a n s w e r it?", " W h a t is the an- s w e r ? " . T h e planning and e x e c u t i o n stages are dis- cussed in detail in a c o m p a n i o n p a p e r ( W a r r e n 1981), so here we will c o n c e n t r a t e on the translation stage, which is responsible for the natural language analysis. We first describe the w a y we r e p r e s e n t the " m e a n i n g " of an English s e n t e n c e as a logical e x p r e s s i o n , a n d then outline h o w the translation process is formalised, in logic, as a practical Prolog p r o g r a m . Finally, we b r i e f l y explain h o w the logical f o r m is t r a n s f o r m e d into a Prolog p r o g r a m by the planning phase and h o w it is t h e n executed.
2. A S i m p l i f i e d S e m a n t i c s f o r a Basic English S u b s e t T o answer a question, one first has to u n d e r s t a n d w h a t it means. If question answering is to be done b y c o m p u t e r , there needs to be s o m e precise r e p r e s e n t a - tion f o r the result of this first process, w h a t one might call the " m e a n i n g " of the question, a n d also s o m e precise w a y of relating the question to its meaning. It is f u r t h e r n e c e s s a r y t h a t the m e a n i n g r e p r e s e n t a t i o n can in some w a y be given a precise i n t e r p r e t a t i o n (or " s e m a n t i c s " ) so that, in the case of questions for in- stance, o n e then k n o w s precisely w h a t is or is not a c o r r e c t answer to the questions. It is surprising that, e v e n for such basic f e a t u r e s of English as the c o m m o n d e t e r m i n e r s , a n d e v e n within the d i f f e r e n t l a n g u a g e c a m p s r e p r e s e n t e d by linguistics, philosophy, and arti- ficial intelligence, there is as yet no established solu- tion to this p r o b l e m .
O n e w a y to try to articulate the m e a n i n g of a sen- tence is to p a r a p h r a s e it into s o m e standard, u n a m b i - guous f o r m of English. Since these s t a n d a r d f o r m s are likely to be stilted and long-winded, it will p r o b a b l y be c o n v e n i e n t to r e p r e s e n t t h e m in a m o r e concise n o t a - tion. This is essentially the logician's a p p r o a c h , and we will call such m e a n i n g r e p r e s e n t a t i o n s " l o g i c a l f o r m s " .
C h a t - 8 0 r e p r e s e n t s the m e a n i n g of a question b y a logical form. T h e a p p r o a c h is a d e v e l o p m e n t of that p r o p o s e d b y C o l m e r a u e r 1978 a n d i m p l e m e n t e d b y Dahl 1981,1979.
W o r d s a p p r o x i m a t i n g to the status of " p r o p e r n o u n s " are r e p r e s e n t e d b y logical constants, f o r e x a m - ple:
France france
the Soviet Union soviet union
wine wine
M o s t verbs, nouns, and adjectives ( t o g e t h e r with a n y associated prepositions) are r e p r e s e n t e d b y predicates, taking one or m o r e arguments (which for our p u r p o s e s are called c o n s t a n t s ) . A predicate with its a r g u m e n t s is called a predication (or s o m e t i m e s a goal). E x a m - ples are:
David H.D. Warren and Fernando C.N. Pereira An Efficient Easily Adaptable System
F r a n c e exports wine to Britain.
exports (france, wine, britain) F r a n c e is a country, c o u n t r y ( f r a n c e ) Paris is the capital of France. capital(france,paris) F r a n c e is European. e u r o p e a n ( f r a n c e ) M a n y kinds of more complex phrases or sentences can be r e p r e s e n t e d by conjunctions of predications, for example:
Paris is a E u r o p e a n city.
european(paris) & city(paris). F r a n c e is a c o u n t r y that borders on Spain.
c o u n t r y ( f r a n c e ) & b o r d e r s ( f r a n c e , s p a i n ) T h e second of these conjunctions, for example, can be read m o r e literally as a s h o r t h a n d f o r " F r a n c e is a c o u n t r y and F r a n c e b o r d e r s Spain", which is just a paraphrase of the original sentence.
The most important class of words not c o v e r e d so far are the determiners - words such as " a " , " t h e " , " e v e r y " . D e t e r m i n e r s play a particularly i m p o r t a n t role in questions, since they enable relatively complex requests for i n f o r m a t i o n to be expressed very concise- ly.
In Colmerauer's approach, each d e t e r m i n e r is rep- r e s e n t e d by what he called a " t h r e e - b r a n c h e d q u a n t i f i e r " (3BQ). F o r example, the logical form that would be ascribed to the sentence " T h e b o y sleeps" would be:
t h e ( X , b o y ( X ) , s l e e p s ( X ) )
where the d e t e r m i n e r " t h e " is r e p r e s e n t e d by the 3BQ ' t h e ( , , )'. 3BQs are very close to the meaning representat'ion for determiners used by W o o d s in the L U N A R system ( 1 9 7 7 ) . C o l m e r a u e r gave 3BQs a precise semantics in terms of certain operations over sets. H o w e v e r , we have f o u n d that this way of inter- preting 3BQs fails to give a correct model of natural language in certain cases, and, worse still, it does not appear to lend itself to efficient implementation. Cer- tainly this is the case with Dahl's p r o g r a m which, while being very efficient at understanding questions, is hopelessly inefficient at answering questions where the domain is of any significant size.
In Chat-80, we have addressed these problems by instead translating 3BQs directly into s t a n d a r d first- order logic, or rather into something as close to first- o r d e r logic as is practical. T o be more exact, we translate into the P r o l o g subset of logic, which we have a u g m e n t e d with certain " m e t a - l o g i c a l " e x t e n - sions. (A similar approach has b e e n t a k e n by M c C o r d 1982, who has i n d e p e n d e n t l y been developing a sys- tem i n f l u e n c e d by the C o l m e r a u e r / D a h l a p p r o a c h . ) The subset of first-order logic we have chosen has the great advantage as a meaning r e p r e s e n t a t i o n that it already has a well u n d e r s t o o d semantics which is amenable to very efficient implementation. Thus the m e a n i n g r e p r e s e n t a t i o n can in principle be directly
e x e c u t e d as a Prolog p r o g r a m (whereas 3BQs require a special-purpose interpreter). F u r t h e r m o r e , the first- o r d e r logic f o r m u l a t i o n lends itself to t r a n s f o r m a t i o n s which can greatly improve the efficiency of execution. This c o r r e s p o n d s to what is k n o w n as " q u e r y optimisation" in relational database circles, and will be discussed in more detail later.
Our t r a n s l a t i o n into logic c o m p l e t e l y ignores the presuppositions which can be implicit in a natural lan- guage question, and which C o l m e r a u e r ' s 3BQ seman- tics t o o k pains to reflect. In most situations that we are c o n c e r n e d with, this simplification seems relatively harmless or e v e n beneficial. F o r example, C h a t - 8 0 ignores the presupposition that there is only one an- swer to the question " W h i c h o c e a n b o r d e r s the U n i t e d States?", and simply gives all three answers without f u r t h e r comment.
T h e way we translate d e t e r m i n e r s into logic is shown in Figure 1. E a c h d e t e r m i n e r is translated into a quantification, which introduces some logic variable (X, N, etc.), and which links two predications involv- ing that variable, called the range and scope, indicated by R and S.
The determiners " a " , " t h e " (in a singular c o n t e x t ) , and " s o m e " ( w h e t h e r in a singular or plural c o n t e x t ) are all translated in exactly the same way, by a stand- ard f i r s t - o r d e r logic existential quantification. R e a d 'exists(X,P)' as " t h e r e is some X such that P " . The same translation is also normally used for the " e m p t y plural" determiner, for example:
Zambia exports minerals.
exists(X,mineral(X) & e x p o r t s ( z a m b i a , X ) ) . The d e t e r m i n e r " n o " is translated with the aid of a kind of negation. Read ' \ + P ' as " i t c a n n o t be shown that P " . N o t e that this is not the standard negation of f i r s t - o r d e r logic, which is outside the P r o l o g subset. S t a n d a r d n e g a t i o n is p r o b l e m a t i c to i m p l e m e n t and seems inappropriate for m a n y purposes. Instead Pro- log systems provide (or can easily be e x t e n d e d with) a partial implementation of nonprovability. T h e predica- tion ' \ + P ' is c o n s i d e r e d true if P is not deducible from the facts and rules which define a particular ap- plication domain. N o t e that n o n p r o v a b i l i t y is also used in the translation of the d e t e r m i n e r s " e v e r y " and "all".
The d e t e r m i n e r " t h e " in a plural c o n t e x t presents a n u m b e r of problems, for which we do not yet feel we have a completely adequate solution. In general, we consider a plural definite noun phrase to d e n o t e a set. T o cater for this, we have p r o p o s e d and i m p l e m e n t e d a " m e t a - l o g i c a l " extension to Prolog, which has b e e n d e s c r i b e d in detail elsewhere ( W a r r e n , 1982; Byrd, Pereira, and W a r r e n 1980). T h e e x t e n s i o n allows predications of the form:
David H.D. Warren and Fernando C.N. Pereira An Efficient Easily Adaptable System a, some, the[singular] n o every, all the[plural] one, two, ... n u m e r a l ( N ) which, what how many exists(X,R & S) \ + e x i s t s ( X , R & S) \ + e x i s t s ( X , R & \ + S ) e x i s t s ( X , s e t o f ( X , R , X ) & S) n u m b e r o f ( X , R & S,N) a n s w e r ( X ) < = R & S a n s w e r ( N ) < = n u m b e r o f ( X , R & S,N) S o m e birds migrate. e x i s t s ( X , b i r d ( X ) & m i g r a t e s ( X ) ) .
The p o p u l a t i o n of Britain exceeds 50 million.
e x i s t s ( X , p o p u l a t i o n ( b r i t a i n , X ) & X > 5 0 0 0 0 0 0 0 ) . T h e r e are no rivers in Antarctica.
\ + e x i s t s ( X , r i v e r ( X ) & i n ( X , a n t a r c t i c a ) ) . M a n inhabits every continent.
\ + e x i s t s ( X , c o n t i n e n t ( X ) & \ + i n h a b i t s ( m a n , X ) ) . Jupiter is the largest of the planets.
e x i s t s ( X , s e t o f ( X , p l a n e t ( X ) , X ) & l a r g e s t ( X , j u p i t e r ) ) . T h e Rhine flows t h r o u g h three countries.
n u m b e r o f ( X , c o u n t r y ( X ) & flows t h r o u g h ( r h i n e , X ) , 3 ) .
Which birds migrate?
a n s w e r ( X ) < = b i r d ( X ) & m i g r a t e s ( X ) .
How many countries e x p o r t oil?
a n s w e r ( N ) < = n u m b e r o f ( X , c o u n t r y ( X ) & e x p o r t s ( X , o i l ) , N ) .
Figure 1. Translations of determiners. to be r e a d as " t h e set of Xs such t h a t P is p r o v a b l e is
S, where S is n o n e m p t y " . N o t e that this c o n s t r u c t b e h a v e s like a q u a n t i f i c a t i o n in t h a t it i n t r o d u c e s a variable (or, m o r e generally, a collection of variables) X which is purely local to P. Thus it is possible, as in the t r a n s l a t i o n of the plural definite article given in Figure 1, to use the same variable n a m e for a set and its " t y p i c a l " element.
O u r translation entails t h a t certain predicates c a n take sets as arguments. At present, we leave it up to the definition of each individual predicate to draw a n y n e c e s s a r y c o r r e s p o n d e n c e b e t w e e n p r e d i c a t i o n s o v e r sets and predications o v e r individuals, since it is hard to fix a general rule. To see w h a t the p r o b l e m is, c o m p a r e the sentences:
T h e b o y s like the girls.
The b o y s are m a r r i e d to the girls. In certain contexts, such as:
W h a t are the ages of the b o y s ?
plural definite noun phrases are translated s o m e w h a t differently, as indexed sets. M o r e on this later.
F o r c o n v e n i e n c e in translating the numerals " o n e " , " t w o " , " t h r e e " , etc., we allow p r e d i c a t i o n s of the form:
numberof (X,P,N)
m e a n i n g " t h e n u m b e r of Xs such that P is p r o v a b l e is N " . This predicate can easily be defined in t e r m s of ' s e t o f ' b y the logical implication:
n u m b e r o f ( X , P , N ) < = s e t o f ( X , P , S ) & sizeof(S,N) R e a d ' P < = Q ' as " P if Q " . T h e predicate ' s i z e o f ' just gives the n u m b e r of e l e m e n t s in a set.
Notice that implications are also used in the trans- lation of questions. R e a d ' a n s w e r ( X ) < = P ' as " X is an a n s w e r if P " or "I w a n t to k n o w X if P (is t r u e ) " . Variables in the ' a n s w e r ' predicate are not explicitly quantified. Such free variables are interpreted, follow- ing n o r m a l c o n v e n t i o n s in logic, as though t h e y were universally q u a n t i f i e d ; t h a t is, o n e m a y p r e f i x o n e ' s reading of the entire logical f o r m with phrases " F o r a n y X, for a n y Y , " etc.
We h a v e n o w s e e n h o w s o m e c o m m o n t y p e s of English words are t r a n s l a t e d into bits of logical struc- ture. It r e m a i n s to discuss h o w the bits fit t o g e t h e r to p r o d u c e the c o m p l e t e logical f o r m f o r a whole sen- tence. F o r example, a s e n t e n c e within the scope of our subset is"
Which E u r o p e a n c o u n t r y e x p o r t s no arms to c o u n - tries in Africa?
H o w is it that the bits of structure c o r r e s p o n d i n g to each individual w o r k in this s e n t e n c e fit t o g e t h e r to p r o d u c e the following logical form:
David H,D. Warren and Fernando C.N. Pereira An Efficient Easily Adaptable System
answer(C) < = e u r o p e a n ( C ) & c o u n t r y ( C ) & \ +exists(X, arm(X) &
exists(C1, c o u n t r y ( C 1 ) & i n ( C l , a f r i c a ) & e x p o r t s ( C , X , C 1 ) ) )
(One should realize that this is just a shorthand for " F o r any C, C is an answer if C is E u r o p e a n and C is a c o u n t r y and it c a n n o t be shown that there is some X such that X is an a r m a m e n t and there is some C1 such that C1 is a c o u n t r y and C1 is in Africa and C exports X to C I " . ) Hopefully, the reader should already have a fair intuitive idea of what the "assembly p r o c e s s " must do. Basically, there are two main problems.
First, h o w are the a p p r o p r i a t e variables or con- stants chosen to fill each predicate argument position? F o r example, why is the last argument of 'exports' the same variable C1 that appears as arguments to ' c o u n t r y ' and 'in'? This " s l o t filling" is d e t e r m i n e d mainly by the grammatical structure of the sentence, b u t the c o r r e c t a t t a c h m e n t of prepositional phrases o f t e n c a n n o t be d e t e r m i n e d on purely syntactic grounds.
Second, what determines the scope of the different quantifications? F o r example, why is the existential quantification corresponding to the e m p t y d e t e r m i n e r g o v e r n i n g " c o u n t r i e s in A f r i c a " n e s t e d inside the quantification corresponding to " n o " ? This " s c o p i n g " is only weakly i n f l u e n c e d by grammatical structure. Indeed, it is possible to give an alternative but much less likely reading to our example sentence, which corresponds to the same grammatical structure, but to a different logical form where the nesting of the two inner quantifications is reversed. T h e more likely reading is that no arms are e x p o r t e d to any countries in Africa; the less likely reading is that no arms are e x p o r t e d to certain countries in Africa.
The details of our mapping from English into logic are made precise in the program text corresponding to the first phase of Chat-80. This text itself consists of clauses of the Prolog subset of logic. It serves b o t h as a clear f o r m a l definition of our mapping and, w h e n e x e c u t e d by Prolog, as an efficient implementation of that mapping, which performs the translation of Eng- lish questions into their logical forms. A fuller discus- sion of this implementation will be given in the next section, and f u r t h e r details can be f o u n d in P e r e i r a 1982.
3. Translating English into Logic, in Logic
T h e translation f r o m English s e n t e n c e to logical form can be seen as involving three main functions - the slot filling and scope determination m e n t i o n e d in the last section, and in addition the parsing function, which determines the grammatical structure of a sen- tence. In Chat-80, in contrast to Dahl's s~stem, these
t h r e e functions are s e p a r a t e d into distinct p r o g r a m modules, which operate in sequence:
English question parsing p h r a s e structure i n t e r p r e t a t i o n semantic structure scoping logical f o r m
The parsing module consists of a set of grammar rules of the XG formalism, which the Prolog system preprocesses into Prolog clauses. The i n t e r p r e t a t i o n and scoping m o d u l e s consist of various t r a n s l a t i o n rules, expressed directly as Prolog clauses. Executing the grammar rules with Prolog leads to a straightfor- ward t o p - d o w n , b a c k t r a c k parsing strategy ( P e r e i r a and W a r r e n 1980). A l t h o u g h the main c o n c e r n in writing the grammar was to p r o d u c e a clear description of the language covered, some concessions have had to be made to achieve a r e a s o n a b l y efficient b e h a v i o u r with the a b o v e parsing strategy; in particular, left- recursive rules have b e e n avoided. It is s o m e w h a t c o n t r a r y to current opinion that such a grammar, not carefully designed for parsing, can also be the basis of an efficient parser. One of the reasons for the effi- ciency in this case m a y be that the g r a m m a r itself makes no a t t e m p t to give the " r i g h t " modifier attach- ments, as discussed below.
T h e r e has b e e n some d e b a t e on w h e t h e r the differ- ent parts of language analysis, such as the three distin- guished above, should be d o n e serially or c o n c u r r e n t l y ( B u r t o n 1976; W o o d s 1977). Some of the arguments for c o n c u r r e n t o p e r a t i o n are that early semantic inter- pretation limits search by bringing in relevant informa- tion at the earliest possible m o m e n t , and that piece- wise generation of the i n t e r p r e t a t i o n is psychologically more plausible. Given that we are not proposing a model of language c o m p r e h e n s i o n in people, the latter argument is not directly relevant. T h e o t h e r argument is a t w o - e d g e d one: by i n t e r w e a v i n g several o p e r a - tions, one is multiplying t o g e t h e r their n o n d e t e r m i n a - cies. T h e r e are two main reasons why we have c h o s e n serial operation. The first is that serial o p e r a t i o n is much simpler both conceptually and in programming terms, particularly if one is trying to deal flexibly with global properties of the input, for instance the relative scopes of determiners. T h e o t h e r r e a s o n is that the b a c k t r a c k i n g traditionally associated with m o d i f i e r a t t a c h m e n t can be avoided by a careful choice of the parse trees p r o d u c e d by the parsing module.
In typical systems w h e r e syntactic and semantic f u n c t i o n s o p e r a t e in s e q u e n c e ( W o o d s , Kaplan, and N a s h - W e b b e r 1972), choices are made in the syntactic analysis that m a y be f o u n d to be i n a d e q u a t e on se-
David H.D. Warren and Fernando C.N. Pereira An Efficient Easily Adaptable System
mantic grounds, as for example in prepositional phrase attachment. In the present system, the syntactic com- p o n e n t of the grammar contains additional constraints which block all but one of the potential attachments of each postmodifier. Thus, all analyses produces are in a kind of normal form with r e s p e c t to p o s t m o d i f i e r attachment. F r o m this normal form, subsequent oper- ations can r e c o n s t r u c t o t h e r alternative analyses, if that is n e e d e d on semantic grounds. The use of nor- mal form analyses has the useful c o n s e q u e n c e of mak- ing apparent other, significant, ambiguities in the in- put, which otherwise would be s w a m p e d by a large n u m b e r of alternative analyses differing only with respect to modifier attachment.
A m a j o r limitation of the c u r r e n t system is that p r o n o u n s ( o t h e r than interrogative and relative pro- nouns) are not c o v e r e d at all by the translation phase. This makes the natural language subset strictly less powerful than the underlying logic. F o r example, the following sentence has a logical form which c a n n o t be r e n d e r e d in our natural language subset:
Which c o u n t r y contains a city bigger than its capital? answer(C) < = c o u n t r y ( C ) &
exists(X, c o n t a i n s ( C , X ) & city(X) &
exists(Y, bigger(X,Y) & capital(C,Y) ) ). To each of the three modules of the translation process there corresponds a separate dictionary. The g r a m m a r d i c t i o n a r y contains definitions of the usual syntactic categories, b o t h for g e n e r a l - p u r p o s e , or " c l o s e d - c a t e g o r y " , words, such as determiners, and for application d e p e n d e n t , or " c o n t e n t " , words, such as the nouns and verbs corresponding to database predi- cates. T h e slot filling m o d u l e has a d i c t i o n a r y of templates, which define the translation of words to predicates and the argument patterns required for each such translation. Each application will require a dif- f e r e n t set of templates. Finally, the scope determina- tion module has a small dictionary defining the scope relationships for d e t e r m i n e r s and o t h e r " o p e r a t o r " words, and their translation as discussed in the last section. This dictionary is i n d e p e n d e n t of the applica- tion domain. The dictionaries are divided in this man- ner for c o n c e p t u a l and p r o g r a m m i n g reasons, but it would not be difficult to write a program to create the dictionary entries from a more user-oriented dictionary format. The complete dictionary definition for a sin- gle word is shown in Appendix II.
3.1. P h r a s e S t r u c t u r e
A grammar for any substantial language fragment needs to define grammatical relationships which we m a y call " t r a n s f o r m a t i o n a l " , that is, relationships which c a n n o t be described directly by a small n u m b e r of phrase structure ( c o n t e x t - f r e e ) rules. B o t h MGs (used in Dahl's system) and DCGs have general pro-
gramming power, and so can describe any " t r a n s f o r m a t i o n a l " relationship, but they c a n n o t do so by specific, well motivated grammar rules. In particu- lar, this applies to " l e f t e x t r a p o s i t i o n " , the underlying c o n c e p t in most grammars for such i m p o r t a n t con- structions as WH-questions, relative clauses, and auxil- iary fronting. Similar c o m m e n t s apply to ATNs (Woods 1970), even those using the HOLD/VIR facili- ty.
T o handle " l e f t e x t r a p o s i t i o n " , and some o t h e r " t r a n s f o r m a t i o n a l " concepts, we have i n t r o d u c e d the g r a m m a r formalism of extraposition grammars, which are described fully elsewhere (Pereira 1981). An XG, like a DCG, is no more t h a n " s y n t a c t i c s u g a r " for clauses of logic.
As the C h a t - 8 0 g r a m m a r is i n t e n d e d partly as a d e m o n s t r a t i o n of the p o w e r of XGs for treating left extraposition in English, the coverage of questions and relative clauses is fairly extensive. O f course, this wide coverage is essential if complex queries are to be f o r m u l a t e d in a single sentence.
A major limitation in the present coverage of Eng- lish syntax is that the only phrases that may be con- joined (with " a n d " , etc.) are noun postmodifiers and predications i n t r o d u c e d by the verb 'to be'. T o cover more general c o n j u n c t i o n s would require a m i n o r change in the XG formalism, to cope with the interac- tion b e t w e e n left extraposition and conjoined phrases.
The analysis of a sentence p r o d u c e d by the Chat- 80 grammar is a fairly conventional a n n o t a t e d surface structure, where in general the subtrees for all phrases appear in the same o r d e r as in the input. This is es- sential for the heuristics used in the scoping o p e r a - tions, which rely on the l e f t - t o - r i g h t o r d e r of n o u n phrases.
3.2. A t t a c h i n g A r g u m e n t s a n d M o d i f i e r s
As we have seen, the translation of c o n t e n t words into predicates is defined by dictionary templates. Of course, certain words, like " a v e r a g e " , " n u m b e r ( o f ) " and superlative adjectives, c a n n o t be t r a n s l a t e d as first-order predicates, but represent some higher-order operation. Templates specify, for each argument posi- tion of a predicate which translates a word, the " c a s e " (usually a preposition) and the most general entity type that can fill the position, or slot. T y p e matching helps the system to find a semantically s o u n d a r g u m e n t placement, and is also used to create additional predi- cations when attributes are r e f e r r e d to implicitly, as in comparatives. Templates are similar to the dictionary entries in Dahl's system, but our a t t a c h m e n t p r o c e - dure, by being separate from the syntax analysis, can be much more flexible in deciding how to fill slots.
T h e following are typical application d e p e n d e n t templates:
David H.D. Warren and Fernando C.N. Pereira An Efficient Easily Adaptable System
p r o p e r t y ( a r e a , m e a s u r e & a r e a , A , r e g i o n & T y p e , R ,
a r e a ( R , A ) ) . t r a n s i t i v e ( e x c e e d , m e a s u r e & T y p e , X , m e a s u r e & T y p e , Y ,
e x c e e d s ( X , Y ) ) . The first t e m p l a t e states that ' a r e a ' is a " p r o p e r t y " , a subclass of nouns which require an a r g u m e n t m a r k e d by the p r e p o s i t i o n " o f " . Variable A in this t e m p l a t e c o r r e s p o n d s to the " a r e a " value, which belongs to the s u b - t y p e ' a r e a ' of the t y p e ' m e a s u r e ' . V a r i a b l e R cor- r e s p o n d s to the thing having an area, and belongs to s o m e s u b - t y p e of t y p e ' r e g i o n ' . The p r e d i c a t i o n f o r this w o r d is ' a r e a ( R , A ) ' . T h e second t e m p l a t e states t h a t " ( t o ) e x c e e d " is a transitive verb, whose subject X and o b j e c t Y are b o t h m e a s u r e s of s o m e c o m m o n t y p e T y p e , a n d ' e x c e e d s ( X , Y ) ' is the c o r r e s p o n d i n g predication.
W h e n P r o l o g a c c e s s e s such t e m p l a t e s , u n i f i c a t i o n a u t o m a t i c a l l y does m o s t of the w o r k of " s l o t filling".
T h e result of the slot filling process is a tree with three kinds of nodes, quantification n o d e s ( Q u a n t s ) , p r e d i c a t i o n n o d e s ( P r e d s ) and c o n j u n c t i o n n o d e s ( C o n j s ) . Q u a n t s c o r r e s p o n d to n o u n phrases, Preds to verbs, a n d Conjs to c o n j o i n e d restrictive modifiers.
As we h a v e seen, quantifications play a crucial role in the translation of sentences into logics. T h e fields of a Q u a n t are:
• the determiner, which can be an English d e t e r m i n e r or o n e of the special d e t e r m i n e r s described below; • the head, which is either the p r e d i c a t i o n translating
the head n o u n of a n o u n phrase, or a t e r m d e n o t i n g a h i g h e r - o r d e r o p e r a t i o n ;
• the predication, a tree describing restrictions on the h e a d whose d e t e r m i n e r s have n a r r o w e r scope t h a n the d e t e r m i n e r on this Q u a n t ;
• the arguments, a list of the trees for the a r g u m e n t s of the noun, t o g e t h e r with the trees of those re- strictions whose d e t e r m i n e r s m a y h a v e wider scope t h a n the p r e s e n t one;
• the b o u n d variable for this quantification.
T h e distinction b e t w e e n the p r e d i c a t i o n and the argu- m e n t list of a Q u a n t c o r r e s p o n d s to one of the main scoping heuristics in the system: full relative clauses are the only s u b o r d i n a t e d phrases whose d e t e r m i n e r s c a n n o t " m o v e u p " to d o m i n a t e d e t e r m i n e r s in higher tree nodes. Thus, w h e n a Q u a n t is m a p p e d into a logic quantification, the head, predication, and s o m e of the a r g u m e n t s will t r a n s l a t e into the r a n g e of the quantification, w h e r e a s the scope will be m a d e f r o m the rest of the a r g u m e n t s and s o m e q u a n t i f i c a t i o n s which are higher in the tree but w h o s e d e t e r m i n e r s h a v e a n a r r o w e r scope t h a n the p r e s e n t one.
T h e d e t e r m i n e r of a Q u a n t m a y not be the original English d e t e r m i n e r of the c o r r e s p o n d i n g noun phrase. In nested plural definite n o u n phrases, only the highest d e t e r m i n e r gets translated into a set expression follow-
ing the translation table of Figure 1; lower d e t e r m i n e r s are u n d e r s t o o d to index t h a t set, and are r e p r e s e n t e d in Q u a n t s b y an index token. F o r e x a m p l e , the n o u n phrase:
the children of the e m p l o y e e s
t r a n s l a t e s into a set of sets of children, i n d e x e d b y e m p l o y e e s :
s e t o f ( E - S , e m p l o y e e ( E ) & s e t o f ( C , c h i l d ( E , C ) , S ) , S1).
3.3. Meaning and Scope of Quantifications
G i v e n the tree of Q u a n t s , Preds, and C o n j s p r o - d u c e d b y slot filling, the final m o d u l e specifies the relative s c o p e s of d e t e r m i n e r s , of n e g a t i o n , a n d of question markers. T h e m a i n i n f o r m a t i o n f o r this m o - dule is a set of rules of t h u m b a b o u t w h a t d e t e r m i n e r s usually " g o v e r n " o t h e r determiners. T h e relationship of " g o v e r n i n g " is n o t a total order, or e v e n a partial order: it is only m e a n i n g f u l for pairs of o p e r a t o r s , one in a s u b o r d i n a t i n g a n d the o t h e r in a s u b o r d i n a t e d position. Relative scopes not d e c i d e d b y " g o v e r n i n g " are decided b y the l e f t - t o - r i g h t o r d e r of p h r a s e s in the input sentence.
O u r scope rules are m o r e a c c u r a t e t h a n those p r o - p o s e d b y C o l m e r a u e r 1982 and used in D a h l ' s system. C o l m e r a u e r ' s rules d e t e r m i n e relative scope strictly on the basis of p r e d i c a t e - a r g u m e n t relationships d e f i n e d in syntactic terms. O u r rules are r e l a t e d to the ideas for i m p r o v i n g LUNAR discussed b y W o o d s 1977 a n d V a n l e h n 1978. U n f o r t u n a t e l y , e x c e p t f o r set a n d h i g h e r - o r d e r o p e r a t i o n s , we h a v e no m e a n s of using the distinct roles of d i f f e r e n t a r g u m e n t places to help decide the scopes of their fillers.
As an e x a m p l e of our s c o p e rules, the d e t e r m i n e r ' e a c h ' is a s s u m e d to h a v e a " d i s t r i b u t i v e " role, a n d g o v e r n s m o s t o t h e r d e t e r m i n e r s , a n d also q u e s t i o n m a r k e r s , so the reply to a question containing ' e a c h ' will be an indexed list of values, o n e for e a c h entity satisfying the conditions in the n o u n p h r a s e with that determiner. A n e g a t e d verb, h o w e v e r , will p r e v e n t an ' e a c h ' in a n y of its a r g u m e n t s f r o m assuming its dis- tributive role. In fact, no d e t e r m i n e r g o v e r n s a n e g a - tion except ' a n y ' , which is seen as a universal quantifi- cation of wide scope relative to negation.
A p a r t f r o m deciding on relative scopes, this m o d u l e also specifies h o w set e x p r e s s i o n s are built f r o m plural d e t e r m i n e r s a n d index d e t e r m i n e r s , and w h a t are the f i r s t - o r d e r predications which m a k e the a r g u m e n t s of h i g h e r - o r d e r functions like ' a v e r a g e ' and ' n u m b e r of'.
4. Query Planning and Execution
We h a v e n o w seen h o w an English question is m a p - p e d into its logical form. Since the logical f o r m has a precise semantics, it is in principle possible to d e t e r - mine the a n s w e r to the question. H o w e v e r , there is a
David H.D. W a r r e n and Fernando C.N. Pereira An Efficient Easily Adaptable System
big difference between principle and practice. Can the process of finding the answer really be made fast enough for this to be useful for practical question an- swering purposes? The evidence of Chat-80 is that it can.
The key question here is how to avoid combinatori- al explosion. Naive question-answering strategies typically take a time that is exponential in the size of the query. Even for relatively small databases, such as that in Chat-80, exponential behaviour will be disas- trous for non-trivial queries (and non-trivial queries are what a natural language interface encourages). A query over a small database that can be answered almost instantaneously with the right question- answering strategy may easily take hours with a poor algorithm. We had actual experience of this phenome- non when we experimented with mounting the Chat database on the relational database system Ingres (Stonebraker, Wong, Kreps, and Held 1976). Simple queries Ingres handled easily, but on queries involving more than two relations, which were no problem for Chat, Ingres usually bogged down completely. We therefore think that the question-answering part of natural language question-answering is at least as wor- thy of attention as the natural language part, and the two should be studied hand in hand.
A complete description of the way Chat-80 proc- esses logic queries, together with a fuller discussion of the efficiency issues, is given in a separate paper (Warren 1981), which we urge the interested reader to consult. Here we just give a brief summary, illustrated by one example. Basically, Chat-80 augments the logical form of a query with extra control information, to make it into an efficient piece of Prolog program, which can then be directly executed to produce the answer. The control information is computed by a general planning algorithm, applicable to any query in the logic subset, not just to those derivable from the present natural language subset. The planning process makes use of certain statistics about the size, etc., of the domain relations, and is analogous to " q u e r y optimisation" in a relational database system.
The control information that is generated takes two forms:
• the ordering of predications within a query, which will determine the order in which Prolog will at- tempt to satisfy them;
• the marking of "independent subproblems" by en- closing them in braces, to limit (or " c u t " ) the amount of backtracking performed by Prolog. For example, here is an English question with the logical form produced by the natural language analysis phase of Chat-80:
"Which countries bordering the Mediterranean border Asian countries?"
answer(C) < = country(C) &
borders (C,mediterranean) &
e x i s t s ( C l , c o u n t r y ( C 1 ) & asian(C1) & borders(C,C 1))
After planning, the logical form is transformed into: answer(C) < = borders(C,mediterranean) &
{country(C)} & {borders(C,C1) & {asian(C1) & {country(C1)}}}
When executed by Prolog, this produces a behaviour equivalent to the following procedural interpretation: To generate an answer C:
generate a C bordering the mediterranean, and then check that C is a country, and then
check that it is possible to:
generate a C1 bordered by C, and then check that C1 is asian, and then check that C1 is a country.
Thus Prolog is led to answer the query in an obviously sensible way; it iterates through the countries border- ing the Mediterranean, and for each one, it iterates through the things bordering that country until it finds something that is an Asian country. In fact the DEC-10 Prolog compiler can in principle compile the transformed query into code which is comparable in efficiency with iterative loops in a conventional lan- guage (Warren 1977). However, in Chat-80 the transformed query is actually just interpreted.
5. P e r f o r m a n c e a n d P o r t a b i l i t y
Chat-80 at its current stage of implementation, covers a limited but useful subset of English. A fair idea of the range of the present subset is given by the examples in Appendix I. It will be seen that the sub- set includes nouns, verbs, adjectives, prepositions, and determiners, with a fairly full coverage of interrogative and relative constructions. We have concentrated on features of English that seemed essential for simple question answering; there are many directions in which the subset could usefully be extended and which do not appear to pose any particular difficulties.
At present, the system accepts a small vocabulary of about 100 domain dependent works (not counting proper nouns, but including alternative word forms such as plurals). This vocabulary can very easily be extended (as indicated below). In addition there are some 50 domain independent words. On the whole, any question that can be expressed using this vocabu- lary is correctly understood and answered by the sys- tem.
The sizes of the different components of the system are indicated below in terms of the approximate num- ber of Prolog clauses comprised, and the approximate number of DEC-10 (36-bit) words occupied:
David H.D. Warren and Fernando C.N. Pereira An Efficient Easily Adaptable System
DEC-10
clauses words
NL analysis 580 2 4 0 0 0
Q u e r y planning and execution, etc. 290 8500
Geographical vocabulary 180 4000
Geographical database 1590 22500
The speed of C h a t - 8 0 on some sample queries rela- ting to the geographical database is shown in A p p e n - dix I. Generally speaking, any q u e r y in this domain that can c o m f o r t a b l y be expressed in a single sentence of the English subset is answered in well u n d e r one second of CPU time. N o t e that the domain d e p e n d e n t v o c a b u l a r y could be m u c h e x t e n d e d w i t h o u t having any significant impact on these times (because of the way the dictionary is indexed).
It is also w o r t h noting that, for all but the simplest queries, natural language analysis r e p r e s e n t s only a small p r o p o r t i o n of the total time. This suggests that, as far as the efficiency of natural language question answering systems is c o n c e r n e d , it is the answering process r a t h e r than the natural language analysis to which most e f f o r t needs to be directed. Certainly this has b e e n our a p p r o a c h , although it appears to be somewhat c o n t r a r y to the prevailing view in artificial intelligence. In particular, parsing does not seem to pose any major efficiency problem, provided one does not e x p e c t the grammar to do too much.
As regards portability, we think C h a t - 8 0 should be relatively easy to adapt to different applications - for the same reasons that we f o u n d it easy to adapt Dahl's program to English and to a different domain.
Partly this is due to the fact that (in b o t h systems) the domain d e p e n d e n t parts are clearly separated f r o m the rest of the system, and are b r o k e n d o w n into small units which can be added incrementally as " d a t a " (see Appendix II). Thus our natural language analysis mo- dules deal exclusively with general features of English, in c o n t r a s t to the " s e m a n t i c g r a m m a r " a p p r o a c h ( B u r t o n 1976).
N o w there are o t h e r practical systems which have not taken the " s e m a n t i c g r a m m a r " approach but are, we feel, less easy to m o d i f y t h a n C h a t - 8 0 ; LUNAR (Woods, Kaplan, and N a s h - W e b b e r 1972) is a good example. The reason lies in the way " m e a n i n g s " are attached to words. In LUNAR, a meaning is simply a procedure. F o r nouns it is a p r o c e d u r e to generate objects in a certain class; for most o t h e r words it is a p r o c e d u r e to test w h e t h e r some p r o p e r t y is true of given objects. This entails that " m e a n i n g s " can be e x e c u t e d in only one way, and precludes the kind of q u e r y planning done in Chat-80. But such a simple- minded approach to q u e r y execution is not viable in most practical situations, as W o o d s 1977 recognises with his " s m a r t q u a n t i f i e r s " . T h e only alternative, given the procedural approach to meaning, is to repre-
sent the meaning of a word by a set of alternative procedures to be used in different circumstances. But this makes life very difficult for s o m e o n e wanting to introduce a new word or c o n c e p t into the system.
In Chat-80, the meaning of a new word is in princi- ple just a set of facts and general rules that define the predicate corresponding to that word. T h e p r o c e d u r a l aspect is on the whole t a k e n care of b y the planning algorithm, and by Prolog's flexible handling of predi- cations in which only certain arguments are instantiat- ed. H o w e v e r , with the present system, the definer of a new word must be responsible for ensuring that the predicate definition he supplies is not only correct, but is also r e a s o n a b l y efficient when e x e c u t e d by Prolog.
6. C o n c l u s i o n
We have s h o w n h o w questions within a limited subset of English can be translated into a certain sub- set of logic which, when suitably t r a n s f o r m e d , is exec- utable as efficient Prolog code. Although this map- ping b e t w e e n English and logic may seem " o b v i o u s " (since logic is, after all, usually m o t i v a t e d in terms of its c o r r e s p o n d e n c e with natural language), it is surpris- ing that a mapping like ours does not a p p e a r to have b e e n implemented, or even precisely defined, before. Parts of the mapping overlap with M o n t a g u e ' s 1974 formalisation of aspects of English, but m a n y of the basics were not c o v e r e d in his work (for instance, the t r e a t m e n t of questions, plurals, and d e t e r m i n e r prece- dence), and of course he was not c o n c e r n e d to p r o d - uce a practical implementation. A m o n g practical im- plementations, the closest work is that of W o o d s 1977 and that of C o l m e r a u e r 1982 as i m p l e m e n t e d b y Dahl 1981. Both these efforts are similar in that they map English into a n o n s t a n d a r d (and more e l a b o r a t e ) logic, w h e r e the quantifiers are m o r e directly m o d e l l e d on the determiners of natural language. These n o n s t a n - dard quantifiers are called " F O R e x p r e s s i o n s " by W o o d s and " t h r e e - b r a n c h e d q u a n t i f i e r s " b y Colmer- auer. We have kept much closer to standard predicate logic, for the very d o w n - t o - e a r t h r e a s o n that the tradi- tional formalism seems to make " q u e r y o p t i m i s a t i o n " much easier (see the c o m p a n i o n paper, W a r r e n 1981).
Our mapping f r o m English to logic, as well as the processes of q u e r y planning and answering, have all b e e n i m p l e m e n t e d entirely in Prolog. The result is a p r o t o t y p e natural language question answering system, C h a t - 8 0 , which we think p r o b a b l y has the best combi- nation of efficiency and portability of any c o m p a r a b l e system at the present time, due principally to the use of Prolog as the implementation language.
A c k n o w l e d g e m e n t s
This work was s u p p o r t e d by a British Science Re- search Council grant, and owes much to the work of Alain C o l m e r a u e r and V e r o n i c a Dahl.
David H.D. W a r r e n and Fernando C.N. Pereira An Efficient Easily Adaptable System
R e f e r e n c e s
Burton, R.R. 1976 Semantic grammar: an engineering technique for constructing natural language understanding systems. Re- port 3453. Bolt Beranek and Newman Inc. (December). Byrd, L., Pereira, F., and Warren, D.H.D. 1980 A guide to ver-
sion 3 of DEC-10 Prolog. Occasional Paper 19. Dept. of Artificial Intelligence, University of Edinburgh (July).
Colmerauer, A. 1978 Metamorphosis grammars. In Bolc., L., Ed.,
Natural Language Communication with Computers. Springer- Verlag. First appeared as an internal report, Les Grammaires de Metamorphose, in November 1975.
Colmerauer, A. 1982 An interesting subset of natural language. In Clark, K.L. and Tarnlund, S.-A., Ed., Logic Programming.
Academic Press.
Dahl, V. 1979 Quantification in a three-valued logic for natural language question-answering systems. IJCA1-79, Tokyo (August) 182-187.
Dahl, V. 1981 Translating Spanish into logic through logic. AJCL
7, 3, 149-164.
Konolige, K. 1979 A framework for a portable natural language interface to large data bases. Technical Note 197. AI Center, SRI International (October).
McCord, M.C. 1982 Using slots and modifiers in logic grammars for natural language. Artificial Intelligence 18, 3,327-367. Montague, R. 1974 The proper treatment of quantification in
ordinary English. In Thomason, R.M., Ed., Formal Philosophy.
Yale University Press.
Pereira, F.C.N. 1981 Extraposition grammars. AJCL 7, 4, 243- 256.
Pereira, F.C.N. 1982 Logic for natural language analysis. Ph.D. thesis. University of Edinburgh.
Pereira, F.C.N. and Warren, D.H.D. 1980 Definite clause gram- mars for language analysis - a survey of the formalism and a comparison with augmented transition networks. Artificial Intelligence 13, 231-278.
Pereira, L.M., Pereira, F., and Warren, D.H.D. 1978 User's guide to DECsystem-10 Prolog. Dept. of Artificial Intelligence, University of Edinburgh.
Roussel, P. 1975 Prolog: manuel de reference et d'utilisation Group d'Intelligence Artificielle, UER de Luminy, Universit6 d'Aix-Marseille II.
Stonebraker, M., Wong, E., Kreps, P. and Held, G. 1976 The design and implementation of INGRES. A C M Trans. on Data- base Systems 1, 3 (Sept.) 189-222.
Vanlehn, K.A. 1978 Determining the Scope of English Quantifi- ers. Master's thesis. Published as Report AI-TR-483. M.I.T. (June).
Warren, D.H.D. 1977 Implementing Prolog - compiling predicate logic programs. Technical Research Reports 39 and 40. Dept. of Artificial Intelligence, University of Edinburgh (May). Warren, D.H.D. 1979 Prolog on the DECsystem-10. In Michie,
D., Ed., Expert Systems in the Micro-Electronic Age. Edinburgh University Press.
Warren, D.H.D. 1981 Efficient processing of interactive relational database queries expressed in logic. Seventh International Conference on Very Large Data Bases.
Warren, D.H.D. 1982 Higher-order extensions to Prolog - are they needed? In Hayes, Michie, and Pao, Ed., Machine Intelli- gence 10. Ellis Horwood.
Warren, D.H.D., Pereira, L.M., and Pereira, F,C.N. 1977 Prolog - the language and its implementation compared with Lisp. ACM Symposium on A1 and Programming Languages (August). Woods, W.A. 1970 Transition network grammars for natural
language analysis. Comm. A C M 13 (Oct.) 591-606.
Woods, W.A. 1977 Semantics and quantification in natural lan- guage question answering. Report 3687. Bolt Beranek and Newman Inc. (November).
Woods, W.A., Kaplan, R.M., and Nash-Webber, B. 1972 The Lunar science natural language information system: final report. Report 3438. Bolt Beranek and Newman Inc. (June).
David H.D. Warren and Fernando C.N. Pereira An Efficient Easily A d a p t a b l e S y s t e m
Appendix I. Sample Queries
The Chat-80 examples below show the original English query, its logical form, the executable form after planning, and the actual answer. (The logical expressions have been "tidied", and superfluous quan- tifiers dropped, to make them easier to read.) Also
Does Afghanistan border China?
38 ms. ans(yes) < = borders(afghanistan,china). 12 ms. ans(yes) < = {borders(afghanistan,china)}.
0 ms. yes.
Which country's capital is Ouagadougou?
shown, preceding the corresponding output, are the separate times (in CPU milliseconds on a DEC KL-10) for natural language analysis, for planning, and for execution. Time spent in producing output to the user is excluded.
41 ms. ans(C) < = country(C) & capital(C,ouagadougou). 15 ms. ans(C) < = capital(C,ouagadougou) & {country(C)}. 22 ms. upper volta.
Which is the ocean that borders African countries and that borders Asisan countries? 91 ms. ans(X) < = ocean(X) & country(C) & african(C) & borders(X,C) &
country(C 1) & asian(C 1) & borders(X,C 1). 51 ms. ans(X) < = ocean(X) &
{borders(X,C) & {african(C)} & {country(C)}} & {borders(X,C1) & {asian(C1)} & {country(C1)}}. 102 ms. indian ocean.
What is the capital of each country bordering the Baltic?
81 ms. ans(C-X) < = country(C) & borders(C,baltic) & capital(C,X). 12 ms. ans(C-X) < = borders(C,baltic) & {country(C)} & capital(C,X).
29 ms. denmark-copenhagen, e a s t g e r m a n y - e a s t b e r l i n , finland-helsinki, poland-warsaw, s o v i e t u n i o n - m o s c o w , sweden-stockholm, w e s t g e r m a n y - b o n n .
What are the lattitudes of the countries north of the United Kingdom?
102 ms. ans(C-LL) < = country(C) & northof(C,united kingdom) & setof (L,latitude (C,L),LL).
26 ms. ans(C-LL) < = northof(C,united kingdom) &{country(C)} & setof(L,latitude(C,L),LL).
141 ms. canada-60 degrees, denmark-55 degrees, finland-65 degrees, iceland-65 degrees, norway-64 degrees, soviet union-57 degrees, sweden-63 degrees.
Which country is bordered by two seas?
42. ms. ans(C) < = country(C) & numberof(X,sea(X) & borders(C,X),2). 11 ms. ans(C) < = numberof(X,sea(X) & borders(C,X),2) & {country(C)}. 206 ms. egypt, iran, israel, saudi arabia, turkey.
How many countries does the Danube flow through?
48 ms. ans(N) < = numberof(C,country(C) & flows(danube,C),N). 3 ms. ans(N) < = numberof(C,flows(danube,C) & {country(C)},N). 21 ms. 6.
From what country does a river flow into the Persian Gulf?
69 ms. ans(C) < = river(R) & country(C) & flows(R,C,persian gulf). 12 ms. ans(C) < = flows(R,C,persian gulf) & {river(R)} & {country(C)}. 23 ms. iraq.
What is the total area of countries south of the Equator not in Australasia? 115 ms. ans(T) < = setof(A-C,area(C,A) & country(C) &
southof(C,equator) & \+in(C,australasia),S) & aggregate (total,S,T).
23 ms. ans(T) < = setof(A-C,southof(C,equator) & area(C,A) & {countryof(C)} & \+in(C,australasia),S) & aggregate(total,S,T).
David H.D. Warren and Fernando C.N. Pereira An Efficient Easily Adaptable System
What is the average area o f the countries in each continent?
101 ms. ans(X-Av) < = continent(X) &
setof(A-C,area(C,A) & country(C) & in(C,X),S) & aggregate(average,S,Av).
33 ms. ans(X-Av) < = continent(X) &
setof(A-C,in(C,X) & area(C,A) & {country(C)},S) & aggregate (average,S,Av).
759 ms. africa-233 ksqmiles, america-496 ksqmiles, asia-485 ksqmiles, australasia-543 ksqmiles, europe-58 ksqmiles.
How many countries are there in each continent?
50 ms. ans(X-N) < = continent(X) & numberof(C,country(C) & in(C,X),N). 19 ms. ans(X-N) < = continent(X) & numberof (C,in(C,X) & {country(C)},N). 352 ms. africa-48, america-31, asia-39, australasia-6, europe-32.
Is there some o c e a n that does not border any country?
68 ms. ans(yes) < = ocean(X) & \+exists(C,borders(X,C) & country(C)). 9 ms. ans(yes) < = {ocean(X) & \+exists(C,borders(X,C) & {country(C)})}. 14 ms. yes.
What does border the o c e a n that does not border any country?
59 ms. ans(Y) < = ocean(X) & \+exists(C,country(C) & borders(X,C)) & borders(Y,X).
20 ms. ans(Y) < = ocean(X) & \+exists(C,borders(X,C) & {country,(C)}) & borders(Y,X).
24 ms. antarctica, atlantic, i n d i a n m o c e a n , pacific.
Which are the continents no country in which contains more than two cities whose population e x c e e d s I million?
160 ms. ans(X) < = continent(X) & \ +exists(C,exists(N,
country(C) & in(C,X) & numberof(Ci,exists(P,
city(Ci) & population(Ci,P) &
exceeds(P,1000000) & in(Ci,C)),N) &
N > 2)).
58 ms. ans(X) < = continent(X) & \ +exists(C,exists(N,
in(C,X) & {country(C)} & { numberof(Ci,exists(P,
in(Ci,C) & {city(Ci)} &
{population(Ci,P) & {exceeds(P,1000000)}}),N) & iN > 2}})).
754 ms. africa, antarctica, australasia.
Which country bordering the Mediterranean borders a country that is bordered by a country w h o s e population e x c e e d s the population o f India?
144 ms. arts(C) < = country(C) & borders(C,mediterranean) & country(C1) &
57 ms.
204 ms.
country(C2) & population(C2,X) & population(indea,Y) & exceeds(X,Y) & borders(C2,C 1) & borders(C,C 1).
ans(C) < = population(india,Y) &
borders(C,mediterranean) & {country(C)} & {borders(C,C1) & {country(C1)} &
{borders(C2,C1) & {country(C2)} & {population(C2,X) & {exceeds(X,Y)}}}}. turkey.
David H.D. Warren and Fernando C.N. Pereira An Efficient Easily Adaptable System
A p p e n d i x II. S a m p l e W o r d D e f i n i t i o n
To illustrate how a new word, and the concept
associated with it, are a d d e d to the system, we show a slightly simplified version of the actual Prolog clauses defining the v e r b " t o drain i n t o . " T h e s e clauses r e p r e - sent e l e m e n t a r y facts, giving the different f o r m s of the
v e r b , its m e a n i n g in t e r m s of the p r e d i c a t e ' d r a i n s ( R , X ) ' (including the t y p e s of the a r g u m e n t s R and X ) , data a b o u t the size of the ' d r a i n s ' relation a n d of its a r g u m e n t domains, a n d finally the definition of the p r e d i c a t e ' d r a i n s ' itself. v e r b r o o t ( d r a i n ) regular p r e s e n t ( d r a i n ) . r e g u l a r n p a s t (drained,drain). v e r b f o r m ( d r a i n s , d r a i n , p r e s e n t + finite,3 +singular). v e r b m f o r m ( d r a i n i n g , d r a i n , p r e s e n t + participle). intransitive(drain, d r a i n s ( R , X ) , river,R, [ s l o t ( p r e p o s i t i o n ( i n t o ) , r e g i o n , X ) ] ) . predicate statistics (drains,41,41,12).
d r a i n s ( a m a z o n , a t l a n t i c ) . d r a i n s ( a m u d a r y a , a r a l sea).
etc.
A p p e n d i x III. C o m p a r i s o n w i t h a Formal Q u e r y Language
It is interesting to c o m p a r e , f r o m a u s e r ' s point of Quel, the q u e r y l a n g u a g e of the r e l a t i o n a l d a t a b a s e view, the C h a t - 8 0 subset of English with c u r r e n t rela- s y s t e m I n g r e s ( S t o n e b r a k e r , W o n g , K r e p s , a n d H e l d tional d a t a b a s e query languages. T h e e x a m p l e s b e l o w 1976). Quel is a r g u a b l y one of the m o s t concise a n d show some C h a t - 8 0 queries with their equivalents in user-friendly of current d a t a b a s e q u e r y languages.
Which countries bordering the Atlantic border countries bordering the Pacific?
range of C I , C2 is countries range of B, B I , B2 is b o r d e r s retrieve (C l . n a m e ) where C 1. n a m e = B 1.side 1 and B 1.side2 = " A t l a n t i c " and C l . n a m e = B . s i d e l and B.side2 = C 2 . n a m e and C 2 . n a m e = B 2 . s i d e l and B2.side2 = " P a c i f i c "
H e w many countries are there in each continent?
range of C is countries range of C o n t is continents range of I is inclusions
retrieve ( C o n t . n a m e , c o u n t ( C . n a m e where C . n a m e = I.inside and I.outside = C o n t . n a m e ) )
Which are the continents no country in which contains more than two cities whose population e x c e e d s 1 million?
range of C is countries range of C o n t is continents range of City is cities range of I1, 12 is inclusions retrieve ( C o n t . n a m e ) where 0 = c o u n t ( C . n a m e where C . n a m e = I I . i n s i d e and I I . o u t s i d e = C o n t . n a m e and 2 < c o u n t ( C i t y . n a m e where C i t y . n a m e = I2.inside and I2.outside = C . n a m e and C i t y . p o p u l a t i o n > 1 0 0 0 0 0 0 ) )