1 / 37

LING/C SC/PSYC 438/538

LING/C SC/PSYC 438/538. Lecture 15 Sandiway Fong. Administrivia. Next time, we’ll start on Chapter 3 of JM: Morphology and Finite State Transducers Reminder : next Monday Guest Lecture #2 Title:

Télécharger la présentation

LING/C SC/PSYC 438/538

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/C SC/PSYC 438/538 Lecture 15 Sandiway Fong

  2. Administrivia • Next time, we’ll start on • Chapter 3 of JM: Morphology and Finite State Transducers • Reminder: • next Monday • Guest Lecture #2 • Title: • A Pseudo-Deterministic Model of Human Language Processing with a Computational Implementation • Author: • Dr. Jerry Ball, Army Research Labs., Mesa AZ

  3. Today’s Topics • Homework 3 review • Midterm review

  4. Homework 3 Review

  5. Homework 3 Review • Consider the language L given by • L = a*b* ∪ (ab)* We can express this as: • L = L1∪ L2 • L1 = a*b* • L2 = (ab)* • Question 1 (438/538) 15 points • Part 1 • Give a regular grammar for L1 in Prolog • Part 2 • Give a regular grammar for L2 in Prolog • Part 3 • Give a regular grammar for L (=L1∪ L2) in Prolog • Instruction: • In each case show your program and sample output

  6. Homework 3 Review • Question 1 • Part 1 • L1 = a*b* • Give a regular grammar for L1 in Prolog • Show sample output • Grammar: • s --> []. • s--> [a], s. • s --> [b], b. • b --> []. • b --> [b], b. empty a+… b’s only

  7. Homework 3 Review • Grammar: • s --> []. • s --> [a], s. • s --> [b], b. • b --> []. • b --> [b], b. Note: doesn’t enumerate well: has two loops

  8. Homework 3 Review • Question 1 • Part 2 • L2 = (ab)* • Give a regular grammar for L2 in Prolog • Grammar: • s --> []. • s--> [a], c. • c--> [b], s. empty (ab)+ This grammar enumerates well

  9. Homework 3 Review • Question 1 • Part 3 • L1 = a*b* • L2 = (ab)* • Give a regular grammar for L (=L1∪ L2) in Prolog • Languages are sets • Therefore ∪ here refers to set union • i.e. the task is to give a grammar that generates strings either belonging to L1 or L2.

  10. Homework 3 Review Note: • You can’t just simply paste the two grammars given together • Otherwise you’d accept strings like abaabb (which doesn’t belong to either a*b* or (ab)*)

  11. Homework 3 Review • Idea: view it as running both grammars in parallel • (an analog of the set-of-states construction) • L1 • s --> []. • s --> [a], s. • s --> [b], b. • b --> []. • b --> [b], b. • L2 • s --> []. • s --> [a], c. • c --> [b], s. • L = L1∪ L2 • % on no input • ss --> []. • % on input [a|..] • ss--> [a], s1c. • % on input [b|..] • ss--> [b], b. • s1c --> []. • s1c --> [a], s1. • s1c --> [b], bs2. [powerpoint animation] Or you could build two FSAs corresponding to the two regular grammars and convert them to a single deterministic FSA, and then convert that DFSA back into a regular grammar

  12. Homework 3 Review • Grammar (g.pl) • ss --> []. • ss --> [a], s1c. • ss--> [b], b. • s1c --> []. • s1c --> [a], s1. • s1c --> [b], bs2. • bs2 --> []. • bs2 --> [a], c. • bs2 --> [b], b. s1 --> []. s1 --> [a], s1. s1 --> [b], b. b --> []. b --> [b], b. c--> [b], s2. s2 --> []. s2 --> [a], c. Original rules renamed

  13. Homework 3 Review

  14. Homework 3 Review • Diagram and Perl program • Question 2 • Give a FSA for L • L = L1∪ L2 • L1 = a*b* • L2 = (ab)* • L1 = a*b* a b 1 2 > b a • L2 = (ab)* > 3 4 b

  15. Homework 3 Review • L1 = a*b* • Set of states: [powerpoint animation] a b 1,3 1,4 > 1 2 > b b a a a a b 1 b 2,3 2 a • L2 = (ab)* b a b > 3 4 3 4 b b

  16. Homework 3 Review • Deterministic FSA • Perl hash table %transitiontable = ( 13 => { a => 14, b => 2 }, 14 => { a => 1, b => 23 }, 1 => { a => 1, b => 2 }, 2 => { b => 2 }, 23 => { a => 4, b => 2 }, 4 => { b => 3 }, 3 => { a => 4 } ); 1,3 1,4 > @input = @ARGV; $state = 13; foreach $c (@input) { $state = $transitiontable{$state}{$c}; } if ($state != 4 & $state ne "") { print "<$state> Accept\n"; } else { print "<$state> Reject\n"; } a a a b b 1 2,3 b 2 a a b b 3 4 b

  17. Homework 3 Review • Deterministic FSA 1,3 1,4 > a a a b b 1 2,3 b 2 a a b b 3 4 b

  18. Homework 3 Review • Question 5 (for 538) • Give a left linear (recursive) regular grammar for L1 • L1 = a*b* • Grammar: • s --> []. • s --> [a]. • s --> [b]. • s --> s, [b]. • s --> a, [b]. • s --> a, [a]. • a --> [a]. • a --> a, [a]. Fails to halt even on some strings in the language

  19. Homework 3 Review • Question 3 • (538 obligatory, 438 extra credit) • Give a FSA that accepts strings of a’s and b’s (in any order) such that the total number of a’s in the string must be even and the total number of b’s in string must be odd e.g. • aabbaababa • *b*ab*aabbbb*aa

  20. Homework 3 Review • Question 3 • total number of a’s: even (i.e. 2,4,6,8…) • total number ofb’s: odd (i.e. 1,3,5,7…) • Basic idea: • Use a feature even/odd to keep track of the number of occurrences • Only need two states per symbol from the alphabet • Example: even odd a > a

  21. Homework 3 Review • Question 3 • total number of a’s: even (i.e. 2,4,6,8…) • total number of b’s: odd (i.e. 1,3,5,7…) • Basic idea: • For a two symbol alphabet • Use two distinct even/odd features a even b even a odd b even a > [powerpoint animation] a b b b b a even b odd a odd b odd a a

  22. Homework 3 Review • Question 3 • total number of a’s: even (i.e. 2,4,6,8…) • total number of b’s: odd (i.e. 1,3,5,7…) • Complication: • Must make sure total number of a‘s reaches two a even b even a odd b even a > a Let even* = even + 0 b b b b a even b odd a even b odd a odd b odd a a

  23. Homework 3 Review • Question 3 • total number of a’s: even (i.e. 2,4,6,8…) • total number of b’s: odd (i.e. 1,3,5,7…) • Complication: • Must make sure total number of a‘s reaches two a even beven* a odd beven* a zero beven* a one beven* a a a > a a b b b b b b b b a even b odd a zero b odd a odd b odd a one b odd a a a a

  24. Midterm Review

  25. Question 1 • Alphabet = {(,)} (set of left and right parentheses) • Language L = set of all non-empty strings with properly balanced parentheses, i.e. each left parenthesis has a properly-nested corresponding right parenthesis • Examples: • () *)( • ()()() *()(() • (()())((())()) • Give a context-free grammar for L (grammar rules in either Prolog or non-Prolog format are acceptable)

  26. Question 1 • Note: have to quote round brackets in Prolog… • Prolog-style: s --> [‘(‘,’)’]. • … and so on • Non-Prolog-style (ambiguous CF grammar): • S  () • S  ( S ) • S  S S

  27. Question 2 • A grammar is ambiguous if there are two (or more) separate ways to derive the (same) string using the rules • Consider regular grammar G below Start symbol: a, alphabet = {0,1} • a --> [1], b. • b --> [0], b. • b --> [0], c. • c --> [0], b. • c --> [1], c. • c --> [1]. • Show that G is ambiguous, i.e. give an example of a string that has two distinct derivations in G • Submit both the string and its derivations • Examples: • strings 101, 1011, 1001 are members of the language generated by G

  28. Question 2 • Two derivations for string 10001 • a --> [1], b. • b --> [0], b. • b --> [0], c. • c --> [0], b. • c --> [1], c. • c --> [1]. a c b b b a b b c b b b c b c b 0 1 0 0 0 0 1 0 1 1

  29. Question 3 • Consider again regular grammar G from Question 2 Start symbol: a, alphabet = {0,1} • a --> [1], b. • b --> [0], b. • b --> [0], c. • c --> [0], b. • c --> [1], c. • c --> [1]. • Construct an equivalent deterministic FSA for G • Show your steps (e.g. conversion into a NDFSA, conversion into a deterministic FSA) (diagrams okay)

  30. Question 3 0 • Grammar • a --> [1], b. • b --> [0], b. • b --> [0], c. • c --> [0], b. • c --> [1], c. • c --> [1]. a 1 1 b > 0 0 c d 1 Non-deterministic

  31. Question 3 1 0 0 • Set of states construction: 1 1 1 1 0 0 0 {c,d} {a} {b} {b,c} > a b > 0 1 c d

  32. Question 4 • Consider again regular grammar G from Question 2 Start symbol: a, alphabet = {0,1} • a --> [1], b. • b --> [0], b. • b --> [0], c. • c --> [0], b. • c --> [1], c. • c --> [1]. • Give an equivalent unambiguous regular grammar to G

  33. Question 4 0 1 • Use the answer to Question 3 1 1 0 Deterministic FSA {c,d} {a} {b} {b,c} > 0 Grammar: a --> [1], b. b--> [0], bc. bc --> [0], bc. bc --> [1], cd. cd --> [1], cd. cd --> [0],b. cd --> [].

  34. Question 5 • Argue (convincingly) whether regular expressions (1) and (2) are equivalent or not • a(ba)* • (ab)*a

  35. Question 5 • Argue (convincingly) whether regular expressions (1) and (2) are equivalent or not • a(ba)* • (ab)*a • Base case: • (1) a, (2) a. • Recursive case: • (1) aba..ba, (2) ab..abast. strings same, i.e. (1)=(2) • (1) aba..baba, (2)abab..aba

  36. Question 6 • Define a Perl regexp as regular expressions + backreferences. • We have seen in class that Perl regexps are more powerful than regular languages, e.g. the prime number testing example. • Decide whether these languages can be described using Perl regexps. • (Submit Perl regexps for the ones you decide can be described.) • L1 = {anbn | n ≥ 1} • L2 = {anbmanbm | n,m ≥ 1} • L3 = {anbnbn | n ≥ 1}

  37. Question 6 • L1= {anbn | n ≥ 1} • L2 = {anbmanbm | n,m ≥ 1} • L3 = {anbnbn | n ≥ 1} • Answers • No • /(a+)(b+)\1\2/ • No

More Related