1 / 15

LING 388: Language and Computers

LING 388: Language and Computers. Sandiway Fong 9/ 17 Lecture 7. Last Time. Prolog term notation: functor (argument 1 ,..,argument n ) functor must be a symbol arguments can be simple terms or (recursive) complex terms We will use Prolog terms to represent parse trees: Example:

yetty
Download Presentation

LING 388: Language and Computers

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. LING 388: Language and Computers Sandiway Fong 9/17 Lecture 7

  2. Last Time • Prolog term notation: • functor(argument1,..,argumentn) • functor must be a symbol • arguments can be simple terms or (recursive) complex terms • We will use Prolog terms to represent parse trees: • Example: s(np(prp(i),vp(vbd(saw),np(dt(the),nn(boy)),pp(in(with),np(dt(a),nn(telescope)))))

  3. Last Time Homework 2

  4. Administrivia • Homework 2 is designed to test your understanding of the Prolog term data structure • due Thursday night!

  5. 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)))

  6. observation ?- trace. we can step through the derivation but it disappears after computation is finished would be nice to keep a parse tree around Programming technique add one argument (parameter) to each non-terminal of each grammar rule to hold the part of the parse tree it computes 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 tree Computing Parse Trees

  7. Computing Parse Trees • use a recursive Prolog data structure to represent a parse • examples • data structure:verb(took) • functor = verb • argument = took • data structure:det(the) • functor = det • argument = the • data structure:np(det(the),man) • functor = np • 1st argument = det(the) • functor = det • argument = the • 2nd argument = man (1) verb | took (2) det | the (3) np / \ det man | the

  8. Computing Parse Trees • original DCG • sentence --> np, vp. • vp --> verb, np. • verb --> [took]. • np --> det, [man]. • np --> det, [book]. • det --> [the]. • 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].

  9. 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)))

  10. 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))) ? ; • no • query • what 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 ? ; • no

  11. 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] ? ; • no • query • supply 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] ? ; • no

  12. Printing of Answers • http://www.swi-prolog.org/FAQ/AllOutput.html

  13. Printing of Answers

  14. Printing of Answers

  15. Exercise • Construct a grammar that produces parsetree representationsfor: • I saw the boy with a telescope (2 parses) • the boy with a telescope saw me (1 parse) • remember: your grammar should allow for PP attachment to VP or NP • let’s use lowercase i to represent the first person pronoun (I) to sidestep problems with variables vs. symbols in SWI Prolog

More Related