Presentation is loading. Please wait.

Presentation is loading. Please wait.

November 2008NLP1 Natural Language Processing Definite Clause Grammars.

Similar presentations

Presentation on theme: "November 2008NLP1 Natural Language Processing Definite Clause Grammars."— Presentation transcript:

1 November 2008NLP1 Natural Language Processing Definite Clause Grammars

2 November 2008NLP2 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 November 2008NLP3 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 November 2008NLP4 Running the Recogniser ?- s([the, monkey,grinned]). yes. ?- s([the, monkey,spat]). no. ?- s(X). X=[the,monkey,grinned]; X=[the,monkey,danced]

5 November 2008NLP5 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 November 2008NLP6 Difference Lists Here are different ways of representing the string a b c using pointers P1 and P2 P1:[a,b,c]P2:[ ] P1:[a,b,c,x]P2:[x] P1:[a,b,c,x,y]P2:[x,y] a b c x y P1 P2

7 November 2008NLP7 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 November 2008NLP8 Running the Recogniser ?- s([the, monkey,grinned],[]). yes. ?- s([the, monkey,spat],[]). no. ?- s(X,[]). X=[the,monkey,grinned]; X=[the,monkey,danced]; no.

9 November 2008NLP9 Difference Lists Advantages append not used efficiency Disadvantages extra arguments in grammar rules grammar less readable Can we retain advantages and eliminate disadvantages ?

10 November 2008NLP10 Definite Clause Grammars (DCG) DCGs are just syntactic sugar Elimination of extra argument places Basic idea is still to look regard a grammar rule S  NP VP as an implication: NP & VP  S

11 November 2008NLP11 Definite Clause Grammars (DCGs) s --> np, vp. vp --> v. vp --> v, np. d --> [walks]. v --> [hits]. np --> [suzie]. np --> [fido].

12 November 2008NLP12 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|X],X]).

13 November 2008NLP13 Extra Arguments Even though we have eliminated variables in rules it is still possible to add extra arguments to which arbitrary terms can be bound. Later we will see how a rule x --> y, z. can be transformed into a rule x(Sx) --> y(Sy), z(Sz). where the red variables can be used to impose agreement or to carry semantic representations.

14 November 2008NLP14 Number Agreement This dog [  ] This dogs [  ] Those dogs [  ] Those dog [  ] np(sg) --> det(sg), n(sg). np(pl) --> det(pl), n(pl).

15 November 2008NLP15 Number Agreement This dog [  ] This dogs [  ] Those dogs [  ] Those dog [  ] np(sg) --> det(sg), n(sg). np(pl) --> det(pl), n(pl). np(N) --> det(N), n(N).

16 November 2008NLP16 Fixing the Grammar OLD GRAMMAR s --> np, vp. np --> n. np --> d, n. vp --> v np. NEW GRAMMAR s(N) --> np(N),vp(N). np(N) --> n(N). np(N) --> d(N),n(N). vp(N) --> v(N),np(_).

17 November 2008NLP17 Syntactic Structure Argument positions can contain arbitrary terms. For example, terms can be used to represent syntactic structure s( s(NP,VP) ) --> np(NP),vp(VP).

18 November 2008NLP18 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)}

19 November 2008NLP19 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.

Download ppt "November 2008NLP1 Natural Language Processing Definite Clause Grammars."

Similar presentations

Ads by Google