# LING 388: Language and Computers Sandiway Fong 9/29 Lecture 11.

## Presentation on theme: "LING 388: Language and Computers Sandiway Fong 9/29 Lecture 11."— Presentation transcript:

LING 388: Language and Computers Sandiway Fong 9/29 Lecture 11

Last Time Prolog FSA implementation –regular expression: baa + ! –query ?- s([b,a,a,!]). –code one predicate per state (but each predicate may have more than one rule) –s([b|L]) :- w(L). –y([a|L]) :- y(L). –y([!|L]) :- z(L). –z([]). –w([a|L]) :- x(L). –x([a|L]) :- y(L). z ! y a sw ba > x a

Today’s Topics More on –the power of FSA, and –writing FSA in Prolog

FSA Finite State Automata (FSA) have a limited amount of expressive power Let’s look at some modifications to FSA and their effects on its power

Last Time String Transitions if we allow strings to label arcs –do they endow the FSA with any more power? abb abb Empty Transitions if we allow empty transitions –do they endow the FSA with any more power? xy ε 12 a a 3 b > Set of states construction Eliminate all determinism Empty transitions and as well as symbol ambiguity 1 2,3 a 3 b 2 >

Equivalence FSANDFSA FSA with ε-transitions same expressive power

NDFSA and Prolog we have already seen how to encode a regular FSA in Prolog –(using one predicate per state) z ! y a sw ba > x a Database s([b|L]) :- w(L). w([a|L]) :- x(L). x([a|L]) :- y(L). y([a|L]) :- y(L). y([!|L]) :- z(L). z([]).

NDFSA and Prolog we can do the same for NDFSA –without the set-of-states conversion to FSA –let Prolog’s computation rule keep track of the possible states and choice points for us s([a|L]) :- x(L). s([a|L]) :- y(L). x([b|L]) :- y(L). y([]). s([a|L]) :- x(L). s([a|L]) :- y(L). x([b|L]) :- y(L). y([]). sx a a y b >

NDFSA and Prolog computation tree –?- s([a]).L=[] rule 1 ?- x([]). –No ?- y([]).L=[] rule 2 –Yes rule 4 1.s([a|L]) :- x(L). 2.s([a|L]) :- y(L). 3.x([b|L]) :- y(L). 4.y([]). 1.s([a|L]) :- x(L). 2.s([a|L]) :- y(L). 3.x([b|L]) :- y(L). 4.y([]). sx a a y b > 2

ε-Transitions and Prolog earlier example s([a|L]):- x(L). s(L):- x(L). x([b|L]):- y(L). y([]). s([a|L]):- x(L). s(L):- x(L). x([b|L]):- y(L). y([]). ε sx a y b > pass on L from state s to state x unchanged

ε-Transitions and Prolog Computation tree: –?- s([b]). rule 2 ?- x([b]).L=[] rule 3 –?- y([]). rule 4 »Yes 1.s([a|L]):- x(L). 2.s(L):- x(L). 3.x([b|L]):- y(L). 4.y([]). 1.s([a|L]):- x(L). 2.s(L):- x(L). 3.x([b|L]):- y(L). 4.y([]). ε sx a y b >

Worked Example 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

Worked Example Derivational Morphology write a FSA that accepts all words ending in the verbal suffix -ize use: –atom_chars(Word,List) –from previous homework examples: –formalize –summarize –*formalizes

Worked Example 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

Worked Example 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

Worked Example Step 1: Draw the FSA:Step 2: Write the Prolog Hint: use the underscore variable to simulate the range a-z (more precisely, a variable will allow any character to match, not just a-z.) s i iz ize z i e a-z

Worked Example Step 1: Draw the FSA:Step 2: Write the Prolog s([_|L]) :- s(L). s([i|L]) :- i(L). i([z|L]) :- iz(L). iz([e|L]) :- ize(L). ize([]). s i iz ize z i e a-z

Recall [previous 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 abb

Worked Example: Part 2 Let’s simplify the FSA for -ize using string transitions Give the modified Prolog form s i iz ize z i e a-z s ize a-z

Worked Example: Part 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 a-z Note: this is a further simplication, it replaces: s([i,z,e]) :- ize([]).

Worked Example: Part 3 Note: -ize suffixation works with –formalize –modernize –summarize –concretize –Sterilize but not –*summaryize –*concreteize –*sterileize What rule of English is at work here?

Worked Example: Part 3 s([_|L]) :- s(L). s([X,i,z,e]) :- \+ vowel(X). vowel(e). vowel(y). etc… Exercise: pick some other English suffixation rule, e.g. –able, and implement it as a Prolog FSA. Exercise: pick some other English suffixation rule, e.g. –able, and implement it as a Prolog FSA.

Similar presentations