1 / 13

LING 388: Language and Computers

LING 388: Language and Computers. Sandiway Fong Lecture 8: 9/20. Administrivia. LING 388 Homework #2 handed out today submit homework by email sandiway@email.arizona.edu due date is one week from now Monday September 27th (by midnight) Next time Back in classroom.

kamea
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 Lecture 8: 9/20

  2. Administrivia • LING 388 Homework #2 • handed out today • submit homework by email • sandiway@email.arizona.edu • due date is one week from now • Monday September 27th (by midnight) • Next time • Back in classroom

  3. SWI-Prolog Cheatsheet • How to start it? • from the Windows Program menu • How to see what’s in the database? • ?- listing. • How to see what the current working directory is? • ?- working_directory(X,Y). • X: current working directory, Y: new working directory • How to change to a new working directory? • ?- working_directory(X,NEW). • How to turn on tracing mode for the Prolog debugger? • ?- trace. • How to turn off Prolog debugger? • ?- nodebug. • How to see non-abbreviated results? (…) • ?- set_prolog_flag(toplevel_print_options,[max_depth(0)]).

  4. a s x a b y b Exercise 1: FSA L = {a+b+}

  5. Exercise 1: FSA • FSA machine for L = {a+b+} • state s: • s([a|L]) :- x(L). match input string beginning with a and call state x with remainder of input • State x: • x([a|L]) :- x(L). • x([b|L]) :- y(L). • state y: • y([]). % end state • y([b|L]) :- y(L). • Enter this machine into the database and trace machine on queries: • ?-s([a,a,b,b]). Yes • ?- s([a,b,a]). No • ?- s([a,X]). X = b

  6. Exercise 1: FSA • Homework Question (A): (2pts) • What and how many answers does the query ?- s([X,Y,Z]). return? • Homework Question (B): (2pts) • If the rule x([a|L]) :- x(L). is removed from the program, what language does the revised FSA accept?

  7. s b w a x a b y a ! z Exercise 2: FSA • Homework Question 2 (4pts) • Implement the FSA shown below for Sheeptalk (baa! baaa! baaaa! …) • Show the machine accepts strings • baa! baaaa! • Show the machine rejects strings • ba! baa baba! • Submit both the program • and your output

  8. Exercise 3: Regular Grammars • A regular grammar for the man I saw: • dp --> [the], np. • np --> [man], relc. • relc --> [that], sorel. • sorel --> [i], vporel. % object relative sentence • vporel --> [saw]. • Verify rules work using query: • ?- dp([the,man,that,i,saw],[]). Yes • Add regular grammar rules to handle • the man that you saw • the man that you met

  9. Exercise 3: Regular Grammars • Homework Question A (4pts) • Modify regular grammar to accept recursive embeddings of the form • the man that I saw that you heard • the man that you heard that I saw • Submit both your grammar and the output • Note: make sure your grammar is still regular • Hint: it may be useful to draw the equivalent FSA

  10. Exercise 3: Regular Grammars • Homework Question B (2pts) • Modify regular grammar to allow the option of dropping the relative pronoun that, e.g. • the man that I saw • the man I saw • Submit both your grammar and the output • Note: make sure your grammar is still regular

  11. A a B b Exercise 4: Beyond Regular Grammars • In Lecture 7, we mentioned • anbn is not a regular language • And that a grammar with both left and right recursive rules can accept it • a --> [a], b. • b --> [b]. • b --> a, [b]. • Verify that this grammar accepts • aabb aaaabbbb • and rejects • aab aaaabbbbb A a B A b

  12. Exercise 4: Beyond Regular Grammars • Extra Credit Homework Question (5pts) • write a similar grammar for the non-regular language • wwR • where w  {a,b}+, i.e. any non-empty sequence of a’s and b’s, and • wR is w in reverse order • Examples: • aabbaa w = aab wR = baa • aaaa w = aa wR = aa • *aaaaa • *abab

  13. Homework Summary • 14 pts on offer • Exercise 1 (4pts) • Exercise 2 (4pts) • Exercise 3 (6pts) • Extra Credit • Exercise 4 (5pts)

More Related