Presentation is loading. Please wait.

Presentation is loading. Please wait.

LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong.

Similar presentations


Presentation on theme: "LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong."— Presentation transcript:

1 LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong

2 Homework 8 Clarifications
Overlap between the irregular verb list and the -en pattern: that's ok, you are free to report the numbers with them overlapping, or with them filtered out (of the irregular verb list) The perfective and passive can be combined: e.g. the eggs have been eaten Let $be a regex representing the forms of the verb be You're looking for $be followed by a verb ending in -en (passive)

3 On regexs … Webcomic: xkcd.com Acknowledgement: from Erwin Chan

4 Regular Languages Three formalisms
All formally equivalent (no difference in expressive power) i.e. if you can encode it using a RE, you can do it using a FSA or regular grammar, and so on … Regular Languages Note: Perl regexs are more powerful than the math characterization, e.g. backreferences, recursive regexs Regular Grammars FSA Expressions talk about formal equivalence next time

5 Regular Languages A regular language is the set of strings
(including possibly the empty string) (set itself could also be empty) (set can be infinite) generated by a RE/FSA/Regular Grammar Note: in formal language theory: a language = set of strings

6 Regular Languages Example:
Language: L = { a+b+ } “one or more a’s followed by one or more b’s” L is a regular language described by a regular expression (we’ll define it formally next time) Note: infinite set of strings belonging to language L e.g. abbb, aaaab, aabb, *abab, * Notation: is the empty string (or string with zero length), sometimes ε is used instead * means string is not in the language

7 Finite State Automata (FSA)
L = { a+b+ } can be also be generated by the following FSA s x y a b > Conventions (used here): > Indicates start state Red circle indicates end (accepting) state we accept a input string only when we’re in an end state and we’re at the end of the string

8 Finite State Automata (FSA)
L = { a+b+ } can be also be generated by the following FSA s x y a b > There is a natural correspondence between components of the FSA and the regex defining L Note: L = {a+b+} L = {aa*bb*}

9 Finite State Automata (FSA)
L = { a+b+ } can be also be generated by the following FSA s x y a b > deterministic FSA (DFSA) no ambiguity about where to go at any given state i.e. for each input symbol in the alphabet at any given state, there is a unique “action” to take non-deterministic FSA (NDFSA) no restriction on ambiguity (surprisingly, no increase in power)

10 Finite State Automata (FSA)
more formally (Q,s,f,Σ,) set of states (Q): {s,x,y} must be a finite set start state (s): s end state(s) (f): y alphabet (Σ): {a, b} transition function : signature: character × state → state (a,s)=x (a,x)=x (b,x)=y (b,y)=y s x y a b >

11 Finite State Automata (FSA)
In Perl transition function : (a,s)=x (a,x)=x (b,x)=y (b,y)=y We can simulate our 2D transition table using a hash whose elements are themselves (anonymized) hashes %transitiontable = ( s => { a => "x" }, x => { a => "x", b => "y" y => { } ); Example: print "$transitiontable{s}{a}\n"; s x y a b > Syntactic sugar for %transitiontable = ( "s", { "a", "x", }, "x", { "a", "x" , "b", "y" }, "y", { "b", "y" }, );

12 Finite State Automata (FSA)
Given transition table encoded as a hash How to build a decider (Accept/Reject) in Perl? Complications: How about ε-transitions? Multiple end states? Multiple start states? Non-deterministic FSA?

13 Finite State Automata (FSA)
%transitiontable = ( s => { a => "x" }, x => { a => "x", b => "y" y => { } $state = "s"; foreach $c { $state = $transitiontable{$state}{$c}; if ($state eq "y") { print "Accept\n"; } else { print "Reject\n" } Example runs: perl fsm.prl a b a b Reject perl fsm.prl a a a b b Accept

14 Finite State Automata (FSA)
this is pseudo-code not any real programming language but can be easily translated

15 In Python Python dictionary = Perl hash
key:value sys.argv but numbered from 1 tab indentation used for grouping statements

16 In Python Python has a data structure called a tuple: (e1,..,en)
Note: Python lists use [..] In Python, tuples (but not lists) can also be dictionary keys Note: Many other ways of encoding FSA in Python, e.g. using object-oriented programming (classes)

17 Finite State Automata (FSA)
practical applications can be encoded and run efficiently on a computer widely used encode regular expressions (e.g. Perl regex) morphological analyzers Different word forms, e.g. want, wanted, unwanted (suffixation/prefixation) see chapter 3 of textbook speech recognizers Markov models = FSA + probabilities and much more …


Download ppt "LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong."

Similar presentations


Ads by Google