SlideShare a Scribd company logo
Lecture 8: More DCGs

                                                       •  Theory
                                                         – Examine two important capabilities offered
                                                           by DCG notation:
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                            •  Extra arguments
                                                            •  Extra tests
                                                         – Discuss the status and limitations of DCGs
                                                       •  Exercises
                                                         – Exercises of LPN: 8.1, 8.2
                                                         – Practical session
Extra arguments

                                                       •  In the previous lecture we introduced
                                                          basic DCG notation
                                                       •  But DCGs offer more than we have seen
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                          so far
                                                         – DCGs allow us to specify extra arguments
                                                         – These extra arguments can be used for
                                                           many purposes
Extending the grammar

                                                                                       s --> np, vp.
                                                       •  This is the simple grammar
                                                          from the previous lecture    np --> det, n.
                                                                                       vp --> v, np.
                                                       •  Suppose we also want to
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                                                       vp --> v.
                                                          deal with sentences
                                                                                       det --> [the].
                                                          containing pronouns such
                                                                                       det --> [a].
                                                          as
                                                                                       n --> [woman].
                                                              she shoots him
                                                                                       n --> [man].
                                                          and
                                                              he shoots her            v --> [shoots].
                                                       •  What do we need to do?
Extending the grammar
                                                                                        s --> np, vp.
                                                       •  Add rules for pronouns        np --> det, n.
                                                       •  Add a rule saying that noun   np --> pro.
                                                          phrases can be pronouns       vp --> v, np.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




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




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




                                                                                        vp --> v.
                                                       ?- s([her,shoots,a,man],[ ]).
                                                                                        det --> [the].
                                                       yes
                                                                                        det --> [a].
                                                       s([her,shoots,she],[ ]).
                                                                                        n --> [woman].
                                                       yes
                                                                                        n --> [man].
                                                                                        v --> [shoots].
                                                                                        pro --> [he].
                                                                                        pro --> [she].
                                                                                        pro --> [him].
                                                                                        pro --> [her].
What is going wrong?

                                                       •  The DCG ignores some basic facts
                                                          about English
                                                         – she and he are subject pronouns and
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                           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?
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.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




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




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




                                                       vp --> v.                 ?- s([she,shoots,he],[ ]).
                                                       det --> [the].            no
                                                       det --> [a].              ?-
                                                       n --> [woman].
                                                       n --> [man].
                                                       v --> [shoots].
                                                       pro(subject) --> [he].
                                                       pro(subject) --> [she].
                                                       pro(object) --> [him].
                                                       pro(object) --> [her].
What is really going on?

                                                       •  Recall that the rule:
                                                               s --> np,vp.
                                                          is really syntactic sugar for:
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                               s(A,B):- np(A,C), vp(C,B).
What is really going on?

                                                       •  Recall that the rule:
                                                               s --> np,vp.
                                                          is really syntactic sugar for:
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                               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).
Listing noun phrases
                                                       s --> np(subject), vp.    ?- np(Type, NP, [ ]).
                                                       np(_) --> det, n.         Type =_
                                                       np(X) --> pro(X).         NP = [the,woman];
                                                       vp --> v, np(object).
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                       vp --> v.                 Type =_
                                                       det --> [the].            NP = [the,man];
                                                       det --> [a].
                                                       n --> [woman].            Type =_
                                                       n --> [man].              NP = [a,woman];
                                                       v --> [shoots].
                                                       pro(subject) --> [he].    Type =_
                                                       pro(subject) --> [she].   NP = [a,man];
                                                       pro(object) --> [him].
                                                       pro(object) --> [her].    Type =subject
                                                                                 NP = [he]
Building parse trees

                                                       •  The programs we have discussed so
                                                          far have been able to recognise
                                                          grammatical structure of sentences
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                       •  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
Parse tree example

                                                                      s

                                                                              vp
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                             np                          np

                                                       det        n       v        det        n

                                                       the woman shoots            a      man
Parse tree in Prolog
                                                                          s(np(det(the),n(woman)),
                                                                      s
                                                                             vp(v(shoots),np(det(a),n(man)))))

                                                                              vp
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                             np                          np

                                                       det        n       v        det        n

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




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




                                                       vp --> v.                 vp(vp(V)) --> v(V)).
                                                       det --> [the].            det(det(the)) --> [the].
                                                       det --> [a].              det(det(a)) --> [a].
                                                       n --> [woman].            n(n(woman)) --> [woman].
                                                       n --> [man].              n(n(man)) --> [man].
                                                       v --> [shoots].           v(v(shoots)) --> [shoots].
                                                       pro(subject) --> [he].    pro(subject,pro(he)) --> [he].
                                                       pro(subject) --> [she].   pro(subject,pro(she)) --> [she].
                                                       pro(object) --> [him].    pro(object,pro(him)) --> [him].
                                                       pro(object) --> [her].    pro(object,pro(her)) --> [her].
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).
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




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




                                                                          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].
Beyond context free languages

                                                       •  In the previous lecture we presented
                                                          DCGs as a useful tool for working with
                                                          context free grammars
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                       •  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 anbncn{ε}
An example

                                                       •  The language anbncn{ε} consists of
                                                          strings such as abc, aabbcc,
                                                          aaabbbccc, aaaabbbbcccc, and so on
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                       •  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
DCG for anbncn{ε}

                                                       s(Count) --> as(Count), bc(Count), cs(Count).

                                                       as(0) --> [].
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                       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




                                                       •  LPN 8.1
                                                                    Exercises
Extra goals

                                                       •  Any DCG rule is really syntactic
                                                          structure for ordinary Prolog rule
                                                       •  So it is not really surprising we can also
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                          call any Prolog predicate from the right-
                                                          hand side of a DCG rule
                                                       •  This is done by using curly brackets { }
Example: DCG for anbncn{ε}
                                                       s(Count) --> as(Count), bc(Count), cs(Count).

                                                       as(0) --> [].
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                       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}.
Separating rules and lexicon

                                                       •  One classic application of the extra
                                                          goals of DCGs in computational
                                                          linguistics is separating the grammar
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                          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
The basic grammar
                                                       s --> np, vp.

                                                       np --> det, n.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                       vp --> v, np.
                                                       vp --> v.

                                                       det --> [the].
                                                       det --> [a].

                                                       n --> [woman].
                                                       n --> [man].

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




                                                       vp --> v, np.                                                lex(woman, n).
                                                                             vp --> v, np.
                                                       vp --> v.                                                    lex(man,    n).
                                                                             vp --> v.
                                                                                                                   lex(shoots, v).
                                                                                                                +
                                                       det --> [the].
                                                                             det --> [Word], {lex(Word,det)}.
                                                       det --> [a].

                                                                             n --> [Word], {lex(Word,n)}.
                                                       n --> [woman].
                                                       n --> [man].
                                                                             v --> [Word], {lex(Word,v)}.
                                                       v --> [shoots].
Concluding Remarks

                                                       •  DCGs are a simple tool for encoding context
                                                          free grammars
                                                       •  But in fact DCGs are a full-fledged
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                          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
Next lecture

                                                       •  A closer look at terms
                                                         – Introduce the identity predicate
                                                         – Take a closer look at term structure
© Patrick Blackburn, Johan Bos & Kristina Striegnitz




                                                         – Introduce pre-defined Prolog predicates
                                                           that test whether a given term is of a
                                                           certain type
                                                         – Show how to define new operators in
                                                           Prolog

More Related Content

More from CS, NcState

Lexisnexis june9
Lexisnexis june9Lexisnexis june9
Lexisnexis june9
CS, NcState
 
Ai4se lab template
Ai4se lab templateAi4se lab template
Ai4se lab template
CS, NcState
 
Automated Software Enging, Fall 2015, NCSU
Automated Software Enging, Fall 2015, NCSUAutomated Software Enging, Fall 2015, NCSU
Automated Software Enging, Fall 2015, NCSU
CS, NcState
 
Dagstuhl14 intro-v1
Dagstuhl14 intro-v1Dagstuhl14 intro-v1
Dagstuhl14 intro-v1
CS, NcState
 

More from CS, NcState (20)

Talks2015 novdec
Talks2015 novdecTalks2015 novdec
Talks2015 novdec
 
Future se oct15
Future se oct15Future se oct15
Future se oct15
 
GALE: Geometric active learning for Search-Based Software Engineering
GALE: Geometric active learning for Search-Based Software EngineeringGALE: Geometric active learning for Search-Based Software Engineering
GALE: Geometric active learning for Search-Based Software Engineering
 
Big Data: the weakest link
Big Data: the weakest linkBig Data: the weakest link
Big Data: the weakest link
 
Three Laws of Trusted Data Sharing: (Building a Better Business Case for Dat...
Three Laws of Trusted Data Sharing:(Building a Better Business Case for Dat...Three Laws of Trusted Data Sharing:(Building a Better Business Case for Dat...
Three Laws of Trusted Data Sharing: (Building a Better Business Case for Dat...
 
Lexisnexis june9
Lexisnexis june9Lexisnexis june9
Lexisnexis june9
 
Welcome to ICSE NIER’15 (new ideas and emerging results).
Welcome to ICSE NIER’15 (new ideas and emerging results).Welcome to ICSE NIER’15 (new ideas and emerging results).
Welcome to ICSE NIER’15 (new ideas and emerging results).
 
Icse15 Tech-briefing Data Science
Icse15 Tech-briefing Data ScienceIcse15 Tech-briefing Data Science
Icse15 Tech-briefing Data Science
 
Kits to Find the Bits that Fits
Kits to Find  the Bits that Fits Kits to Find  the Bits that Fits
Kits to Find the Bits that Fits
 
Ai4se lab template
Ai4se lab templateAi4se lab template
Ai4se lab template
 
Automated Software Enging, Fall 2015, NCSU
Automated Software Enging, Fall 2015, NCSUAutomated Software Enging, Fall 2015, NCSU
Automated Software Enging, Fall 2015, NCSU
 
Requirements Engineering
Requirements EngineeringRequirements Engineering
Requirements Engineering
 
172529main ken and_tim_software_assurance_research_at_west_virginia
172529main ken and_tim_software_assurance_research_at_west_virginia172529main ken and_tim_software_assurance_research_at_west_virginia
172529main ken and_tim_software_assurance_research_at_west_virginia
 
Automated Software Engineering
Automated Software EngineeringAutomated Software Engineering
Automated Software Engineering
 
Next Generation “Treatment Learning” (finding the diamonds in the dust)
Next Generation “Treatment Learning” (finding the diamonds in the dust)Next Generation “Treatment Learning” (finding the diamonds in the dust)
Next Generation “Treatment Learning” (finding the diamonds in the dust)
 
Tim Menzies, directions in Data Science
Tim Menzies, directions in Data ScienceTim Menzies, directions in Data Science
Tim Menzies, directions in Data Science
 
Goldrush
GoldrushGoldrush
Goldrush
 
Dagstuhl14 intro-v1
Dagstuhl14 intro-v1Dagstuhl14 intro-v1
Dagstuhl14 intro-v1
 
Know thy tools
Know thy toolsKnow thy tools
Know thy tools
 
The Art and Science of Analyzing Software Data
The Art and Science of Analyzing Software DataThe Art and Science of Analyzing Software Data
The Art and Science of Analyzing Software Data
 

Recently uploaded

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 

Recently uploaded (20)

Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptx
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Forest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFForest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDF
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 

Lecture 8: More DCGs

  • 1. Lecture 8: More DCGs •  Theory – Examine two important capabilities offered by DCG notation: © Patrick Blackburn, Johan Bos & Kristina Striegnitz •  Extra arguments •  Extra tests – Discuss the status and limitations of DCGs •  Exercises – Exercises of LPN: 8.1, 8.2 – Practical session
  • 2. Extra arguments •  In the previous lecture we introduced basic DCG notation •  But DCGs offer more than we have seen © Patrick Blackburn, Johan Bos & Kristina Striegnitz so far – DCGs allow us to specify extra arguments – These extra arguments can be used for many purposes
  • 3. Extending the grammar s --> np, vp. •  This is the simple grammar from the previous lecture np --> det, n. vp --> v, np. •  Suppose we also want to © Patrick Blackburn, Johan Bos & Kristina Striegnitz vp --> v. deal with sentences det --> [the]. containing pronouns such det --> [a]. as n --> [woman]. she shoots him n --> [man]. and he shoots her v --> [shoots]. •  What do we need to do?
  • 4. Extending the grammar s --> np, vp. •  Add rules for pronouns np --> det, n. •  Add a rule saying that noun np --> pro. phrases can be pronouns vp --> v, np. © Patrick Blackburn, Johan Bos & Kristina Striegnitz vp --> v. det --> [the]. •  Is this new DCG any good? det --> [a]. n --> [woman]. •  What is the problem? n --> [man]. v --> [shoots]. pro --> [he]. pro --> [she]. pro --> [him]. pro --> [her].
  • 5. Some examples of grammatical strings accepted by this DCG s --> np, vp. np --> det, n. np --> pro. ?- s([she,shoots,him],[ ]). vp --> v, np. yes © Patrick Blackburn, Johan Bos & Kristina Striegnitz vp --> v. ?- s([a,woman,shoots,him],[ ]). det --> [the]. yes det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. pro --> [he]. pro --> [she]. pro --> [him]. pro --> [her].
  • 6. Some examples of ungrammatical strings accepted by this DCG s --> np, vp. np --> det, n. np --> pro. ?- s([a,woman,shoots,he],[ ]). vp --> v, np. yes © Patrick Blackburn, Johan Bos & Kristina Striegnitz vp --> v. ?- s([her,shoots,a,man],[ ]). det --> [the]. yes det --> [a]. s([her,shoots,she],[ ]). n --> [woman]. yes n --> [man]. v --> [shoots]. pro --> [he]. pro --> [she]. pro --> [him]. pro --> [her].
  • 7. What is going wrong? •  The DCG ignores some basic facts about English – she and he are subject pronouns and © Patrick Blackburn, Johan Bos & Kristina Striegnitz 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?
  • 8. 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. © Patrick Blackburn, Johan Bos & Kristina Striegnitz vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. pro_subject --> [he]. pro_subject --> [she]. pro_object --> [him]. pro_object --> [her].
  • 9. Nice way using extra arguments s --> np(subject), vp. np(_) --> det, n. np(X) --> pro(X). vp --> v, np(object). © Patrick Blackburn, Johan Bos & Kristina Striegnitz vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. pro(subject) --> [he]. pro(subject) --> [she]. pro(object) --> [him]. pro(object) --> [her].
  • 10. This works… s --> np(subject), vp. np(_) --> det, n. np(X) --> pro(X). ?- s([she,shoots,him],[ ]). vp --> v, np(object). yes © Patrick Blackburn, Johan Bos & Kristina Striegnitz vp --> v. ?- s([she,shoots,he],[ ]). det --> [the]. no det --> [a]. ?- n --> [woman]. n --> [man]. v --> [shoots]. pro(subject) --> [he]. pro(subject) --> [she]. pro(object) --> [him]. pro(object) --> [her].
  • 11. What is really going on? •  Recall that the rule: s --> np,vp. is really syntactic sugar for: © Patrick Blackburn, Johan Bos & Kristina Striegnitz s(A,B):- np(A,C), vp(C,B).
  • 12. What is really going on? •  Recall that the rule: s --> np,vp. is really syntactic sugar for: © Patrick Blackburn, Johan Bos & Kristina Striegnitz 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).
  • 13. Listing noun phrases s --> np(subject), vp. ?- np(Type, NP, [ ]). np(_) --> det, n. Type =_ np(X) --> pro(X). NP = [the,woman]; vp --> v, np(object). © Patrick Blackburn, Johan Bos & Kristina Striegnitz vp --> v. Type =_ det --> [the]. NP = [the,man]; det --> [a]. n --> [woman]. Type =_ n --> [man]. NP = [a,woman]; v --> [shoots]. pro(subject) --> [he]. Type =_ pro(subject) --> [she]. NP = [a,man]; pro(object) --> [him]. pro(object) --> [her]. Type =subject NP = [he]
  • 14. Building parse trees •  The programs we have discussed so far have been able to recognise grammatical structure of sentences © Patrick Blackburn, Johan Bos & Kristina Striegnitz •  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
  • 15. Parse tree example s vp © Patrick Blackburn, Johan Bos & Kristina Striegnitz np np det n v det n the woman shoots a man
  • 16. Parse tree in Prolog s(np(det(the),n(woman)), s vp(v(shoots),np(det(a),n(man))))) vp © Patrick Blackburn, Johan Bos & Kristina Striegnitz np np det n v det n the woman shoots a man
  • 17. DCG that builds parse tree s --> np(subject), vp. np(_) --> det, n. np(X) --> pro(X). vp --> v, np(object). © Patrick Blackburn, Johan Bos & Kristina Striegnitz vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots]. pro(subject) --> [he]. pro(subject) --> [she]. pro(object) --> [him]. pro(object) --> [her].
  • 18. DCG that builds parse tree s --> np(subject), vp. s(s(NP,VP)) --> np(subject,NP), vp(VP). np(_) --> det, n. np(_,np(Det,N)) --> det(Det), n(N). np(X) --> pro(X). np(X,np(Pro)) --> pro(X,Pro). vp --> v, np(object). vp(vp(V,NP)) --> v(V), np(object,NP). © Patrick Blackburn, Johan Bos & Kristina Striegnitz vp --> v. vp(vp(V)) --> v(V)). det --> [the]. det(det(the)) --> [the]. det --> [a]. det(det(a)) --> [a]. n --> [woman]. n(n(woman)) --> [woman]. n --> [man]. n(n(man)) --> [man]. v --> [shoots]. v(v(shoots)) --> [shoots]. pro(subject) --> [he]. pro(subject,pro(he)) --> [he]. pro(subject) --> [she]. pro(subject,pro(she)) --> [she]. pro(object) --> [him]. pro(object,pro(him)) --> [him]. pro(object) --> [her]. pro(object,pro(her)) --> [her].
  • 19. 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). © Patrick Blackburn, Johan Bos & Kristina Striegnitz vp(vp(V)) --> v(V)). det(det(the)) --> [the]. det(det(a)) --> [a]. ?- s(T,[he,shoots],[]). n(n(woman)) --> [woman]. T = s(np(pro(he)),vp(v(shoots))) n(n(man)) --> [man]. yes v(v(shoots)) --> [shoots]. pro(subject,pro(he)) --> [he]. pro(subject,pro(she)) --> [she]. pro(object,pro(him)) --> [him]. pro(object,pro(her)) --> [her].
  • 20. Generating parse trees s(s(NP,VP)) --> np(subject,NP), vp(VP). np(_,np(Det,N)) --> det(Det), n(N). ?- s(Tree,S,[]). np(X,np(Pro)) --> pro(X,Pro). vp(vp(V,NP)) --> v(V), np(object,NP). © Patrick Blackburn, Johan Bos & Kristina Striegnitz 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].
  • 21. Beyond context free languages •  In the previous lecture we presented DCGs as a useful tool for working with context free grammars © Patrick Blackburn, Johan Bos & Kristina Striegnitz •  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 anbncn{ε}
  • 22. An example •  The language anbncn{ε} consists of strings such as abc, aabbcc, aaabbbccc, aaaabbbbcccc, and so on © Patrick Blackburn, Johan Bos & Kristina Striegnitz •  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
  • 23. DCG for anbncn{ε} s(Count) --> as(Count), bc(Count), cs(Count). as(0) --> []. © Patrick Blackburn, Johan Bos & Kristina Striegnitz as(succ(Count)) --> [a], as(Count). bs(0) --> []. bs(succ(Count)) --> [b], bs(Count). cs(0) --> []. cs(succ(Count)) --> [c], cs(Count).
  • 24. © Patrick Blackburn, Johan Bos & Kristina Striegnitz •  LPN 8.1 Exercises
  • 25. Extra goals •  Any DCG rule is really syntactic structure for ordinary Prolog rule •  So it is not really surprising we can also © Patrick Blackburn, Johan Bos & Kristina Striegnitz call any Prolog predicate from the right- hand side of a DCG rule •  This is done by using curly brackets { }
  • 26. Example: DCG for anbncn{ε} s(Count) --> as(Count), bc(Count), cs(Count). as(0) --> []. © Patrick Blackburn, Johan Bos & Kristina Striegnitz 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}.
  • 27. Separating rules and lexicon •  One classic application of the extra goals of DCGs in computational linguistics is separating the grammar © Patrick Blackburn, Johan Bos & Kristina Striegnitz 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
  • 28. The basic grammar s --> np, vp. np --> det, n. © Patrick Blackburn, Johan Bos & Kristina Striegnitz vp --> v, np. vp --> v. det --> [the]. det --> [a]. n --> [woman]. n --> [man]. v --> [shoots].
  • 29. The modular grammar s --> np, vp. s --> np, vp. np --> det, n. lex(the, det). np --> det, n. lex(a, det). © Patrick Blackburn, Johan Bos & Kristina Striegnitz vp --> v, np. lex(woman, n). vp --> v, np. vp --> v. lex(man, n). vp --> v.  lex(shoots, v). + det --> [the]. det --> [Word], {lex(Word,det)}. det --> [a]. n --> [Word], {lex(Word,n)}. n --> [woman]. n --> [man]. v --> [Word], {lex(Word,v)}. v --> [shoots].
  • 30. Concluding Remarks •  DCGs are a simple tool for encoding context free grammars •  But in fact DCGs are a full-fledged © Patrick Blackburn, Johan Bos & Kristina Striegnitz 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
  • 31. Next lecture •  A closer look at terms – Introduce the identity predicate – Take a closer look at term structure © Patrick Blackburn, Johan Bos & Kristina Striegnitz – Introduce pre-defined Prolog predicates that test whether a given term is of a certain type – Show how to define new operators in Prolog