1 / 13

Definite Clause Grammar

Definite Clause Grammar. CS440 Sept 29, 2009. Solution to HW1. Maximum maximum([N],N):-number(N). maximum([X|List], M):- number(X), maximum(List, N), M is max(X,N). Solution to HW1. Depth depth([],1):-!. depth([X|List], M):- depth(X,N1), depth(List, N2), !,

diane
Download Presentation

Definite Clause Grammar

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Definite Clause Grammar CS440 Sept 29, 2009

  2. Solution to HW1 • Maximum maximum([N],N):-number(N). maximum([X|List], M):- number(X), maximum(List, N), M is max(X,N).

  3. Solution to HW1 • Depth depth([],1):-!. depth([X|List], M):- depth(X,N1), depth(List, N2), !, M is max(N1+1,N2). depth(_,0).

  4. Definite Clause Grammar • Convenient way to represent grammatical relationship for parsing. • Well used in natural language processing application. • Prolog is well suited for natural language processing. • Eg: [The, cat, chases, the, mouse] Sentence->nounphrase, verbphrase. verbphrase->verb, nounphrase.

  5. GCD -Difference List diffList(X,L,R) :- append(X,R,L). • How to parse : Sentence->nounphrase, verbphrase. 1. generate and test Sentence(X):- append(N,V,X) nounphrase(N), verbphrase(V). 2. difference list – get the part each predicate wants and pass the remainder to next. sentences(S,R):- nounphrase(P, S, R1), R1 = S-P verbphrase(V, R1, R). R = R1 – V

  6. DCG Syntax • --> operator indicates a DCG rule, replacing the normal neck ( :- ) used for Prolog clauses. For example, the sentence grammar rule can be written using a DCG rule: sentence --> subject, verb, object. • Each goal is assumed to refer to the head of a DCG rule, and the preprocessor adds two extra arguments for the difference list. • Curly braces {} are used to isolate normal Prolog goals from the DCG preprocessor. For example: subject --> modifier, noun, {write('found subject')}. • Square brackets [], list notation, are used to indicate terminal symbols of the grammar. For example: noun --> [cat]

  7. GCD -Difference List • Thus, • each goal refers to one predicates head and two argument for different list. • Eg: term(Z) -> number(X), “*”, number(Y), {Z is X*Y} • Will be • term(Z, S, R):- • number(X,S,R1), number(Y,R1,R), Z is X*Y

  8. Single Digit Calculus • Eg: 3*4+5*8+6*3 • expr(Z) --> term(X), "+", expr(Y), {Z is X + Y}. expr(Z) --> term(Z). term(Z) --> number(X), "*", term(Y), {Z is X * Y}. term(Z) --> number(Z). number(X) --> [C], {"0"=<C, C=<"9", X is C - "0"}.

  9. Single Digit Calculus • expr(A, B, C) :- term(D, B, E), E=[43|F], expr(G, F, H), A is D+G, C=H. • expr(A, B, C) :- term(A, B, C).

  10. Single Digit Calculus • term(A, B, C) :- number(D, B, E), E=[42|F], term(G, F, H), A is D*G, C=H. • term(A, B, C) :- number(A, B, C).

  11. Single Digit Calculus • number(A, B, C) :- B=[D|E], [48]=<D, D=<[57], A is D-[48], C=E.

  12. Predicates Call • expr(Z,”1*2*4+5”,[]) . Need one extra argument for remainder after parsing. • expr(Z,”1*3*4+50”,R). R?

  13. THANKS

More Related