Finite-State Funhouse


Welcome to the Finite-State Funhouse, a small collection of amusing finite-state machine examples that have been implemented in Xerox Finite-State Tools (XFST). You need to have XFST installed in order to try them. Enjoy!


ELIZA

ELIZA (Weizenbaum 1966) is a computer program simulating a (rogerian) psycho-therapist. The program is a 'classical' program in the area of Artificial Intelligence, with many followers (Emacs users: run the command "Meta-x doctor" to meet with one of them!).

The following regular expressions compile into a finite-state transducer implementing a Swedish speaking version of ELIZA:

define Delimiter [" "|.#.|"."|"?"] ;

regex jag -> du, du -> jag || Delimiter _ Delimiter;

regex dig -> mig, mig -> dig || Delimiter _ Delimiter;

regex  $[mamma|pappa] @-> "Kan du berätta mer om din familj?";

turn stack
compose net
apply down
 

Note the use of parallel- and longest-match replacement. The resulting machine behaves as follows:

xfst[1]: apply down
apply down> hej
hej
apply down> jag längtar efter min mamma
Kan du berätta mer om din familj?
apply down> varför frågar du mig?
varför frågar jag dig?
apply down> jag tycker du är dum
du tycker jag är dum
apply down>
 

Constructed by Torbjörn Lager


Lingo

In a game of Lingo, there is a hidden word, five characters long. The object of the game is to find this word by guessing, and in return receive two kinds of information: 1) the characters that are fully correct, with respect to identity as well as to position, and 2) the characters that are indeed present in the word, but which are placed in the wrong position.

A machine with which one can play Lingo can easily be constructed in XFST. Square brackets are used to mark characters correct in the sense of 1), and ordinary parantheses to mark characters correct in the sense of 2).

Assuming, for example, that the machine conceals the word "tiger", you may interact with it in the following way:

xfst[1]: apply down
apply down> snake
snak(e)
apply down> fiest
f[i](e)s(t)
apply down> times
[t][i]m[e]s
apply down> tiger
[t][i][g][e][r]
apply down>
 
Here's an XFST script accomplishing this:

read regex
        t -> %[ ... %] || _ ? ? ? ? ,,
        i -> %[ ... %] || ? _ ? ? ? ,,
        g -> %[ ... %] || ? ? _ ? ? ,,
        e -> %[ ... %] || ? ? ? _ ? ,,
        r -> %[ ... %] || ? ? ? ? _ ;
define CorrectChar

define CorrectPos [t|i|g|e|r] -> "(" ... ")" || [.#.|\"["] _ [\"]"|.#.];
 
regex CorrectChar .o. CorrectPos;

apply down
 

Constructed by Natalia Zinovjeva and Torbjörn Lager


The World's Fastest Haiku Generator!

Haiku is a Japanese form of poetry which in its classical form consists of seventeen syllables. In English haiku poems, these are distributed over three lines (for more about the relation between English and Japanese haikus, see here):

    Five syllables
    Seven  syllables
    Five syllables

Syntactically, it may look as follows (although many other variants are possible):

    Prep Det A N
    Det A N Part Vsg3
    Mod Adv

Here's a concrete example:

    Behind hope's dead goose
    Joe's eager baboon still snorts
    seemingly slowly

The following XFST script results in a machine which is able to generate English haiku poems. Use the XFST command print random 1 to randomly generate poems.
 
read regex
a %+DET %@ |
any %+DET %@ |
each %+DET %@ |
fate's %+DET %@ |
her %+DET %@ |
his %+DET %@ |
hope's %+DET %@ |
joe's %+DET %@ |
man's %+DET %@ |
my %+DET %@ |
one %+DET %@ |
our %+DET %@ |
some %+DET %@ |
the %+DET %@ |
their %+DET %@ |
this %+DET %@ |
your %+DET %@ |
axe %+N %@ |
babe %+N %@ |
barn %+N %@ |
beard %+N %@ |
beer %+N %@ |
bird %+N %@ |
bluff %+N %@ |
box %+N %@ |
boy %+N %@ |
bud %+N %@ |
bull %+N %@ |
bus %+N %@ |
car %+N %@ |
cat %+N %@ |
chick %+N %@ |
cloud %+N %@ |
coat %+N %@ |
cow %+N %@ |
dog %+N %@ |
dude %+N %@ |
face %+N %@ |
fox %+N %@ |
frog %+N %@ |
girl %+N %@ |
goose %+N %@ |
hail %+N %@ |
hand %+N %@ |
home %+N %@ |
horse %+N %@ |
house %+N %@ |
jerk %+N %@ |
jet %+N %@ |
leaf %+N %@ |
light %+N %@ |
lip %+N %@ |
log %+N %@ |
man %+N %@ |
moon %+N %@ |
nail %+N %@ |
name %+N %@ |
nerd %+N %@ |
nose %+N %@ |
pan %+N %@ |
pig %+N %@ |
point %+N %@ |
pond %+N %@ |
pot %+N %@ |
rain %+N %@ |
rat %+N %@ |
rock %+N %@ |
room %+N %@ |
rose %+N %@ |
school %+N %@ |
shoe %+N %@ |
sin %+N %@ |
sink %+N %@ |
snail %+N %@ |
snow %+N %@ |
sock %+N %@ |
soul %+N %@ |
stalk %+N %@ |
star %+N %@ |
stem %+N %@ |
stick %+N %@ |
street %+N %@ |
sun %+N %@ |
swan %+N %@ |
tea %+N %@ |
tree %+N %@ |
vase %+N %@ |
watch %+N %@ |
yak %+N %@ |
animal %+N %@ %@ |
baboon %+N %@ %@ |
sailor %+N %@ %@ |
baboon %+N %@ %@ |
water %+N %@ %@ |
river %+N %@ %@ |
lover %+N %@ %@ |
bad %+A %@ |
bald %+A %@ |
black %+A %@ |
bold %+A %@ |
bright %+A %@ |
brown %+A %@ |
calm %+A %@ |
clear %+A %@ |
cold %+A %@ |
dark %+A %@ |
dead %+A %@ |
dear %+A %@ |
firm %+A %@ |
flat %+A %@ |
fleet %+A %@ |
gold %+A %@ |
good %+A %@ |
green %+A %@ |
hard %+A %@ |
high %+A %@ |
loud %+A %@ |
low %+A %@ |
odd %+A %@ |
old %+A %@ |
poor %+A %@ |
proud %+A %@ |
quick %+A %@ |
raw %+A %@ |
red %+A %@ |
rich %+A %@ |
round %+A %@ |
sad %+A %@ |
sharp %+A %@ |
short %+A %@ |
slow %+A %@ |
small %+A %@ |
soft %+A %@ |
warm %+A %@ |
weird %+A %@ |
young %+A %@ |
eager %+A %@ %@ |
is %+V %@ |
ask %+V %@ |
bawl %+V %@ |
bend %+V %@ |
bump %+V %@ |
call %+V %@ |
chart %+V %@ |
cheat %+V %@ |
chirp %+V %@ |
claw %+V %@ |
crawl %+V %@ |
creep %+V %@ |
drink %+V %@ |
fall %+V %@ |
groan %+V %@ |
jump %+V %@ |
moan %+V %@ |
mourn %+V %@ |
part %+V %@ |
plead %+V %@ |
pray %+V %@ |
read %+V %@ |
scream %+V %@ |
sell %+V %@ |
shout %+V %@ |
shrink %+V %@ |
sing %+V %@ |
sleep %+V %@ |
snarl %+V %@ |
snort %+V %@ |
speak %+V %@ |
squirt %+V %@ |
stand %+V %@ |
start %+V %@ |
stink %+V %@ |
think %+V %@ |
turn %+V %@ |
wait %+V %@ |
walk %+V %@ |
weep %+V %@ |
yawn %+V %@ |
yearn %+V %@ |
asks %+Vsg3 %@ |
bawls %+Vsg3 %@ |
bends %+Vsg3 %@ |
bumps %+Vsg3 %@ |
calls %+Vsg3 %@ |
charts %+Vsg3 %@ |
cheats %+Vsg3 %@ |
chirps %+Vsg3 %@ |
claws %+Vsg3 %@ |
crawls %+Vsg3 %@ |
creeps %+Vsg3 %@ |
drinks %+Vsg3 %@ |
falls %+Vsg3 %@ |
groans %+Vsg3 %@ |
jumps %+Vsg3 %@ |
moans %+Vsg3 %@ |
mourns %+Vsg3 %@ |
parts %+Vsg3 %@ |
pleads %+Vsg3 %@ |
prays %+Vsg3 %@ |
reads %+Vsg3 %@ |
screams %+Vsg3 %@ |
sells %+Vsg3 %@ |
shouts %+Vsg3 %@ |
shrinks %+Vsg3 %@ |
sings %+Vsg3 %@ |
sleeps %+Vsg3 %@ |
snarls %+Vsg3 %@ |
snorts %+Vsg3 %@ |
speaks %+Vsg3 %@ |
squirts %+Vsg3 %@ |
stands %+Vsg3 %@ |
starts %+Vsg3 %@ |
stinks %+Vsg3 %@ |
thinks %+Vsg3 %@ |
turns %+Vsg3 %@ |
waits %+Vsg3 %@ |
walks %+Vsg3 %@ |
weeps %+Vsg3 %@ |
yawns %+Vsg3 %@ |
yearns %+Vsg3 %@ |
asking %+Ving %@ %@ |
bawling %+Ving %@ %@ |
bending %+Ving %@ %@ |
bumping %+Ving %@ %@ |
burping %+Ving %@ %@ |
calling %+Ving %@ %@ |
charting %+Ving %@ %@ |
cheating %+Ving %@ %@ |
chirping %+Ving %@ %@ |
clawing %+Ving %@ %@ |
crawling %+Ving %@ %@ |
creeping %+Ving %@ %@ |
drinking %+Ving %@ %@ |
falling %+Ving %@ %@ |
groaning %+Ving %@ %@ |
jumping %+Ving %@ %@ |
laughing %+Ving %@ %@ |
moaning %+Ving %@ %@ |
mourning %+Ving %@ %@ |
parting %+Ving %@ %@ |
pleading %+Ving %@ %@ |
praying %+Ving %@ %@ |
reading %+Ving %@ %@ |
screaming %+Ving %@ %@ |
singing %+Ving %@ %@ |
selling %+Ving %@ %@ |
shouting %+Ving %@ %@ |
shrinking %+Ving %@ %@ |
singing %+Ving %@ %@ |
sleeping %+Ving %@ %@ |
snarling %+Ving %@ %@ |
snorting %+Ving %@ %@ |
speaking %+Ving %@ %@ |
squirting %+Ving %@ %@ |
standing %+Ving %@ %@ |
starting %+Ving %@ %@ |
stinking %+Ving %@ %@ |
thinking %+Ving %@ %@ |
turning %+Ving %@ %@ |
waiting %+Ving %@ %@ |
walking %+Ving %@ %@ |
weeping %+Ving %@ %@ |
yawning %+Ving %@ %@ |
yearning %+Ving %@ %@ |
running %+Ving %@ %@ |
flying %+Ving %@ %@ |
dying  %+Ving %@ %@ |
swimming %+Ving %@ %@ |
yawning %+Ving %@ %@ |
badly %+ADV %@ %@ |
boldly %+ADV %@ %@ |
brightly %+ADV %@ %@ |
calmly %+ADV %@ %@ |
deadly %+ADV %@ %@ |
firmly %+ADV %@ %@ |
loudly %+ADV %@ %@ |
proudly %+ADV %@ %@ |
quickly %+ADV %@ %@ |
sadly %+ADV %@ %@ |
sharply %+ADV %@ %@ |
slowly %+ADV %@ %@ |
softly %+ADV %@ %@ |
warmly %+ADV %@ %@ |
coldly %+ADV %@ %@ |
nicely %+ADV %@ %@ |
eagerly %+ADV %@ %@ %@ |
in %+PREP %@ |
on %+PREP %@ |
to %+PREP %@ |
around %+PREP %@ %@ |
besides %+PREP %@ %@ |
along %+PREP %@ %@ |
aboard %+PREP %@ %@ |
above %+PREP %@ %@ |
among %+PREP %@ %@ |
behind %+PREP %@ %@ |
inside %+PREP %@ %@ |
outside %+PREP %@ %@ |
under %+PREP %@ %@ |
without %+PREP %@ %@ |
still %+PART %@ |
extremely %+MOD %@ %@ %@ |
heavily %+MOD %@ %@ %@ |
awfully %+MOD %@ %@ %@ |
seemingly %+MOD %@ %@ %@ |
dreadfully %+MOD %@ %@ %@ |
quite %+MOD %@ |
very %+MOD %@ %@ |
bloody %+MOD %@ %@ ;
define Word

define Tag [%+DET|%+N|%+V|%+A|%+Ving|%+Vsg3|%+ADV|%+MOD|%+PREP|%+PART|%@|%@ %@|%@ %@ %@];

define SP " " ;

define Syll %@+;

define Words [[Word SP]+ "\n"]+;

define Det [? %+DET Syll SP] ;
define N [? %+N Syll SP] ;
define V [? %+V Syll SP] ;
define A [? %+A Syll SP] ;
define Ving [? %+Ving Syll SP] ;
define Vsg3 [? %+Vsg3 Syll SP] ;
define ADV [? %+ADV Syll SP] ;
define PART [? %+PART Syll SP] ;
define PREP [? %+PREP Syll SP] ;
define MOD [? %+MOD Syll SP] ;
 

define FiveSyllLine [?* %@ ?* %@ ?* %@ ?* %@ ?* %@ ?*] ;

define SevenSyllLine [?* %@ ?* %@ ?* %@ ?* %@ ?* %@ ?* %@ ?* %@ ?*] ;
 

define Phrase1 [PREP Det A N];

define Phrase2 [Det A N PART Vsg3];

define Phrase3 [MOD ADV];
 

define Line1 FiveSyllLine & Phrase1;

define Line2 SevenSyllLine & Phrase2;

define Line3 FiveSyllLine & Phrase3;
 

define Haiku [Line1 "\n"  Line2 "\n" Line3 "\n"] ;

define FilterTags Tag -> [];
 

regex [Words & Haiku] .o. FilterTags ;
 

 
Constructed by Torbjörn Lager