© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 8: More DCGs Theory –Examine two important capabilities offered by DCG notation: Extra arguments.

Slides:



Advertisements
Similar presentations
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 10: Cuts and Negation Theory –Explain how to control Prolog`s backtracking behaviour with.
Advertisements

Prolog programming....Dr.Yasser Nada. Chapter 8 Parsing in Prolog Taif University Fall 2010 Dr. Yasser Ahmed nada prolog programming....Dr.Yasser Nada.
Intro to NLP - J. Eisner1 Modeling Grammaticality [mostly a blackboard lecture]
Natural Language Processing Syntax. Syntactic structure John likes Mary PN VtVt NP VP S DetPNVtVt NP VP S Every man likes Mary Noun.
November 2008NLP1 Natural Language Processing Definite Clause Grammars.
CSA2050: DCG I1 CSA2050 Introduction to Computational Linguistics Lecture 8 Definite Clause Grammars.
First-Order Logic (and beyond)
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 6: More Lists Theory –Define append/3, a predicate for concatenating two lists, and illustrate.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 6: More Lists Theory –Define append/3, a predicate for concatenating two lists, and illustrate.
Prolog: List © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
CSA4050: Advanced Topics in NLP Semantics IV Partial Execution Proper Noun Adjective.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Syntactic analysis using Context Free Grammars. Analysis of language Morphological analysis – Chairs, Part Of Speech (POS) tagging – The/DT man/NN left/VBD.
May 2006CLINT-LN Parsing1 Computational Linguistics Introduction Approaches to Parsing.
Feb MRDefinite Clause Grammar1 An Introduction to Definite Clause Grammars Grammars and Algorithms Prolog Recogniser DCGs.
Long Distance Dependencies (Filler-Gap Constructions) and Relative Clauses October 10, : Grammars and Lexicons Lori Levin (Examples from Kroeger.
Natural Language Processing DCG and Syntax NLP DCG A “translation” example: special case A DCG recogniser.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 9: 9/25.
Matakuliah: G0922/Introduction to Linguistics Tahun: 2008 Session 11 Syntax 2.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 7: Definite Clause Grammars Theory –Introduce context free grammars and some related concepts.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 5: Arithmetic Theory –Introduce Prolog`s built-in abilities for performing arithmetic –Apply.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 7: Definite Clause Grammars Theory –Introduce context free grammars and some related concepts.
LING 388 Language and Computers Lecture 10 10/2/03 Sandiway FONG.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 4: Lists Theory –Introduce lists, an important recursive data structure often used in Prolog.
LING 388: Language and Computers Sandiway Fong Lecture 17: 10/25.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 9: A closer look at terms Theory –Introduce the == predicate –Take a closer look at term structure.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 5: Arithmetic Theory –Introduce Prolog`s built-in abilities for performing arithmetic –Apply.
1 CONTEXT-FREE GRAMMARS. NLE 2 Syntactic analysis (Parsing) S NPVP ATNNSVBD NP AT NNthechildrenate thecake.
Normal forms for Context-Free Grammars
LING 364: Introduction to Formal Semantics Lecture 13 February 23rd.
LING 388 Language and Computers Lecture 9 9/30/03 Sandiway FONG.
LING 364: Introduction to Formal Semantics Lecture 5 January 26th.
LING 388: Language and Computers Sandiway Fong Lecture 13: 10/10.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 8: More DCGs Exercises –Solution to exercises LPN 7 –Recall of previous lecture Theory –Examine.
Linguistics II Syntax. Rules of how words go together to form sentences What types of words go together How the presence of some words predetermines others.
Context-Free Grammar CSCI-GA.2590 – Lecture 3 Ralph Grishman NYU.
Models of Generative Grammar Smriti Singh. Generative Grammar  A Generative Grammar is a set of formal rules that can generate an infinite set of sentences.
LING 388: Language and Computers Sandiway Fong 10/4 Lecture 12.
Linguistic Theory Lecture 3 Movement. A brief history of movement Movements as ‘special rules’ proposed to capture facts that phrase structure rules cannot.
11 CS 388: Natural Language Processing: Syntactic Parsing Raymond J. Mooney University of Texas at Austin.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Horn clauses A literal is an atomic formula or its negation A clause is a disjunction of literals.
October 2004csa4050: Semantics II1 CSA4050: Advanced Topics in NLP Semantics II The Lambda Calculus Semantic Representation Encoding in Prolog.
Context Free Grammars Reading: Chap 12-13, Jurafsky & Martin This slide set was adapted from J. Martin, U. Colorado Instructor: Paul Tarau, based on Rada.
1 Features and Unification Chapter 15 October 2012 Lecture #10.
LING 388: Language and Computers Sandiway Fong Lecture 7.
LING 388: Language and Computers Sandiway Fong Lecture 3.
Natural Language Processing Lecture 6 : Revision.
The Pumping Lemma for Context Free Grammars. Chomsky Normal Form Chomsky Normal Form (CNF) is a simple and useful form of a CFG Every rule of a CNF grammar.
LING 388: Language and Computers Sandiway Fong Lecture 10.
PARSING David Kauchak CS159 – Spring 2011 some slides adapted from Ray Mooney.
October 2004CSA4050: Semantics III1 CSA4050: Advanced Topics in NLP Semantics III Quantified Sentences.
Context Free Grammars Reading: Chap 9, Jurafsky & Martin This slide set was adapted from J. Martin, U. Colorado Instructor: Rada Mihalcea.
Semantic Construction lecture 2. Semantic Construction Is there a systematic way of constructing semantic representation from a sentence of English? This.
1 Definite Clause Grammars for Language Analysis – A Survey of the Formalism and a Comparison with Augmented Transition Networks 인공지능 연구실 Hee keun Heo.
Rules, Movement, Ambiguity
Artificial Intelligence: Natural Language
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 9: A closer look at terms Theory –Introduce the == predicate –Take a closer look at term structure.
Operators in Prolog © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong. Did you install SWI Prolog?
◦ Process of describing the structure of phrases and sentences Chapter 8 - Phrases and sentences: grammar1.
CAS LX 502 9b. Formal semantics Pronouns and quantifiers.
Natural Language Processing
Chapter Eight Syntax.
Chapter Eight Syntax.
LING/C SC/PSYC 438/538 Lecture 22 Sandiway Fong.
CSCI 5832 Natural Language Processing
CSA4050: Advanced Topics in NLP
Lecture 7: Definite Clause Grammars
Presentation transcript:

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 8: More DCGs Theory –Examine two important capabilities offered by DCG notation: Extra arguments Extra tests –Discuss the status and limitations of DCGs Exercises –Exercises of LPN: 8.1, 8.2 –Practical session

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Extra arguments In the previous lecture we introduced basic DCG notation But DCGs offer more than we have seen so far –DCGs allow us to specify extra arguments –These extra arguments can be used for many purposes

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Extending the grammar s --> np, vp. np --> det, n. vp --> v, np. vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. This is the simple grammar from the previous lecture Suppose we also want to deal with sentences containing pronouns such as she shoots him and he shoots her What do we need to do?

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Extending the grammar s --> np, vp. np --> det, n. np --> pro. vp --> v, np. vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. pro --> [he]. pro --> [she]. pro --> [him]. pro --> [her]. Add rules for pronouns Add a rule saying that noun phrases can be pronouns Is this new DCG any good? What is the problem?

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Some examples of grammatical strings accepted by this DCG s --> np, vp. np --> det, n. np --> pro. vp --> v, np. vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. pro --> [he]. pro --> [she]. pro --> [him]. pro --> [her]. ?- s([she,shoots,him],[ ]). yes ?- s([a,woman,shoots,him],[ ]). yes

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Some examples of ungrammatical strings accepted by this DCG s --> np, vp. np --> det, n. np --> pro. vp --> v, np. vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. pro --> [he]. pro --> [she]. pro --> [him]. pro --> [her]. ?- s([a,woman,shoots,he],[ ]). yes ?- s([her,shoots,a,man],[ ]). yes s([her,shoots,she],[ ]). yes

© Patrick Blackburn, Johan Bos & Kristina Striegnitz What is going wrong? The DCG ignores some basic facts about English –she and he are subject pronouns and cannot be used in object position –her and him are object pronouns and cannot be used in subject position It is obvious what we need to do: extend the DCG with information about subject and object How do we do this?

© Patrick Blackburn, Johan Bos & Kristina Striegnitz A naïve way… s --> np_subject, vp. np_subject --> det, n. np_object --> det, n. np_subject --> pro_subject. np_object --> pro_object. vp --> v, np_object. vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. pro_subject --> [he]. pro_subject --> [she]. pro_object --> [him]. pro_object --> [her].

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Nice way using extra arguments s --> np(subject), vp. np(_) --> det, n. np(X) --> pro(X). vp --> v, np(object). vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. pro(subject) --> [he]. pro(subject) --> [she]. pro(object) --> [him]. pro(object) --> [her].

© Patrick Blackburn, Johan Bos & Kristina Striegnitz This works… s --> np(subject), vp. np(_) --> det, n. np(X) --> pro(X). vp --> v, np(object). vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. pro(subject) --> [he]. pro(subject) --> [she]. pro(object) --> [him]. pro(object) --> [her]. ?- s([she,shoots,him],[ ]). yes ?- s([she,shoots,he],[ ]). no ?-

© Patrick Blackburn, Johan Bos & Kristina Striegnitz What is really going on? Recall that the rule: s --> np,vp. is really syntactic sugar for: s(A,B):- np(A,C), vp(C,B).

© Patrick Blackburn, Johan Bos & Kristina Striegnitz What is really going on? Recall that the rule: s --> np,vp. is really syntactic sugar for: s(A,B):- np(A,C), vp(C,B). The rule s --> np(subject),vp. translates into: s(A,B):- np(subject,A,C), vp(C,B).

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Listing noun phrases s --> np(subject), vp. np(_) --> det, n. np(X) --> pro(X). vp --> v, np(object). vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. pro(subject) --> [he]. pro(subject) --> [she]. pro(object) --> [him]. pro(object) --> [her]. ?- np(Type, NP, [ ]). Type =_ NP = [the,woman]; Type =_ NP = [the,man]; Type =_ NP = [a,woman]; Type =_ NP = [a,man]; Type =subject NP = [he]

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Building parse trees The programs we have discussed so far have been able to recognise grammatical structure of sentences But we would also like to have a program that gives us an analysis of their structure In particular we would like to see the trees the grammar assigns to sentences

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Parse tree example s vp np np det n v det n the woman shoots a man

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Parse tree in Prolog s vp np np det n v det n the woman shoots a man s(np(det(the),n(woman)), vp(v(shoots),np(det(a),n(man)))))

© Patrick Blackburn, Johan Bos & Kristina Striegnitz DCG that builds parse tree s --> np(subject), vp. np(_) --> det, n. np(X) --> pro(X). vp --> v, np(object). vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. pro(subject) --> [he]. pro(subject) --> [she]. pro(object) --> [him]. pro(object) --> [her].

© Patrick Blackburn, Johan Bos & Kristina Striegnitz DCG that builds parse tree s --> np(subject), vp. np(_) --> det, n. np(X) --> pro(X). vp --> v, np(object). vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. pro(subject) --> [he]. pro(subject) --> [she]. pro(object) --> [him]. pro(object) --> [her]. s(s(NP,VP)) --> np(subject,NP), vp(VP). np(_,np(Det,N)) --> det(Det), n(N). np(X,np(Pro)) --> pro(X,Pro). vp(vp(V,NP)) --> v(V), np(object,NP). vp(vp(V)) --> v(V)). det(det(the)) --> [the]. det(det(a)) --> [a]. n(n(woman)) --> [woman]. n(n(man)) --> [man]. v(v(shoots)) --> [shoots]. pro(subject,pro(he)) --> [he]. pro(subject,pro(she)) --> [she]. pro(object,pro(him)) --> [him]. pro(object,pro(her)) --> [her].

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Generating parse trees s(s(NP,VP)) --> np(subject,NP), vp(VP). np(_,np(Det,N)) --> det(Det), n(N). np(X,np(Pro)) --> pro(X,Pro). vp(vp(V,NP)) --> v(V), np(object,NP). vp(vp(V)) --> v(V)). det(det(the)) --> [the]. det(det(a)) --> [a]. n(n(woman)) --> [woman]. n(n(man)) --> [man]. v(v(shoots)) --> [shoots]. pro(subject,pro(he)) --> [he]. pro(subject,pro(she)) --> [she]. pro(object,pro(him)) --> [him]. pro(object,pro(her)) --> [her]. ?- s(T,[he,shoots],[]). T = s(np(pro(he)),vp(v(shoots))) yes

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Generating parse trees s(s(NP,VP)) --> np(subject,NP), vp(VP). np(_,np(Det,N)) --> det(Det), n(N). np(X,np(Pro)) --> pro(X,Pro). vp(vp(V,NP)) --> v(V), np(object,NP). vp(vp(V)) --> v(V)). det(det(the)) --> [the]. det(det(a)) --> [a]. n(n(woman)) --> [woman]. n(n(man)) --> [man]. v(v(shoots)) --> [shoots]. pro(subject,pro(he)) --> [he]. pro(subject,pro(she)) --> [she]. pro(object,pro(him)) --> [him]. pro(object,pro(her)) --> [her]. ?- s(Tree,S,[]).

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Beyond context free languages In the previous lecture we presented DCGs as a useful tool for working with context free grammars However, DCGs can deal with a lot more than just context free grammars The extra arguments gives us the tools for coping with any computable language We will illustrate this by looking at the formal language a n b n c n \{  }

© Patrick Blackburn, Johan Bos & Kristina Striegnitz An example The language a n b n c n \{  } consists of strings such as abc, aabbcc, aaabbbccc, aaaabbbbcccc, and so on This language is not context free – it is impossible to write a context free grammar that produces exactly these strings But it is very easy to write a DCG that does this

© Patrick Blackburn, Johan Bos & Kristina Striegnitz DCG for a n b n c n \{  } s(Count) --> as(Count), bc(Count), cs(Count). as(0) --> []. as(succ(Count)) --> [a], as(Count). bs(0) --> []. bs(succ(Count)) --> [b], bs(Count). cs(0) --> []. cs(succ(Count)) --> [c], cs(Count).

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Exercises LPN 8.1

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Extra goals Any DCG rule is really syntactic structure for ordinary Prolog rule So it is not really surprising we can also call any Prolog predicate from the right- hand side of a DCG rule This is done by using curly brackets { }

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Example: DCG for a n b n c n \{  } s(Count) --> as(Count), bc(Count), cs(Count). as(0) --> []. as(NewCnt) --> [a], as(Cnt), {NewCnt is Cnt + 1}. bs(0) --> []. bs(NewCnt) --> [b], bs(Cnt), {NewCnt is Cnt + 1}. cs(0) --> []. cs(NewCnt) --> [c], cs(Cnt), {NewCnt is Cnt + 1}.

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Separating rules and lexicon One classic application of the extra goals of DCGs in computational linguistics is separating the grammar rules from the lexicon What does this mean? –Eliminate all mention of individual words in the DCG –Record all information about individual words in a separate lexicon

© Patrick Blackburn, Johan Bos & Kristina Striegnitz The basic grammar s --> np, vp. np --> det, n. vp --> v, np. vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots].

© Patrick Blackburn, Johan Bos & Kristina Striegnitz The modular grammar s --> np, vp. np --> det, n. vp --> v, np. vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. s --> np, vp. np --> det, n. vp --> v, np. vp --> v. det --> [Word], {lex(Word,det)}. n --> [Word], {lex(Word,n)}. v --> [Word], {lex(Word,v)}. lex(the, det). lex(a, det). lex(woman, n). lex(man, n). lex(shoots, v).  +

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Concluding Remarks DCGs are a simple tool for encoding context free grammars But in fact DCGs are a full-fledged programming language and can be used for many different purposes For linguistic purposes, DCG have drawbacks –Left-recursive rules –DCGs are interpreted top-down DCGs are no longer state-of-the-art, but they remain a useful tool

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Next lecture A closer look at terms –Introduce the identity predicate –Take a closer look at term structure –Introduce pre-defined Prolog predicates that test whether a given term is of a certain type –Show how to define new operators in Prolog