Download presentation

Presentation is loading. Please wait.

Published byZack Elliston Modified over 2 years ago

1
Feb 2008 - MRDefinite Clause Grammar1 An Introduction to Definite Clause Grammars Grammars and Algorithms Prolog Recogniser DCGs

2
Feb 2008 - MRDefinite Clause Grammar2 CF Recognition in Pure Prolog Use lists to represent strings. the monkey grinned [the,monkey,grinned] Reinterpret CF rules as Prolog clauses s np vp s :- np, vp. Use append to concatenate the strings s(Z) :- np(X), vp(Y), append(X,Y,Z) Reinterpret lexical rules as simple assertions n [monkey] becomes n([monkey]).

3
Feb 2008 - MRDefinite Clause Grammar3 Complete Recogniser Program s(Z) :-np(X), vp(Y), append(X,Y,Z). np(Z):-d(X),n(Y), append(X,Y,Z). vp(Z):-v(Z). d([the]). n([monkey]). v([grinned]). v([danced]).

4
Feb 2008 - MRDefinite Clause Grammar4 Running the Recogniser ?- s([the, monkey,grinned]). yes. ?- s([the, monkey,spat]). no. ?- s(X). X=[the,monkey,grinned]; X=[the,monkey,danced]

5
Feb 2008 - MRDefinite Clause Grammar5 Difference Lists Using append is very inefficient. We can avoid append by using difference lists. Key idea is to represent a string as the difference between two lists. For this purpose we employ two pointers.

6
Feb 2008 - MRDefinite Clause Grammar6 Difference Lists Here are different ways of representing the string a b c [a,b,c] [ ] [a,b,c,x] [x] [a,b,c,x,y] [x,y] a b c x y P1 P2

7
Feb 2008 - MRDefinite Clause Grammar7 Recogniser Using Difference Lists s(X,Z) :-np(X,Y), vp(Y,Z). np(X,Z):-d(X,Y), n(Y,Z). vp(X,Y):-v(X,Y). d([the|Rest],Rest). n([monkey|Rest],Rest). v([grinned|Rest],Rest). v([danced|Rest],Rest).

8
Feb 2008 - MRDefinite Clause Grammar8 Running the Recogniser ?- s([the, monkey,grinned],[]). yes. ?- s([the, monkey,spat],[]). no. ?- s(X,[]). X=[the,monkey,grinned]; X=[the,monkey,danced]

9
Feb 2008 - MRDefinite Clause Grammar9 Difference Lists Advantages append not used efficiency Disadvantages More difficult to understand the interpreter Can we retain advantages and eliminate disadvantages ?

10
Feb 2008 - MRDefinite Clause Grammar10 Definite Clause Grammars (DCGs) s --> np, vp. vp --> v. vp --> v, np. d --> [walks]. v --> [hits]. np --> [suzie]. np --> [fido].

11
Feb 2008 - MRDefinite Clause Grammar11 How DCGs are compiled We run the DCG recogniser in exactly the same way as we run the difference-list recogniser. The reason is that DCG notation is just syntactic sugar.The DCG rule x --> y, z. is actually compiled into an ordinary clause x(V1,V2) :- y(V1,V3), z(V3,V2). whilst the preterminal rule x --> [word]. compiles to the clause x([word|W],W]).

12
Feb 2008 - MRDefinite Clause Grammar12 Use of Curly Brackets Suppose we have s(Z) -> np(X), vp(Y). and there is an ordinary predicate p(X,Y,Z) which operates on the arguments. We enclose the ordinary predicate in curly brackets to avoid the automatic addition of two argument places. s(Z) -> np(X), vp(Y), {p(X,Y,Z)}

13
Feb 2008 - MRDefinite Clause Grammar13 Adding Features Suppose we wish to impose number agreement between np and vp To solve the problem of multiplying categories, we need to add feature constraints to our grammar specifications, in order to express the following sort of fact s np vp constraint: number(np) = number(vp) Fortunately we can do just that because the constituents of rules can be full Prolog terms, which may include variables arguments.

14
Feb 2008 - MRDefinite Clause Grammar14 Fixing the Grammar OLD GRAMMAR s --> np, vp. np --> n. np --> d, n. vp --> v np. NEW GRAMMAR s --> np(N),vp(N). np(N) --> n(N). np(N) --> d(N),n(N). vp(N) --> v(N),np(_).

Similar presentations

OK

Type Inference: CIS Seminar, 11/3/2009 Type inference: Inside the Type Checker. A presentation by: Daniel Tuck.

Type Inference: CIS Seminar, 11/3/2009 Type inference: Inside the Type Checker. A presentation by: Daniel Tuck.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on plants and trees Ppt on nutrition in plants for class 7 Ppt on current indian economy Ppt on high voltage engineering pdf Ppt on chapter 3 atoms and molecules video Ppt on as 14 amalgamation synonym Read ppt on iphone Ppt on economic order quantity formula Download ppt on bluetooth hotspot Ppt on rational numbers for class 10