/
LING 388: Language and Computers LING 388: Language and Computers

LING 388: Language and Computers - PowerPoint Presentation

kittie-lecroy
kittie-lecroy . @kittie-lecroy
Follow
402 views
Uploaded On 2015-09-20

LING 388: Language and Computers - PPT Presentation

Sandiway Fong Lecture 9 Administrivia Reminder Homework 3 due Wednesday night Have questions TA Ben Martin is here to help Computing Parse Trees Getting Prolog to build a representation of the parse ID: 134333

man det parse book det man book parse sentence verb trees computing prolog argument query tree grammar structure functor terminal rule parses

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "LING 388: Language and Computers" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

LING 388: Language and Computers

Sandiway

Fong

Lecture

9Slide2

Administrivia

Reminder

Homework 3 due Wednesday night…

Have questions? TA Ben Martin is here to help…Slide3

Computing Parse Trees

Getting Prolog to build a representation of the parse

tree

[S [NP [

Det

the] man][VP [V took][NP [Det the] book]]]sentence(np(det(the),man),vp(verb(took),np(det(the),book)))Slide4

Computing Parse Trees

Programming technique:

add one argument

(a Prolog term)

to each non-terminal

on the left-hand-side of each grammar rule to hold the part of the parse tree it computesadd one argument (a variable) to each non-terminal on the right-hand-side of each grammar rulethe variable stores the value of the subtree computed for the non-terminale.g.s --> np, vp.s(s(NP,VP)) --> np

(NP),

vp

(VP).

NB. variable naming is not strict:

s(s

(X,Y)

) -->

np

(X)

,

vp

(Y).

Rule of compositionality

: rules combine sub-phrases into larger phrases

we

will combine sub-trees to form larger

trees, eventually

resulting in the complete parse

treeSlide5

Computing Parse Trees

use a recursive Prolog data structure to represent a parse

examples

data structure:

verb(took)functor = verbargument = tookdata structure: det(the)functor = detargument = the

data structure:

np(det(the),man)

functor =

np1st argument = det(the)functor = detargument = the2nd argument = man

(1)verb |took

(2)det |the

(3)

np

/ \

det man

|

theSlide6

Computing Parse Trees

original DCG

sentence --> np, vp.

vp --> verb, np.

verb --> [took].

np --> det, [man].np --> det, [book].det --> [the]. revised DCGsentence(s(NP,VP)) --> np(NP), vp(VP).vp(vp(V,NP)) --> verb(V), np(NP).verb(v(took)) --> [took].np(np(D,man)) --> det(D), [man].np(np(D,book)) --> det(D), [book].

det(det(the)) --> [the]. Slide7

Computing Parse Trees

revised DCG

sentence(s(NP,VP)) --> np(NP), vp(VP).

vp(vp(V,NP)) --> verb(V), np(NP).

verb(v(took)) --> [took].

np(np(D,man)) --> det(D), [man].np(np(D,book)) --> det(D), [book].det(det(the)) --> [the]. query (with an extra argument)?- sentence(P,List,[]).

P =

parse tree

List =

sentence

s(np(det(the),man),vp(v(took),np(det(the),man)))Slide8

Examples

query

what parse P corresponds to the sentence “the man took the book”?

?-

sentence(P,[the,man,took,the,book],[]).

P = s(np(det(the),man),vp(v(took),np(det(the),book))) ? ;noquerywhat are the possible parses P and word X for the sentence “the man took the X”??- sentence(P,[the,man,took,the,X],[]).P = s(np(det(the),man),vp(v(took),np(det(the),man))),X = man ? ;P = s(np(det(the),man),vp(v(took),np(det(the),book))),

X = book ?

;

noSlide9

Examples

query

given a parse, what is the corresponding Sentence?

?-

sentence(s(np(det(the),man),vp(v(took),np(det(the),book))),Sentence,[]).

Sentence = [the,man,took,the,book] ? ;noquerysupply no information, i.e. Parse and Sentence are both variables, what are the possible sentences and parses??- sentence(Parse,Sentence,[]).Parse = s(np(det(the),man),vp(v(took),np(det(the),man))),Sentence = [the,man,took,the,man] ? ;Parse = s(np(det(the),man),vp(v(took),np(det(the),book))),

Sentence = [the,man,took,the,book] ?

;

Parse = s(np(det(the),book),vp(v(took),np(det(the),man))),

Sentence = [the,book,took,the,man] ?

;Parse = s(np(det(the),book),vp(v(took),np(det(the),book))),Sentence = [the,book,took,the,book] ? ;noSlide10

Printing of Answers

http://www.swi-prolog.org/FAQ/AllOutput.htmlSlide11

Worked Exercise

Let's c

onstruct

a grammar that produces parse

tree representations for: I saw the boy with a telescope (2 parses)the boy with a telescope saw me (1 parse)remember: our grammar should allow for PP attachment to VP and NPnote: let’s use lowercase i to represent the first person pronoun (I) to sidestep problems with variables vs. symbols in SWI Prolog