Download presentation
Presentation is loading. Please wait.
1
LING 388: Language and Computers Sandiway Fong Lecture 10: 9/26
2
2 Adminstrivia Reminders –No class Thursday –Homework 3 due Thursday Correction –Homework Exercise 2 –Question 4 (1pt) Why is the answer different from a simple spokes* search? –Reword as: Why could the answer different from a simple spokes* search?
3
3 Last Time... into detail with Microsoft Word’s regular expression facility –Find with wildcard option enabled –somewhat limited form of regular expression search
4
4 Today’s Topic Finite State Automata (FSA) equivalent to the regular expressions we’ve been studying
5
5 Regular Expressions: Example.... from lecture 8 example (sheeptalk) –ba! –baa! –baaa! … regular expression –baa*! –ba+!
6
6 Regular Expressions: Example.... from lecture 6 example (sheeptalk) –ba! –baa! –baaa! … regular expression –baa*! –ba+! sx z b ! y a a >
7
7 Regular Expressions: Example step-by-step regular expression –baa*! s >
8
8 Regular Expressions: Example step-by-step regular expression –baa*! –b –from s, –see a ‘b’, –move to x sx b >
9
9 Regular Expressions: Example step-by-step regular expression –baa*! –ba –from x, –see an ‘a’, –move to y sx b y a >
10
10 Regular Expressions: Example step-by-step regular expression –baa*! –baa* –ba –baa –baaa –baaaa... –from y, –see an ‘a’, –move to ? sx b y a > y’ y” a a a... but machine must have a finite number of states!
11
11 Regular Expressions: Example step-by-step regular expression –baa*! –baa* –ba –baa –baaa –baaaa... –from y, –see an ‘a’, –“loop” or move back to y sx b y a a >
12
12 Regular Expressions: Example step-by-step regular expression –baa*! –from y, –see an ‘!’, –move to final state z (indicated in red) sx z b ! y a a > Note: machine cannot finish (i.e. reach the end of the input string) in states s, x or y
13
13 Finite State Automata (FSA) construction –the step-by-step FSA construction method we just used –works for any regular expression conclusion –anything we can encode with a regular expression, we can build a FSA for it –an important step in showing that FSA and REs are equivalent
14
14 Microsoft Word Wildcards basic wildcards –? and * ? any single character e.g. p?tput, pit, pat, pet *zero or more characters xy d a b c e z etc.... y a etc. one loop for each character
15
15 Microsoft Word Wildcards basic wildcards –@ one or more of the preceding character e.g. a@ –[ ] range of characters e.g. [aeiou] xy a a xy o a e i u
16
16 Microsoft Word Wildcards basic wildcards – < beginning of a word can think of there being a special symbol/invisible character marking the beginning of each word > end of a word suppose there is an invisible character marking the end of each word xy < see anything but ‘<‘ xy > see anything but ‘>‘
17
17 Microsoft Word Wildcards basic wildcards – > end of a word –Note the see-anything-but loop is implicit m> “word that ends in m” example: –mom is... xy > see anything but ‘>‘ xy m see anything but ‘m‘ z >
18
18 Finite State Automata (FSA) more formally –(Q,s,f,Σ, ) 1.set of states (Q): {s,x,y,z} 4 statesmust be a finite set 2.start state (s): s 3.end state(s) (f): z 4.alphabet ( Σ ): {a, b, !} 5.transition function : signature: character × state → state (b,s)=x (a,x)=y (a,y)=y (!,y)=z sx z b ! y a a >
19
19 Finite State Automata (FSA) in Prolog –define one predicate for each state taking one argument (the input string L ) consume input character call next state with remaining input string –query fsa(L) :- s(L). i.e. call start state s
20
20 Finite State Automata (FSA) state s: (start state) –s([b|L]) :- x(L). match input string beginning with b and call state x with remainder of input state x: –x([a|L]) :- y(L). state y: –y([a|L]) :- y(L). –y(['!'|L]) :- z(L). state z: (end state) –z([]). sx z b ! y a a >
21
21 Finite State Automata (FSA) query –?- s([b,a,a,’!’]). sx z b ! y a a > Database s([b|L]) :- x(L). x([a|L]) :- y(L). y([a|L]) :- y(L). y(['!'|L]) :- z(L). z([]). query –?- s([b,a,b,a,’!’]). –in which state does this query fail? [b,a,a,’!’][a,a,’!’] [a,’!’] [’!’] [] [b,a,b,a,’!’] [a,b,a,’!’] [b,a,’!’]
22
22 FSA Finite State Automata (FSA) have a limited amount of expressive power Let’s look at a modification to FSA and its effect on its power
23
23 String Transitions –so far... 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 abb
24
24 Finite State Automata (FSA) equivalent s z ba ! y a > sx z b ! y a a > 4 state machine
25
25 Finite State Automata (FSA) equivalent s z ba ! y a > sx z b ! y a a > Database s([b|L]) :- x(L). x([a|L]) :- y(L). y([a|L]) :- y(L). y(['!'|L]) :- z(L). z([]). Database s([b,a|L]) :- y(L). y([a|L]) :- y(L). y(['!'|L]) :- z(L). z([]).
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.