LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.
-
date post
19-Dec-2015 -
Category
Documents
-
view
223 -
download
4
Transcript of LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.
![Page 1: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/1.jpg)
LING 388: Language and Computers
Sandiway Fong
Lecture 12: 10/5
![Page 2: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/2.jpg)
Today’s Topics
• Tasks – Practice how to write a FSA in Prolog– Dealing with string transitions
• Homework #4– Due next Thursday– Only two questions
• Derivational morphology and FSA• Converting NDFSA to (deterministic) FSA
![Page 3: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/3.jpg)
Prolog FSA: One predicate per state
• from previous lectures• Prolog FSA implementation
– regular expression: ba+!
– query• ?- s([b,a,a,’!’]).
– code– s([b|L]) :- x(L).
s x
z
b
!
ya
a
>
– y([a|L]) :- y(L).
– y([‘!’|L]) :- z(L).– z([]).
– x([a|L]) :- y(L).
![Page 4: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/4.jpg)
Exercise 1
Derivational Morphology• Write a Prolog FSA that accepts all words
ending in the verbal suffix -ize• use:
– atom_chars(Word,List)
– from the previous homework
• examples:– formalize– summarize– *formalizes
![Page 5: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/5.jpg)
Exercise 1
• Given code:ends_ize(Word) :-
atom_chars(Word,List),
s(List).
s = start state
• Write s/1 such that?- ends_ize(formalize).
Yes
?- ends_ize(summarize).Yes
?- ends_ize(formalizes).No
![Page 6: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/6.jpg)
Exercise 1
• Step 1: Draw the FSA: • Notes:– machine is non-
deterministic• see an i
• we don’t know if it’s the “i” in rise or formalize
– we can name the states anything we want
• here: states are named after the portion of the suffix recognized so far
s
i
iz
ize
z
i
e
a-z
![Page 7: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/7.jpg)
Exercise 1
• Step 1: Draw the FSA: • Step 2: Write the Prolog
• Hint: use the underscore variable to simulate the range a-z
s
i
iz
ize
z
i
e
a-z
![Page 8: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/8.jpg)
Exercise 1
• Step 1: Draw the FSA: • Step 2: Write the Prolog
s([_|L]) :- s(L).
s([i|L]) :- i(L).
i([z|L]) :- iz(L).
i([e|L]) :- ize(L).
ize([]).
s
i
iz
ize
z
i
e
a-z
![Page 9: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/9.jpg)
String Transitions
[last lecture]
• all machines have had just a single character label on the arc
• so if we allow strings to label arcs– do they endow the FSA with any
more power?
b
• Answer: No– because we can always convert a
machine with string-transitions into one without
abb
a b b
![Page 10: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/10.jpg)
Exercise 2
• Let’s simplify the FSA for Exercise 1 using string transitions
• Give the modified Prolog form
s
i
iz
ize
z
i
e
a-z
s
ize
ize
a-z
![Page 11: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/11.jpg)
Exercise 2
• Give the modified Prolog form
s([_|L]) :- s(L).s([i,z,e|L]) :- ize(L).ize([]).
s([_|L]) :- s(L).s([i,z,e]).
s
i
iz
ize
z
i
e
a-z
s
ize
ize
a-z
![Page 12: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/12.jpg)
Homework Question 1
• Part 1: (8pts)• Modify your machine so that it accepts
– formalize– modernize– summarize– concretize– sterilize
• but rejects– *summaryize– *concreteize– *sterileize
• Part 2: (2pts)– explain what rule of English are we trying to encode here?
![Page 13: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/13.jpg)
Empty Transitions
[last lecture]• how about allowing the empty
character? – i.e. go from x to y without seeing a input
character– does this endow the FSA with any more
power?
• Answer: No– because we can always convert a
machine with empty transitions into one without
x y
a
b
a
b
b
a
b>
a b
![Page 14: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/14.jpg)
NDFSA
• Deterministic FSA– deterministic
• it’s clear which state we’re always in• deterministic = no choice
• NDFSA– ND = non-deterministic
• i.e. we could be in more than one state• non-deterministic choice point
– example:• see an “a”, either in state 2 or 3 next
s x
y
aa
b
b
>
> 1 2a
a
3b
>
![Page 15: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/15.jpg)
NDFSA
• NDFSA are generally not more powerful than regular (deterministic) FSA
• because
• we can transform any NDFSA into an equivalent FSA
• trick:– (set of states construction)– construct new machine with
states = set of possible states of the old machine
1 2a
a
3b
>
{1}>
a{1}> {2,3}
{3}ba
{1}> {2,3}
{3}ba
{1}> {2,3}
1 2,3a
3b
2,32>
![Page 16: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/16.jpg)
Homework Question 2
• (10pts)• Part 1: (8pts)• Transform the NDFSA shown
on the right into a deterministic FSA
• Give the Prolog implementation of the machine
• Part 2: (2pts)– what does this machine do?
– i.e. what is the language it accepts?
q4>
![Page 17: LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649d3a5503460f94a14e37/html5/thumbnails/17.jpg)
Summary
• Total: 20 pts
• Question 1: 10pts
• Question 2: 10pts