Extraposition Grammars
F e r n a n d o P e r e i r a D e p a r t m e n t o f A r c h i t e c t u r e
U n i v e r s i t y o f E d i n b u r g h E d i n b u r g h EH1 1 J Z S C O T L A N D
Extraposition grammars are an extension of definite clause grammars, and are similarly defined in terms of logic clauses. The extended formalism makes it easy to describe left extraposition of constituents, an important feature of natural language syntax.
1. Introduction
This paper presents a grammar formalism for natu- ral language analysis, called extraposition grammars ( X G s ) , based on the subset of predicate calculus k n o w n as definite, or Horn, clauses. It is argued that certain i m p o r t a n t linguistic p h e n o m e n a , collectively k n o w n in t r a n s f o r m a t i o n a l g r a m m a r as left extra- position, can be described better in X G s than in earlier
grammar formalisms based on definite clauses.
The X G formalism is an extension of the definite
clause grammar ( D C G ) [6] formalism, which is itself a
restriction of C o l m e r a u e r ' s formalism of metamorphosis
grammars (MGs) [2]. Thus X G s and M G s may be
seen as two alternative extensions of the same basic formalism, D C G s .
The argument for X G s will start with a comparison with D C G s . I should point out, however, that the m o t i v a t i o n for the d e v e l o p m e n t of X G s came f r o m studying large M G s for natural language [4,7].
The relationship b e t w e e n M G s and D C G s is analo- gous to that b e t w e e n t y p e - 0 g r a m m a r s and c o n t e x t - free grammars. So, some of the linguistic p h e n o m e n a which are seen as rewriting one sequence of constitu- ents into another might be described better in a M G than in a D C G . H o w e v e r , it will be shown that re- writings such as the one involved in left extraposition cannot easily be described in either of the two formal- isms.
Left extraposition has been used by grammarians to describe the form of interrogative sentences and rela- tive clauses, at least in languages such as English, French, Spanish and Portuguese. The importance of these constructions, even in simplified subsets of natu- ral language, such as those used in database interfaces, suggests that a grammar formalism should be able to
express them in a clear and concise manner. This is the purpose of XGs.
2. Grammars in Logic
This section summarises the c o n c e p t s of definite
clause grammars ( D C G s ) , and of the underlying sys-
tem of logic, definite clauses, needed for the rest of the paper. A fuller discussion can be f o u n d elsewhere [6].
A definite clause has either the form
P:-QI,"',Qn"
to be read as " P is true if Q 1 . . . Qn are true", or the form
P .
to be read as " P is true". P is the head of the clause, Q1 . . . Qn are goals, forming the body of the clause. The symbols P, Q 1 . . . Qn stand for literals. A literal has a predicate symbol, and possibly some arguments (in parentheses, separated by commas), e.g.
father(X,Y) false number(O)
A literal is to be i n t e r p r e t e d as d e n o t i n g a relation b e t w e e n its arguments; e.g. " f a t h e r ( X , Y ) " denotes the relation ' f a t h e r ' between X and Y.
A r g u m e n t s are terms, standing for partially speci- fied objects. Terms m a y be
• variables, denoting unspecified objects
(variable names are capitalised): X C a s e Agreement
• atomic symbols, denoting specific objects:
plural [ ] 3
• compound terms, denoting complex objects:
s(NP,VP) succ(succ(O))
A c o m p o u n d term has a functor and some arguments, which are terms. C o m p o u n d terms are best seen as
Copyright 1981 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.
0 3 6 2 - 6 1 3 X / 8 1 / 0 4 0 2 4 3 - 1 4 5 0 1 . 0 0
trees, e.g.
/ NP
S SUCC
\
I
VP succ
I
0A particular type of term, the list, has a simplified notation. The b i n a r y f u n c t o r ' ' makes up n o n - e m p t y lists, and the atom '[ ]' denotes the e m p t y list. In the special list notation,
[ a , b ] [X I Y]
represent respectively the terms . ( a , . ( b , [ 3) .(X,Y)
Putting these concepts together, the clause grandfather(X,Z) :- f a t h e r ( X , Y ) , parent(Y,Z).
m a y be read as " X is grandfather of Z if X is father of Y and Y is a parent of Z " ; the clause
f a t h e r ( j o h n ,mary).
m a y be read as " J o h n is father of M a r y " (note the use of lower case for the constants in the clause).
A set of definite clauses forms a program. A pro- gram defines the relations d e n o t e d by the predicates appearing on the head of clauses. W h e n using a defi- nite clause interpreter, such as P R O L O G [9], a goal statement
?-19 .
specifies that the relation instances that match P are required.
Now, any context-free rule, such as sentence --> noun_phrase, verb_phrase.
(I use ' , ' for concatenation, and '.' to terminate a rule) m a y be translated into a definite clause
s e n t e n c e ( 5 0 , S ) : - n 0 u n _ p h r a s e ( S 0 , S 1 ) , v e r b _ p h r a s e ( S1 ,S ).
which says: " t h e r e is a s e n t e n c e b e t w e e n points SO and S in a string if there is a n o u n phrase between points SO and S1, and a verb phrase b e t w e e n points S1 and S". A c o n t e x t - f r e e rule like
d e t e r m i n e r - - > [ t h e ] .
(where the square brackets mark a terminal) can be translated into
determiner(SO,S) :- connects(SO,the,S).
which m a y be read as " t h e r e is a determiner b e t w e e n points SO and S in a string if SO is joined to S by the word ' t h e ' " . The predicate ' c o n n e c t s ' is used to relate terms denoting points in a string to the words which join those points. Depending on the application, differ- ent definitions of ' c o n n e c t s ' might be used. In particu- lar, if a point in a string is represented by the list of words after that point, ' c o n n e c t s ' has the very simple definition
connects([Word I 53,Word,S).
which m a y be read as " a string point represented by a list of words with first element W o r d and rest S is c o n n e c t e d by the word W o r d to the string point repre- sented by list S."
D C G s are the natural extension of c o n t e x t - f r e e g r a m m a r s ( C F G s ) o b t a i n e d t h r o u g h the translation into definite clauses outlined above. A D C G n o n - terminal m a y have arguments, of the same f o r m as those of a predicate, and a terminal m a y be any term. F o r instance, the rule
sentence(s(NP,VP)) --> noun_phrase(NP,N), verb_phrase(VP,N).
states: " A sentence with structure s
/ \ NP VP
is made of a noun phrase with structure NP and num- ber N (which can be either 'singular' or 'plural'), fol- lowed by a verb phrase with structure VP agreeing with the number N " . A D C G rule is just " s y n t a c t i c sugar" for a definite clause. The clause for the exam- ple above is
sentence(s(NP,VP),SO,S) :-
noun phrase(NP,N,SO,S1), verb_phrase(VP,N,Sl ,S).
In general, a D C G non-terminal with n arguments is translated into a predicate of n + 2 arguments, the last two of which are the string points, as in the translation of c o n t e x t - f r e e rules into definite clauses.
The main idea of D C G s is then that g r a m m a r sym- bols can be general logic terms rather than just atomic symbols. This makes D C G s a general-purpose gram- mar formalism, capable of describing any t y p e - 0 lan- guage. The first g r a m m a r formalism with logic terms as g r a m m a r symbols was C o l m e r a u e r ' s m e t a m o r p h o s i s g r a m m a r s [2]. W h e r e a D C G is a C F G with logic terms for grammar symbols, a M G is a s o m e w h a t re- stricted t y p e - 0 g r a m m a r with logic terms for g r a m m a r symbols. H o w e v e r , the very simple translation of D C G s into definite clauses presented above does not carry over directly to MGs.
3. Left Extraposition
R o u g h l y speaking, left extraposition occurs in a natural language s e n t e n c e w h e n a s u b c o n s t i t u e n t of some constituent is missing, and some other constitu- ent, to the left of the incomplete one, represents the missing constituent in some way. It is useful to think that an e m p t y c o n s t i t u e n t , the trace, occupies the " h o l e " left by the missing c o n s t i t u e n t , a n d that the c o n s t i t u e n t to the left, which represents the missing part, is a marker, indicating that a constituent to its right contains a trace [1]. One can then say that the constituent in whose place the trace stands has been extraposed to the left, and, in its new position, is rep-
sentence --> noun_phrase, verb phrase.
noun_phrase --> proper_noun.
noun_phrase --> determiner, noun, r e l a t i v e . noun_phrase --> determiner, noun, prep_phrase. noun_phrase --> trace.
trace --> [ ].
verb_phrase --> verb, noun_phrase. verb_phrase --> verb.
r e l a t i v e --> [ ].
r e l a t i v e --> rel_pronoun, sentence.
[image:3.612.318.546.60.303.2]prep_phrase --> p r e p o s i t i o n , noun_phrase.
Figure 4.1. CFG for relative clauses.
(1)
resented by the marker. F o r instance, relative clauses are formed by a marker, which in the simpler cases is just a relative pronoun, followed by a sentence where some noun phrase has been replaced by a trace. This is represented in the following a n n o t a t e d surface struc- ture:
The man t h a t / [sdohn met t i] is a grammarian.
In this example, t stands for the trace, ' t h a t ' is the surface form of the marker, and the c o n n e c t i o n be- tween the two is indicated by the c o m m o n index i.
The concept of left extraposition plays an essential role, directly or indirectly, in m a n y formal descriptions of relative and interrogative clauses. Related to this c o n c e p t , there are several " g l o b a l c o n s t r a i n t s " , the "island c o n s t r a i n t s " , that have been i n t r o d u c e d to restrict the situations in which left extraposition can be applied. F o r instance, the Ross c o m p l e x - N P con- straint [8], implies that any relative p r o n o u n occurring outside a given n o u n phrase c a n n o t be b o u n d to a trace occurring inside a relative clause which is a sub- constituent of the noun phrase. This means that it is not possible to have a configuration like
Xl " " [ n p "'" [ r e l X 2 [ s "'" t2 "'" tl "'" 3] "'" ]
Note that here I use the c o n c e p t of left extraposi- tion in a loose sense, without relating it to transforma- tions as in transformational grammar. In XGs, and also in other formalisms for describing languages (for in- stance the context-free rule schemas of G a z d a r [5]), the notion of transformation is not used, but a c o n c e p - tual operation of some kind is required for instance to relate a relative p r o n o u n to a " h o l e " in the structural r e p r e s e n t a t i o n of the c o n s t i t u e n t following the pro- noun.
4. L i m i t a t i o n s of O t h e r Formalisms
To describe a fragment of language where left ex- traposition occurs, one might start with a C F G which gives a r o u g h a p p r o x i m a t i o n of the fragment. The grammar m a y then be refined by adding arguments to
f u l l sentence --> s e n t e n c e ( n i l ) .
sentence(HoleO) -->
noun_phrase(HoleO,Holel), verb_phrase(Holel).
noun_phrase(Hole,Hole) --> proper_noun. noun_phrase(Hole,Hole) -->
determiner, noun, r e l a t i v e . noun_phrase(HoleO,Hole) -->
determiner, noun, prep_phrase(HoleO,Hole). noun_phrase(trace,nil) --> trace.
trace --> [ ] .
verb_phrase(Hole) -->
verb, noun_phrase(Hole,nil). verb_phrase(nil) --> verb.
r e l a t i v e --> [ ] . r e l a t i v e -->
rel_pronoun, sentence(trace).
prep_phrase(HoleO,Hole) -->
p r e p o s i t i o n , noun_phrase(HoleO,Hole).
Figure 4.2. DCG for relative clauses.
(2)
non-terminals, to carry extraposed constituents across phrases. This m e t h o d is analogous to the introduction of " d e r i v e d " rules by G a z d a r [5]. Take for example the C F G in Figure 4.1. In this g r a m m a r it is possible to use rule (1) to expand a n o u n phrase into a trace, even outside a relative clause. To prevent this, I will add arguments to all non-terminals from ~vhich a n o u n
phrase might be extraposed. The modified g r a m m a r , n o w a D C G , is given in Figure 4.2. A variable ' H o l e . . . ' will have the value ' t r a c e ' if an e x t r a p o s e d n o u n phrase occurs somewhere to the right, 'nil' other- wise. The parse tree of Figure 4.3 shows the variable values when the g r a m m a r of Figure 4.2 is used to ana- lyse the n o u n phrase " t h e m a n that J o h n met".
Intuitively, we either can see n o u n phrases moving to the left, leaving traces behind, or traces appearing from markers and moving to the right. In a phrase " n o u n p h r a s e ( H o l e l , H o l e 2 ) " , H o l e l will have the value ' t r a c e ' when a trace occurs s o m e w h e r e to the right of the left end of the phrase. In that case, Hole2 will be 'nil' if the n o u n phrase contains the trace, ' t r a c e ' if the trace appears to the right of the right end of this n o u n phrase. Thus, rule (2) in Figure 4.2 speci- fies that a noun phrase expands into a trace if a trace appears from the left, and as this trace is now placed, it will not be f o u n d further to the right.
The non-terminal 'relative' has no arguments, be- cause the c o m p l e x - N P constraint prevents n o u n phras- es from moving out of a relative clause. H o w e v e r , that constraint does not apply to prepositional phrases, so ' p r e p p h r a s e ' has arguments. The n o n - t e r m i n a l ' s e n t e n c e ' (and c o n s e q u e n t l y ' v e r b p h r a s e ' ) has a single argument, because in a relative clause the trace
n o u n _ p h r a s e ( n t l , n t l )
d e t e r m i n e r
noun
r e l a t i v e
re
l_pronoun
sentence (trace)
noun_ p hrase (trace ,trace)
I
p r o p e r _ n o u n
the
m a n
that
John
v e r b _ p h r a s e ( t r a c e )
v e r b n o u n _ p h r a s e ( t r a c e , n t l )
I
t r a c e
I
[image:4.612.44.576.58.310.2]met
[]
Figure 4.3. DCG parse tree.
must occur in the sentence immediately to the right of the relative pronoun.
It is obvious that in a more extensive g r a m m a r , m a n y n o n - t e r m i n a l s would need extraposition argu- ments, and the increased complication would make the grammar larger and less readable.
C o l m e r a u e r ' s M G formalism allows an alternative way to express left extraposition. It involves the use of rules whose l e f t - h a n d side is a n o n - t e r m i n a l fol- lowed by a string of " d u m m y " terminal symbols which do not occur in the input vocabulary. A n example of such a rule is:
r e l _ m a r k e r , [ t ] - - > r e l _ p r o n o u n .
Its meaning is that 'rel p r o n o u n ' can be analysed as a 'rel m a r k e r ' provided that the terminal ' t ' is added to the front of the input remaining after the rule applica- tion. Subsequent rule applications will have to cope explicitly with such d u m m y terminals. This m e t h o d has been used in several published grammars [2, 4, 7], but in a large grammar it has the same (if not worse) problems of size and clarity as the previous method. It also suffers from a theoretical problem: in general, the language defined by such a grammar will contain extra sentences involving the d u m m y terminals. F o r parsing, however, no problem arises, because the input sentences are not supposed to contain d u m m y termi- nals. These inadequacies of M G s were the main moti- vation for the development of XGs.
5. I n f o r m a l D e s c r i p t i o n o f X G s
To describe left extraposition, we need to relate n o n - c o n t i g u o u s parts of a sentence. But neither D C G s nor M G s have means of representing such a relation- ship by specific g r a m m a r rules. R a t h e r ; the relation- ship can only be described implicitly, by adding extra information to m a n y unrelated rules in the grammar. That is, one c a n n o t look at a g r a m m a r and find a set of rules specific to the constructions which involve left extraposition.
With extraposition grammars, I attempt to provide a formalism in which such rules can be written.
In this informal introduction to the X G formalism, I will avoid the extra c o m p l i c a t i o n s of n o n - t e r m i n a l arguments. So, in the discussion that follows, we m a y look at X G s as an extension of C F G s .
Sometimes it is easier to look at g r a m m a r rules in the left-to-right, or synthesis, direction. I will say then that a rule is being used to
expand
orrewrite
a string. In other cases, it is easier to look at a rule in the right- to-left, or analysis, direction. I will say then that the rule is being used toanalyse
a string.L e t us first look at the following X G fragment: s e n t e n c e - - > n o u n _ p h r a s e , v e r b _ p h r a s e .
noun p h r a s e - - > d e t e r m i n e r , n o u n , r e l a t i v e . n o u n _ p h r a s e - - > t r a c e .
r e l a t i v e - - > [ ] .
r e l a t i v e - - > r e l m a r k e r , s e n t e n c e .
r e l _ m a r k e r . . . t r a c e - - > r e l _ p r o n o u n .
t h e mouse
the
rel_marker the cat chased trace
m o u s e r e l _ p r o n o u n t h e c a t c h a s e d
squeaks
[image:5.612.113.457.67.155.2]squeaks
Figure 5.1. Applying an XG rule.
A l l r u l e s b u t t h e l a s t a r e c o n t e x t - f r e e . T h e l a s t r u l e ~ x p r e s s e s t h e e x t r a p o s i t i o n in s i m p l e r e l a t i v e c l a u s e s . It s t a t e s t h a t a r e l a t i v e p r o n o u n is to b e a n a l y s e d as a m a r k e r , f o l l o w e d b y s o m e u n k n o w n c o n s t i t u e n t s ( d e n o t e d b y ' . . . ' ) , f o l l o w e d b y a t r a c e . T h i s is s h o w n in F i g u r e 5.1. A s in t h e D C G e x a m p l e o f t h e p r e v i o u s s e c t i o n , t h e e x t r a p o s e d n o u n p h r a s e is e x p a n d e d i n t o a t r a c e . H o w e v e r , i n s t e a d o f t h e t r a c e b e i n g r e w r i t t e n i n t o t h e e m p t y s t r i n g , t h e t r a c e is u s e d as p a r t o f t h e a n a l y s i s o f ' r e l m a r k e r ' .
T h e d i f f e r e n c e b e t w e e n X G r u l e s a n d D C G r u l e s is t h e n t h a t t h e l e f t - h a n d s i d e o f a n X G r u l e m a y c o n t a i n s e v e r a l s y m b o l s . W h e r e a D C G r u l e is s e e n as e x - p r e s s i n g t h e e x p a n s i o n o f a s i n g l e n o n - t e r m i n a l i n t o a s t r i n g , a n X G r u l e is s e e n as e x p a n d i n g together s e v e r a l n o n - c o n t i g u o u s s y m b o l s i n t o a string. M o r e p r e c i s e l y , a n X G rule h a s t h e g e n e r a l f o r m
s 1 . . . s 2 etc. Sk_ 1 . . . s k --> r. (3) H e r e e a c h s e g m e n t s i ( s e p a r a t e d f r o m o t h e r s e g m e n t s b y ' . . . ' ) is a s e q u e n c e o f t e r m i n a l s a n d n o n - t e r m i n a l s ( w r i t t e n in D C G n o t a t i o n , w i t h ' , ' f o r c o n c a t e n a t i o n ) . T h e first s y m b o l in s 1, t h e leading s y m b o l , is r e s t r i c t e d t o b e a n o n - t e r m i n a l . T h e r i g h t - h a n d side r is as in a D C G rule.
L e a v i n g a s i d e t h e c o n s t r a i n t s d i s c u s s e d in t h e n e x t s e c t i o n , t h e m e a n i n g o f a r u l e like ( 3 ) is t h a t a n y se- q u e n c e o f s y m b o l s o f t h e f o r m
SlXqS2X 2 etc. s k _ q X k _ l S k
w i t h a r b i t r a r y xi's, c a n b e r e w r i t t e n i n t o r x q x 2 . . . x k _ 1. T h i n k i n g p r o c e d u r a l l y , o n e c a n s a y t h a t a n o n - t e r m i n a l m a y b e e x p a n d e d b y m a t c h i n g it t o t h e l e a d - i n g s y m b o l o n t h e l e f t - h a n d s i d e o f a rule, a n d t h e r e s t o f t h e l e f t - h a n d s i d e is " p u t a s i d e " t o w a i t f o r t h e d e r i v a t i o n o f s y m b o l s w h i c h m a t c h e a c h o f its s y m b o l s in s e q u e n c e . T h i s s e q u e n c e o f s y m b o l s c a n b e i n t e r - r u p t e d b y a r b i t r a r y s t r i n g s , p a i r e d t o t h e o c c u r r e n c e s o f ' . . . ' o n t h e l e f t - h a n d s i d e o f t h e rule.
6. XG D e r i v a t i o n s
W h e n s e v e r a l X G r u l e s a r e i n v o l v e d , t h e d e r i v a t i o n o f a s u r f a c e s t r i n g b e c o m e s m o r e c o m p l i c a t e d t h a n in t h e s i n g l e r u l e e x a m p l e o f t h e p r e v i o u s s e c t i o n , b e - c a u s e r u l e a p p l i c a t i o n s i n t e r a c t in t h e w a y n o w t o b e
d e s c r i b e d .
T o r e p r e s e n t t h e i n t e r m e d i a t e s t a g e s in a n X G d e - r i v a t i o n , I will u s e b r a c k e t e d strings, m a d e u p o f
• t e r m i n a l s y m b o l s • n o n - t e r m i n a l s y m b o l s • t h e open b r a c k e t < • t h e close b r a c k e t >
A b r a c k e t e d s t r i n g is b a l a n c e d if t h e b r a c k e t s in it b a l a n c e in t h e u s u a l w a y .
N o w , a n X G r u l e
u 1 . . . u 2. .. etc . . . . u n --> v. c a n b e a p p l i e d to b r a c k e t e d s t r i n g s if
s = x O U l X l U 2 etc. Xn_qUnX n
a n d e a c h o f t h e gaps x 1 . . . X n - 1 is b a l a n c e d . T h e s u b s t r i n g o f s b e t w e e n x 0 a n d x n is t h e span o f t h e r u l e a p p l i c a t i o n . T h e a p p l i c a t i o n r e w r i t e s s i n t o n e w s t r i n g t, r e p l a c i n g Ul b y v f o l l o w e d b y n-1 o p e n b r a c k - ets, a n d r e p l a c i n g e a c h o f u 2 . . . u n b y a c l o s e b r a c k - et; in s h o r t , s is r e p l a c e d b y
x 0 v < < ... < x 1 > x 2 > ... Xn_ l > x n
T h e r e l a t i o n b e t w e e n t h e o r i g i n a l s t r i n g s a n d t h e d e r i v e d s t r i n g t is a b b r e v i a t e d as s = > t. I n t h e n e w s t r i n g t, t h e s u b s t r i n g b e t w e e n x 0 a n d x n is t h e result o f t h e a p p l i c a t i o n . I n p a r t i c u l a r , t h e a p p l i c a t i o n o f a r u l e w i t h a s i n g l e s e g m e n t in its l e f t - h a n d s i d e is n o d i f f e r e n t f r o m w h a t it w o u l d b e in a t y p e - 0 g r a m m a r .
T a k i n g a g a i n t h e r u l e
r e l _ m a r k e r . . . t r a c e - - > r e l _ p r o n o u n .
its a p p l i c a t i o n t o
r e l marker John likes t r a c e
p r o d u c e s
rel_pronoun < John likes >
A f t e r t h i s rule a p p l i c a t i o n , it is n o t p o s s i b l e t o a p p l y a n y r u l e w i t h a s e g m e n t m a t c h i n g i n s i d e a b r a c k e t e d p o r t i o n a n d a n o t h e r s e g m e n t m a t c h i n g o u t s i d e it. T h e use o f t h e a b o v e r u l e h a s d i v i d e d t h e s t r i n g i n t o t w o i s o l a t e d p o r t i o n s , e a c h o f w h i c h m u s t b e i n d e p e n d e n t l y e x p a n d e d .
G i v e n a n X G w i t h i n i t i a l s y m b o l s, a s e n t e n c e t is in t h e l a n g u a g e d e f i n e d b y t h e X G if t h e r e is a s e -
a S
bs
a S
a s
[]
bs
~ x b "I~
J
x c
bs
[]
CS
CS
i X C l a
Conventions:
o =
rule
a p p l i c a t i o n
( n o d e )
x = n o n - t e r m i n a l
x = t e r m i n a l
[ ] = e m p t g s t r i n g
c s
[]
[image:6.612.99.497.58.447.2]a a b b c c
Figure 7.1. Derivation graph for "aabbcc".
q u e n c e of rule applications that t r a n s f o r m s s into a string from which t can be o b t a i n e d by deleting all brackets.
I shall refer to the restrictions on X G rule applica- tion which I have just described as the bracketing
constraint. The effect of the bracketing constraint is
independent of the order of application of rules, be- cause if two rules are used in a derivation, the brack- ets introduced by each of them must be compatible in the w a y described above. As brackets are added and never deleted, it is clear that the order of application is irrelevant. F o r similar reasons, any two applications in a derivation where the rules involved have more than one segment in their left-hand sides, one and only one of the two following situations arises:
• the span of neither application intersects the result of the other;
• the result of one of the applications is contained entirely in a gap of the other application - the ap- plications are nested.
If one follows to the letter the definitions in this section, then checking, in a parsing procedure, whether an X G rule m a y be applied, would require a scan of the whole intermediate string. H o w e v e r , we will see in Section 10 that this check m a y be done " o n the f l y " as brackets are introduced, with a cost i n d e p e n d e n t of the length of the c u r r e n t i n t e r m e d i a t e string in the derivation.
7. D e r i v a t i o n G r a p h s
In the same w a y as parse trees are used to visualise c o n t e x t - f r e e derivations, I use derivation graphs to represent X G derivations.
In a derivation graph, as in a parse tree, each node corresponds to a rule application or to a terminal sym- bol in the derived sentence, and the edges leaving a node c o r r e s p o n d to the symbols in the right-hand side of that n o d e ' s rule. In a derivation graph, however, a node can have more than one incoming edge - in fact, one such edge for each of the symbols on the left-
hand side of the rule c o r r e s p o n d i n g to that node. Of these edges, only the one c o r r e s p o n d i n g to the leading s y m b o l is used to define the left-to-right order of the symbols in the sentence whose derivation is r e p r e s e n t - ed by the graph. If one deletes f r o m a derivation graph all e x c e p t the first of the incoming edges to e v e r y node, the result is a tree analogous to a parse tree.
F o r example, Figure 7.1 shows the derivation graph for the string " a a b b c c " according to the X G :
S - - > a s , b s , c s .
as - - > [ ] .
as . . . x b - - > [ a ] , a s .
bs - - > [ ] .
bs . . . x c - - > x b , [ b ] , b s .
cs - - > [ ] .
CS - - > XC, [ C ] , CS.
This X G defines the language f o r m e d by the set of all strings
anbncn for n_> 0.
The example shows, incidentally, that X G s , e v e n with- out arguments, are strictly m o r e p o w e r f u l than C F G s , since the language described is not c o n t e x t - f r e e .
The t o p o l o g y of derivation graphs reflects clearly the b r a c k e t i n g constraint. A s s u m e the following t w o c o n v e n t i o n s f o r the drawing of a d e r i v a t i o n graph, which are followed in all the graphs shown here:
• the edges entering a n o d e are o r d e r e d clockwise following the sequence of the c o r r e s p o n d i n g s y m - bols in the l e f t - h a n d side of the rule for that node; • the edges issuing f r o m a node are o r d e r e d c o u n t e r -
clockwise following the s e q u e n c e of the c o r r e - sponding symbols in the right-hand side of the rule for the node.
T h e n the derivation graph obeys the bracketing const- raint if and only if it can be drawn, following the con- ventions, without any edges crossing. 1 T h e example of Figure 7.2 shows this clearly. In this figure, the closed p a t h f o r m e d by edges 1, 2, 3, and 4 has the same ef- f e c t as a m a t c h i n g pair of b r a c k e t s in a b r a c k e t e d string.
It is also worth noting that nested rule applications a p p e a r in a derivation graph as a configuration like the one depicted in Figure 7.3.
8. X G s a n d L e f t E x t r a p o s i t i o n
We saw in Figure 4.2 a D C G for (some) relative clauses. The X G of Figure 8.1 describes essentially the same language f r a g m e n t , showing h o w easy it is to describe left extraposition in an X G . In that g r a m m a r , the sentence
1 In some of the examples of this article, edges cross to make the graphs more readable, but such crossings could be trivially avoided.
5 - - > a , b , c ,
a . . . c - - > [ x ] .
b ... d - - > [ g ] .
d.
s
a b c d
x
y
S -~>
S -T_>
[image:7.612.323.541.54.440.2] [image:7.612.311.544.426.638.2]a b c d = > x < b > d = > ? (blocks) a b c d = > a g < c > = > ?
Figure 7.2. Relating derivations to derivation graphs.
Figure 7.3. Nested rule applications.
The mouse t h a t the cat chased squeaks.
has the derivation graph s h o w n in Figure 8.2. T h e left extraposition implicit in the structure of the s e n t e n c e is r e p r e s e n t e d in the derivation graph b y the applica-
S
d e t
n o u nr e l
rE
r s
I
e-.---
lp
np
vp
d e t n o u n r e l v e r b
+
i °
[]
t
T
v e r bd e t
np
r
r e [
r e l p
5
t
vp
=
determiner
=
noun_phrase
= r e I _ m a r k e r
= r e l a t i v e = r e l _ p r o n o u n
= s e n t e n c e
= trace
=
verb_phrase
t h e m o u s e t h a t t h e c a t
c h a s e d
s q u e a k s
Figure 8.2. Example of derivation graph for the XG in Figure 8.1.
sentence - - > noun_phrase, v e r b _ p h r a s e .
noun_phrase - - > proper_noun.
noun_phrase - - > d e t e r m i n e r , noun, r e l a t i v e . noun_phrase - - > d e t e r m i n e r , noun, prep_phrase. noun_phrase - - > t r a c e .
ve r b_phras e - - > v e r b , noun_phrase. ve r b_phras e - - > v e r b .
r e l a t i v e - - > [ ] .
r e l a t i v e - - > r e ] m a r k e r , sentence.
r e l _ m a r k e r . . . t r a c e - - > r e l _ p r o n o u n .
prep_phrase - - > p r e p o s i t i o n , noun_phrase.
Figure 8.1. XG for relative clauses.
(4)
tion of the rule for ' r e l _ _ m a r k e r ' , at the node m a r k e d (*) in the figure. O n e can say that the left extraposi- tion has b e e n " r e v e r s e d " in the derivation b y the use of this rule, which m a y be l o o k e d at as
repositioning
' t r a c e ' to the right, thus " r e v e r s i n g " the e x t r a p o s i t i o n of the original sentence.
In the rest of this p a p e r , I o f t e n r e f e r to a constitu- ent being
repositioned into
a b r a c k e t e d string (or into a f r a g m e n t of d e r i v a t i o n g r a p h ) , to m e a n t h a t a rule having that c o n s t i t u e n t as a n o n - l e a d i n g s y m b o l in the l e f t - h a n d side has b e e n applied, a n d the s y m b o l m a t c h e s some s y m b o l in the string (or c o r r e s p o n d s to s o m e edge in the f r a g m e n t ) . F o r e x a m p l e , in Figure 8.2 the trace ' t ' is r e p o s i t i o n e d into the s u b g r a p h with r o o t 's'.9. Using the Bracketing Constraint
In the e x a m p l e of Figure 8.2, t h e r e is o n l y o n e application of a n o n - D C G rule, at the place m a r k e d (*). H o w e v e r , we h a v e seen that w h e n a derivation contains several applications of such rules, the applica- tions must o b e y the b r a c k e t i n g constraint. T h e use of the constraint in a g r a m m a r is b e t t e r explained with an example. F r o m the sentences
The mouse squeaks.
The c a t l i k e s f i s h . The c a t chased the mouse.
[image:8.612.88.528.65.435.2]S
d e t noun t e l
the mouse
r s
d e t noun r e l
r s
r e l p
I
t h a t t h e+
t
relp
- - I ~ l
~
e a t t h a t c h a s e d
verb
np
t
likes
verb
npd e t
noun
I
[1
Fish
vp
verb
tel
[]
squeaks
Figure 9.1. V i o l a t i o n of the c o m p l e x - N P c o n s t r a i n t .
the g r a m m a r of Figure 8.1 can derive the following string, which violates the c o m p l e x - N P constraint:
* The mouse t h a t t h e c a t t h a t chased l i k e s f i s h s q u e a k s .
T h e d e r i v a t i o n of this u n g r a m m a t i c a l string can be b e t t e r u n d e r s t o o d if we c o m p a r e it with a s e n t e n c e outside the fragment:
The mouse, t h a t t h e c a t which chased i t l i k e s f i s h ,
s q u e a k s .
where the p r o n o u n 'it' takes the place of the incorrect trace.
The derivation graph for that un-English string is shown in Figure 9.1. In the graph, (*) and (**) m a r k two nested applications of the rule for 'rel m a r k e r ' . T h e string is un-English b e c a u s e the higher ' r e l a t i v e ' ( m a r k e d ( + ) in the g r a p h ) binds a trace occurring inside a s e n t e n c e which is p a r t of the s u b o r d i n a t e d 'noun___.phrase' ( + + ) .
N o w , using the b r a c k e t i n g constraint one can n e a t - ly express the c o m p l e x - N P constraint. It is only neces-
sary to change the second rule for ' r e l a t i v e ' in Figure 8.1 to
r e l a t i v e - - > open, r e l _ m a r k e r , s e n t e n c e , c l o s e . (5)
and add the rule
open . . . c l o s e - - > [ ] . ( 6 )
With this modified g r a m m a r , it is no longer possible to violate the c o m p l e x - N P constraint, b e c a u s e no constit- u e n t can be r e p o s i t i o n e d f r o m outside into the gap c r e a t e d b y the application of rule (6) to the result of applying the rule for relatives (5).
T h e n o n - t e r m i n a l s ' o p e n ' and ' c l o s e ' b r a c k e t a sub- derivation
. . . open X c l o s e . . . => < X > . . .
p r e v e n t i n g a n y c o n s t i t u e n t f r o m b e i n g r e p o s i t i o n e d f r o m outside t h a t s u b d e r i v a t i o n into it. Figure 9.2 shows the use of rule (6) in the derivation of the sen- tence
The mouse t h a t t h e c a t t h a t l i k e s f i s h chased s q u e a k s .
This is b a s e d on the s a m e three simple sentences as the u n g r a m m a t i c a l string of Figure 9.1, which the
[image:9.612.105.505.64.442.2]d e t noun
open
t e l
s
__....----,0---.---_.
det noun
"-"--"T'el
the
mouseo p e n r s
[]
t
/
:[p
J
that
the cat
thal
ttke~
verb
det noun rel
verb
C l o s e
[]
_ _ _ _ _ . _ i !
J
l J
Fish
chased
cl,
i
P
J
vp
verb
pse
[image:10.612.78.573.73.470.2]squeaks
Figure 9.2. Implementation of the complex-NP constraint.
r e a d e r can n o w try to derive in the modified g r a m m a r , to see h o w the b r a c k e t i n g constraint p r e v e n t s the de- rivation.
10. X G s as Logic P r o g r a m s
In the previous sections, I a v o i d e d the c o m p l i c a t i o n of n o n - t e r m i n a l arguments. A l t h o u g h it would be pos- sible to describe fully the o p e r a t i o n of X G s in t e r m s of derivations on b r a c k e t e d strings, it is m u c h simpler to c o m p l e t e the e x p l a n a t i o n of X G s using the translation of X G rules into definite clauses. In fact, a rigorous definition of X G s i n d e p e n d e n t l y of definite clauses would require a f o r m a l a p p a r a t u s v e r y similar to the o n e n e e d e d to f o r m a l i s e definite clause p r o g r a m s in the first place, and so it would fall outside the scope of the p r e s e n t paper. T h e interested r e a d e r will find a full discussion of those issues in t w o articles b y Col- m e r a u e r [2,3].
Like a D C G , a general X G is no m o r e t h a n a c o n - venient n o t a t i o n f o r a set of definite clauses. A n X G n o n - t e r m i n a l of arity n c o r r e s p o n d s to an n + 4 place p r e d i c a t e (with the s a m e n a m e ) . O f the e x t r a f o u r a r g u m e n t s , t w o are used to r e p r e s e n t string positions as in D C G s , and the o t h e r t w o are used to r e p r e s e n t positions in an extraposition list, which carries s y m b o l s to be repositioned.
E a c h e l e m e n t of the e x t r a p o s i t i o n list r e p r e s e n t s a s y m b o l being r e p o s i t i o n e d as a 4 - t u p l e
x(context, type, symbol, xlist)
where context is either ' g a p ' , if the s y m b o l was p r e c e d - ed b y '...' in the rule w h e r e it originated, or ' n o g a p ' , if the s y m b o l was p r e c e d e d b y ','; type m a y be ' t e r m i n a l ' or ' n o n t e r m i n a l ' , with the o b v i o u s meaning; symbol is the s y m b o l p r o p e r ; xlist is the r e m a i n d e r of the e x t r a - position list (an e m p t y list being r e p r e s e n t e d b y '[ ]').
A n X G rule is translated into a clause for the pred- icate corresponding to the leading symbol of the rule. In the case where the X G rule has just a single symbol on the left-hand side, the translation is very similar to that of D C G rules. F o r example, the rule
sentence --> noun_phrase, verbphrase.
translates into
sentence(S0,S,X0,X) : -
noun_phrase(S0,S1 ,X0 ,Xl ), verb_phrase(S1 ,S,Xl ,X).
A terminal t in the right-hand side of a rule translates into a call to the predicate 'terminal', defined below, whose role is analogous to that of ' c o n n e c t s ' in D C G s . F o r example, the rule
rel_pronoun --> [ t h a t ] .
translates into
re]_pronoun (S0,S,X0,X) : -
terminal (that ,SO ,S ,XO ,X ).
The translation of a rule with more than one symbol in the left-hand side is a bit more complicated. Informal- ly, each symbol after the first is made into a 4-tuple as described above, and fronted to the extraposition list. Thus, for example, the rule
rel_marker . . . trace --> rel_pronoun.
translates into
rel_marker(SO,S,XO,x(gap,nonterminal ,trace,X)) :- rel_pronoun ( SO, S, XO, X ).
F u r t h e r m o r e , for each distinct n o n - l e a d i n g n o n - terminal n t (with arity n) in the left-hand side of a rule of the XG, the translation includes the clause
n/(Vl . . . Vn,S,S,XO,X) :-
v i r t u a l (n/(Vl . . . Vn) ,XO,X).
where ' v i r t u a l ( C , X 0 , X ) ' , defined later, can be read as " C is the constituent b e t w e e n X0 and X in the extra- position list", and the variables Vi transfer the argu- ments of the symbol in the extraposition list to the predicate which translates that symbol.
F o r example, the rule
marker(Var), [the] . . . [of.whom], trace(Var) --> [whose].
which can be used in a more complex g r a m m a r of relative clauses to transform " w h o s e X " into " t h e X of w h o m " , corresponds to the clauses:
marker(Var,SO,S,XO, x ( nogap, terminal, the, x(gap,terminal ,of, x(nogap ,terminal ,whom,
x(nogap,nonterminal ,trace(Var), x ) ) ) ) ) : -
termi hal (whose ,SO, S ,XO, X ).
trace(Var,S,S,XO,X) :- virtual(trace(Var),XO,X).
Finally, the two auxiliary predicates 'virtual' and 'terminal' are defined as follows:-
v i r t u a l ( N T , x(C,nonterminal,NT,X), X).
t e r m i n a l ( T , SO, S, X, X) :- gap(X), connects(SO, T, S).
t e r m i n a l ( T , S, S, x ( C , t e r m i n a l , T , X ) , X).
gap(x(gap,T,S,X)). gap([ ] ) .
where ' c o n n e c t s ' is as for D C O s .
These definitions need some comment. The first clause for ' t e r m i n a l ' says that, p r o v i d e d the current extraposition list allows a gap to appear in the deriva- tion, terminal symbol T m a y be taken from the posi- tion SO in the source string, where T connects SO to some new position S. The second clause for 'terminal' says that if the next symbol in the current extraposi- tion list is a terminal T, then this symbol can be taken as if it occurred at S in the source string. The clause for 'virtual' allows a n o n - t e r m i n a l to be " r e a d off f r o m " the extraposition list.
* r e l a t i v e ( 6 , 9 , X , X )
* o p e n ( 6 , 6 , x ( g a p , n t , t r a c e , x ( g a p , n t , c l o s e , [ ] ) ) , x ( g a p , n t , c l o s e , x ( g a p , n t , t r a c e ,
x ( g a p , n t , c l o s e , [ ] ) ) ) )
* rel_marker(6,7,x(gap,nt,close,x(gap,nt,trace, x(gap,nt,close
x(gap,nt,trace x(gap,nt,trace rel_pronoun(6,7,X
[ t h a t ]
sentence(7,9,x(gap x(gap,nt,trace x(gap,nt,close
, [ ] ) ) ) ,
,x(gap,nt,close, , x ( g a p , n t , c l o s e , [ ] ) ) ) ) ) ,X)
, n t , t r a c e , x ( g a p , n t , c l o s e , , x ( g a p , n t , c l o s e , [ ] ) ) ) ) , ,x(gap,nt,trace, x ( g a p , n t , c l o s e , [ ] ) ) ) )
* noun_phrase(7,7,x(gap,nt,trace,x(gap,nt,close, x ( g a p , n t , t r a c e , x ( g a p , n t , c l o s e , [ ] ) ) ) ) , x ( g a p , n t , c l o s e , x ( g a p , n t , t r a c e , x ( g a p , n t , c l o s e , [ ] ) ) ) )
* t r a c e ( 7 , 7 , x ( g a p , n t , t r a c e , x ( g a p , n t , c l o s e , x ( g a p , n t , t r a c e , x ( g a p , n t , c l o s e , [ ] ) ) ) ) , x ( g a p , n t , c l o s e , x ( g a p , n t , t r a c e , x ( g a p , n t , c l o s e , [ ] ) ) ) )
* verb_phrase(7,9,X,X) * verb(7,8,X,X)
[ l i k e s ]
* noun_phrase(8,9,X,X) * determiner(8,8,X,X) * noun(8,9,X,X)
[ f i s h ]
* r e l a t i v e ( 9 , 9 , X , X )
* c l o s e ( 9 , 9 , x ( g a p , n t , c l o s e , x ( g a p , n t , t r a c e , x ( g a p , n t , c l o s e , [ ] ) ) ) ,
x ( g a p , n t , t r a c e , x ( g a p , n t , c l o s e , [ ] ) ) )
Figure 10.1. Derivation of " t h a t likes fish".
Figure 10.1 shows a f r a g m e n t of the analysis in Figure 9.2, but n o w in terms of the translation of X G rules into definite clauses. Points on the sentence are labelled as follows:
the mouse that the cat t h a t l i k e s f i s h chased squeaks
I 2 3 4 5 6 7 8 9 10 11
T h e nodes of the analysis f r a g m e n t , for the relative clause " t h a t likes fish", are r e p r e s e n t e d by the corre- s p o n d i n g goals, i n d e n t e d in p r o p o r t i o n to their dis- tance f r o m the root of the graph. T h e following c o n - ventions are used to simplify the figure:
• T h e leaves ( t e r m i n a l s ) of the g r a p h are listed directly;
• the values of the e x t r a p o s i t i o n a r g u m e n t s are explictly r e p r e s e n t e d only f o r those goals t h a t add or delete something to the e x t r a p o s i t i o n list; for the other goals, the two identical values are r e p r e s e n t e d by the variable ' X ' ;
• the goals for ' t e r m i n a l ' and 'virtual' are left out as t h e y can be easily r e c o n s t r u c t e d f r o m the other goals and the definitions a b o v e ;
• ' n o n t e r m i n a l ' is a b b r e v i a t e d as ' n t ' .
T h e definite clause p r o g r a m c o r r e s p o n d i n g to the g r a m m a r for this e x a m p l e is listed in A p p e n d i x II.
T h e e x a m p l e shows clearly h o w the b r a c k e t i n g constraint works. Symbols are placed in the e x t r a p o s i - tion list by rules with m o r e than one s y m b o l in the l e f t - h a n d side, and r e m o v e d by calls to 'virtual', on a first-in-last-out basis; that is, the e x t r a p o s i t i o n list is a
stack.
But this p r o p e r t y of the e x t r a p o s i t i o n list is e x a c t l y w h a t is n e e d e d to b a l a n c e " o n the f l y " the auxiliary b r a c k e t s in the i n t e r m e d i a t e steps of a deri- vation.Being no m o r e t h a n a logic p r o g r a m , an X G can be used for analysis and for synthesis in the s a m e w a y as a D C G . F o r instance, to d e t e r m i n e w h e t h e r a string s with initial point
initial
and final pointfinal
is in the language defined by the X G of Figure 8.1, one tries to p r o v e the goal s t a t e m e n t?-sentence(initial,
final,[
3,[ 3).As for D C G s , the string s can be r e p r e s e n t e d in sever- al ways. If it is r e p r e s e n t e d as a list, the a b o v e goal would be written
?-sentence(s,[ ] , [ ] , [ ]).
T h e last two a r g u m e n t s of the goal are '[ ]' to m e a n t h a t the overall e x t r a p o s i t i o n list goes f r o m '[ ]' to '[ ]'; i.e., it is the e m p t y list. Thus, no c o n s t i t u e n t can be r e p o s i t i o n e d into or out of the top level ' s e n t e n c e ' .
11. C o n c l u s i o n s a n d Further W o r k
In this p a p e r I h a v e p r o p o s e d an e x t e n s i o n of D C G s . T h e m o t i v a t i o n for this extension was to p r o - vide a simple f o r m a l device to describe the structure of such i m p o r t a n t natural language constructions as rela- tive clauses and interrogative sentences. In t r a n s f o r m a - tional g r a m m a r , these constructions h a v e usually b e e n analysed in terms of left extraposition, t o g e t h e r with global constraints, such as the c o m p l e x - N P constraint,
which restrict the range of the extraposition. G l o b a l constraints are not explicit in the g r a m m a r rules, but are given externally to be e n f o r c e d across rule applica- tions. T h e s e external global constraints cause t h e o r e t - ical difficulties, b e c a u s e the f o r m a l p r o p e r t i e s of the resulting s y s t e m s are far f r o m evident, and practical difficulties, b e c a u s e t h e y lead to o b s c u r e g r a m m a r s and p r e v e n t the use of a n y r e a s o n a b l e parsing algor- ithm.
D C G s , although t h e y p r o v i d e the basic m a c h i n e r y f o r a clear d e s c r i p t i o n of l a n g u a g e s a n d their struc- tures, lack a m e c h a n i s m to describe simply left e x t r a - p o s i t i o n a n d the a s s o c i a t e d restrictions. M G s c a n express the rewrite of several s y m b o l s in a single rule, but the s y m b o l s m u s t be contiguous, as in a t y p e - 0 g r a m m a r rule. This is still not e n o u g h to describe left e x t r a p o s i t i o n w i t h o u t c o m p l i c a t i n g the rest of the g r a m m a r . X G s are an a n s w e r to those limitations.
An X G has the s a m e f u n d a m e n t a l p r o p e r t y as a D C G , that it is no m o r e t h a n a c o n v e n i e n t n o t a t i o n for the clauses of an o r d i n a r y logic p r o g r a m . X G s a n d their t r a n s l a t i o n into definite clauses h a v e b e e n de- signed to m e e t three requirements: (i) to be a princi- pled extension of D C G s , which c a n be i n t e r p r e t e d as a g r a m m a r f o r m a l i s m i n d e p e n d e n t l y of its t r a n s l a t i o n into definite clauses; (ii) to p r o v i d e for simple descrip- tion of left e x t r a p o s i t i o n and related restrictions; (iii) to be c o m p a r a b l e in efficiency with D C G S w h e n exec- uted b y P R O L O G . It turns out that these r e q u i r e m e n t s are not c o n t r a d i c t o r y , and that the resulting design is e x t r e m e l y simple. T h e restrictions on e x t r a p o s i t i o n are n a t u r a l l y e x p r e s s e d in t e r m s of scope, a n d s c o p e is e x p r e s s e d in the f o r m a l i s m b y " b r a c k e t i n g o u t " sub- d e r i v a t i o n s c o r r e s p o n d i n g to b a l a n c e d strings. T h e notion of b r a c k e t e d string derivation is i n t r o d u c e d in o r d e r to d e s c r i b e e x t r a p o s i t i o n a n d b r a c k e t i n g inde- p e n d e n t l y of the t r a n s l a t i o n of X G s into logic p r o - grams.
S o m e questions a b o u t X G s h a v e not b e e n tackled in this paper. First, f r o m a theoretical point of view it would be n e c e s s a r y to c o m p l e t e the i n d e p e n d e n t char- acterisation of X G s in t e r m s of b r a c k e t e d strings, and show rigorously that the translation of X G s into logic p r o g r a m s c o r r e c t l y renders this i n d e p e n d e n t c h a r a c t e r - isation of the semantics of X G s . As p o i n t e d out b e - fore, this f o r m a l i s a t i o n does not o f f e r a n y substantial problems.
Next, it is not clear w h e t h e r X G s are as general as they could be. F o r instance, it might be possible to e x t e n d t h e m to handle
right
e x t r a p o s i t i o n of constitu- ents, which, although less c o m m o n t h a n left e x t r a p o s i - tion, c a n be used to describe quite f r e q u e n t English constructions, such as the gap b e t w e e n h e a d n o u n and relative clause in:What f i l e s are there t h a t were created today?
It m a y h o w e v e r be possible to describe such situations in terms of left extraposition of s o m e other constituent (e.g. the v e r b p h r a s e " a r e t h e r e " in the e x a m p l e a b o v e ) .
Finally, I h a v e b e e n looking at w h a t t r a n s f o r m a - tions should be applied to an X G d e v e l o p e d as a clear description of a language, so that the resulting g r a m - m a r could be used m o r e efficiently in parsing. In par- ticular, I have b e e n trying to generalise results on det- erministic parsing of c o n t e x t - f r e e languages into a p - p r o p r i a t e principles of t r a n s f o r m a t i o n .
A c k n o w l e d g e m e n t s
David W a r r e n and Michael M c C o r d read drafts of this paper, and their c o m m e n t s led to m a n y i m p r o v e - ments, b o t h in c o n t e n t and in form. The c o m m e n t s of the referees were also very useful. A British Council Fellowship partly s u p p o r t e d m y w o r k in this subject. T h e c o m p u t i n g facilities I used to e x p e r i m e n t with X G s and to p r e p a r e this p a p e r were m a d e available b y British Science R e s e a r c h Council grants.
Appendix I. Translating XGs
T h e following P R O L O G p r o g r a m (for the D E C - 1 0 P R O L O G system) defines a predicate ' g r a m m a r ( F i l e ) ' which translates and stores the X G rules c o n t a i n e d in File. The symbol ' ' as a predicate or f u n c t o r argu- m e n t d e n o t e s an " a n o n y m o u s " variable, i.e. each such occurrence stands for a s e p a r a t e variable with a single occurrence.
% D e f i n i t i o n of the grammar rule operators
• - o p ( 1 O O 1 , x f y , ( . . . ) ) . • - op(t2OO,xfx,(-->)).
% Process the XG in F i l e
grammar(File) :- seeing(Old), s e e ( F i l e ) , consume, seen, see(Old).
% Loop u n t i l end of f i l e
consume :- repeat,
read(X),
( X=end of f i l e , !; process(X),
f a i l ).
% Process a grammar rule
process((L-->R)) :- !, expandlhs(L,SO,S,HO,H,P), expandrhs(R,SO,S,HO,H,Q), assertz((P :- Q)), !.
% Execute a command
process(( :- G)) :- !, G.
% Store a normal clause
process((P :- Q)) :- assertz((P :- Q)).
% Store a u n i t clause
process(P) :- assertz(P).
% Translate an XG rule % Translate the left-hand side
expandlhs(T,SO,S,HO,HI,Q) :- f l a t t e n ( T , [ P I L ] , [ ] ) , f r o n t ( L , H I , H ) , tag(P,SO,S,HO,H,Q).
f l a t t e n ( ( X . . . Y ) , L O , L ) :- !, f l a t t e n ( X , L O , [ g a p l L I ] ) , f l a t t e n ( Y , L I , L ) . f l a t t e n ( ( X , Y ) , L O , L ) :- !,
flatten(X,LO,[nogap I L I ] ) , f l a t t e n ( Y , L I , L ) .
f l a t t e n ( X , [ X l L ] , L ) .
f r o n t ( [ ] , H , H ) .
f r o n t ( [ K , X I L],HO,H) :- case(X,K,HI,H), front(L,HO,H1).
case([TITs],K,HO,x(K,terminal,T,H)) :- !, unwind(Ts,HO,H).
case(Nt,K,H,x(K,nonterminal,Nt,H)) :- v i r t u a l _ r u l e ( N t ) .
% Create the clause
% Nt(S,S,XO,X) :- virtual(Nt,XO,X) % for extraposed symbol Nt
v i r t u a l rule(Nt) :- functor(Nt,F,N), functor(Y,F,N), tag(Y,S,S,Hx,Hy,P),
( c l a u s e ( P , v i r t u a l ( , , ), ), !; asserta((P :- v i r t u a l ( Y , H x , H y ) ) ) ).
% Translate the right-hand side
expandrhs((XI,X2),SO,S,HO,H,Y) :- !, expandrhs(XI,SO,SI,HO,HI,Y1), expandrhs(X2,SI,S,HI,H,Y2), and(YI,Y2,Y).
expandrhs((X1;X2),SO,S,HO,H,(Y1;Y2)) :- !, expandor(X1,SO,S,HO,H,Y1),
expandor(X2,SO,S,HO,H,Y2). expandrhs({X},S,S,H,H,X) :- .
expandrhs(L,SO,S,HO,H,G) :- i s l i s t ( L ) , !, expandlist(L,SO,S,HO,H,G).
expandrhs(X,SO,S,HO,H,Y) :- tag(X,SO,S,HO,H,Y).
expandor(X,SO,S,HO,H,Y) :- expandrhs(X,SOa,S,HOa,H,Ya),
( S\==SOa, !, SO=SOa, Yb=Ya; and(SO=SOa,Ya,Yb) ), ( H\==HOa, !, HO=HOa, Y=Yb; and(HO=HOa,Yb,Y) ).
e x p a n d l i s t ( [ ] , S , S , H , H , t r u e ) .
expandlist([X],SO,S,HO,H,terminal(X,SO,S,HO,H) ) :- !. expandlist([XIL],SO,S,HO,H,
(terminal(X,SO,SI,HO,H1),Y)) :- expandlist(L,S1,S,HI,H,Y).
tag(P,AI,A2,A3,A4,Q) :- P=..[FIArgsO],
conc(ArgsO,[AI,A2,A3,A4],Args), Q=..[FIArgs].
and(true,P,P) :- !. and(P,true,P) :- !. and(P,Q,(p,Q)).
i s l i s t ( [ I ])- i s l i s t ( [ ] ) .
unwind([],H,H) :- !.
unwind([TITs],HO,x(nogap,terminal ,T,H)) unwind(Ts,HO,H).
conc([],L,L) :- !.
c o n c ( [ X l L 1 ] , L 2 , [ X I L 3 ] ) :- conc(LI,L2,L3).
A p p e n d i x II. D e f i n i t e c l a u s e s f o r t h e g r a m m a r u s e d in Figure 9.2
sentence(SO,S,XO,X) :- noun_phrase(SO,Sl,XO,X1), verb_phrase(SI,S,X1,X).
noun_phrase(SO,S,XO,X) :- proper_noun(SO,S,XO,X). noun_phrase(SO,S,XO,X) :-
determiner(SO,SI,XO,Xl), noun(S1,S2,X1,X2), relative(S2,S,X2,X). noun_phrase(SO,S,XO,X) :-
determiner(SO,S1,XO,Xl), noun(SI,S2,XI,X2), prep_phrase(S2,S,X2,X). noun_phrase(SO,S,XO,X) :-
trace(SO,S,XO,X).
verb_phrase(SO,S,XO,X) :- verb(SO,Sl,XO,X1), noun_phrase(SI,S,Xl,X). verb_phrase(SO,S,XO,X) :-
verb(SO,S,XO,X).
relative(SO,SO,X,X). relative(SO,S,XO,X) :-
open(SO,Sl,XO,Xl), rel_marker(Sl,S2,Xl,X2), sentence(S2,S3,X2,X3), close(S3,S,X3,X).
trace(SO,SO,XO,X) :- virtual(trace,XO,X).
rel_marker(SO,S,XO,x(gap,nonterminal,trace,X)) :- rel_pronoun(SO,S,XO,X).
prep_phrase(SO,S,XO,X) :- preposition(SO,S1,XO,Xl), noun_phrase(S1,S,XI,X).
open(SO,SO,X,x(gap,nonterminal,close,X)).
close(SO,SO,XO,X) :- virtual(close,XO,X).
R e f e r e n c e s
1. C h o m s k y , N. Reflections on Language. P a n t h e o n , 1975. 2. C o l m e r a u e r , A. " M e t a m o r p h o s i s G r a m m a r s . " In Natural Lan-
guage Communication with Computers, L .Bolc (ed.). Springer-
Verlag, 1978. First a p p e a r e d as an internal report, ' L e s G r a m - maires de M e t a m o r p h o s e ' , in N o v e m b e r 1975
3. C o l m e r a u e r , A. " L e s B a s e s T h 6 o r i q u e s de P R O L O G . " G r o u p e d'Intelligence Artificielle, U. E. R. de L u m i n y , Universit6 d ' A i x - Marseille II, 1979.
4. Dahl, V. " U n Syst6me D6ductif d ' I n t e r r o g a t i o n de B a n q u e s de D o n n 6 e s en E s p a g n o l . " G r o u p e d'Intelligence Artificielle, U. E. R. de L u m i n y , Universit6 d ' A i x - M a r s e i l l e II, 1977.
5. G a z d a r , G. " E n g l i s h as a C o n t e x t - F r e e L a n g u a g e . " School of Social Sciences, U n i v e r s i t y of Sussex, April, 1979.
6. Pereira, F. a n d W a r r e n , D. H. D. " D e f i n i t e C l a u s e G r a m m a r s for L a n g u a g e A n a l y s i s - A S u r v e y of t h e F o r m a l i s m a n d a C o m p a r i s o n with A u g m e n t e d T r a n s i t i o n N e t w o r k s . " Artificial Intelligence 13 (1980) 2 3 1 - 2 7 8 .
7. Pique, J. F. " I n t e r r o g a t i o n en F r a n c a i s d ' u n e Base de D o n n 6 e s R e l a t i o n n e l l e . " G r o u p e d'Intelligence Artificielle, U. E. R. de L u m i n y , Universit6 d ' A i x - M a r s e i l l e II, 1978.
8. R o s s , J. R. E x c e r p t s f r o m ' C o n s t r a i n t s o n Variables in Syntax'. In G. H a r m a n (ed.): On Noam Chomsky: Critical Essays, A n - c h o r Books, 1974.
9. R o u s s e l , P. " P R O L O G : M a n u e l de R 6 f e r e n c e et U t i l i s a t i o n . " G r o u p e d'Intelligence Artificielle, U . E . R . de L u m i n y , Universit6 d ' A i x - M a r s e i l l e II, 1975.
Fernando C.N. Pereira is a research associate in the Department o f Architecture at Edinburgh University, and also a graduate student in the Department o f Artificial Intelligence. H e received the M.Sc. degree in mathemat- ics f r o m Lisbon University in 1975.