ETA beautifier
This is a utility program for Mike Taylor's ETA language.
This program takes a plain ETA text (using only the ETA command characters and newlines), and converts it to English-alike sentences. The sentences are made from words in usr/dict/words, with some added punctuation. The output usually reads as complete nonsense, but the random nature of the conversion process means that eventually the complete works of Shakespeare will be produced.
This program is written in Ruby - in case you haven't come across Ruby before, it is an extremely well designed object oriented programming language, which has a number of interesting features. To learn more visit the Ruby home page.
This program simply takes ETA on the standard input, and produces beautified ETA on the standard output.
Example
The following ETA is a simple implementation of the traditional 'Hello, World!' program:
ntoaeonahoeonatoeonatoeonatseonsaeoniieontnoeonatseonaaaeonatoeonahaeonineontoeo
anet
The ETA Beautifier transforms it into this:
Burnt rockabye Conakry bulky hole pulmonary, trolley bud, round luxury vault buff. Bordello Nat. Seldom wry, Cygnus cameo fungicide, font. Noel. Don Arcturus. Mckeon, Ababa Creon atop gum, Ceylon jumpy mullah pug paperwork ninefold drug junctor bellboy.
Gander turk.
Source Code
You can download the program here.
# eta beautifier # # S.D.Sykes July 2001 # words = IO.readlines("usrdictwords") #words = IO.readlines("dirtywords") # could use any dictionary you like $profiles = Hash.new words.each do |w| w.chomp! w.gsub!(/\r/,"") # exclude some words I don't want to see in the output here if (w =~ /[a-z]/ && w !~ /(cf)|(Pl)|(Ft)|(Rd)|(du)|(Wu)|(Mt)|(Cluj)|(ppm)|(Mbabane)|(St)|(Nguyen)/) index = w.downcase.gsub(/[bcdfgjklmpqruvwxyz]/,"") if (w.length > 1 || index.length > 0) if ($profiles[index]) $profiles[index] = $profiles[index] + "|" + w else $profiles[index] = w end end end end def getword(p) if ($profiles[p]) ar = $profiles[p].split("|") ar[rand(ar.length)] else nil end end outstr = String.new("") ucflag = 0 while gets i = 0 $_.chomp! while (i < $_.length) testar = [2,6,5,4,3,1,0] testar = [2,5,4,3,6,1,0] if rand(3)==1 testar = [1,3,2,6,5,4,0] if rand(3)==1 testar.each do |a| if (getword($_[i..i+a]) || a==0) if (ucflag == 0) outstr << (getword($_[i..i+a])?getword($_[i..i+a]):$_[i]) << " " else if (getword($_[i..i+a])) outstr << getword($_[i..i+a]).capitalize << " " else outstr << $_[i].chr.capitalize << " " end ucflag = 0 end outstr.capitalize! if i == 0 i = i + a + 1 break end end if (rand(5)==1) outstr << getword("") << " " end if (outstr !~ /[,.:] *$/) if (rand(5)==1) outstr.gsub!(/ +$/, ", ") elsif (rand(9)==1) outstr.gsub!(/ +$/, ". ") ucflag = 1 elsif (rand(35)==1) outstr.gsub!(/ +$/, ": ") end end end if (outstr == "") outstr = getword("").capitalize outstr = outstr << " " << getword("") if rand(2)==1 end outstr = outstr.gsub(/^\s*/,"").gsub(/\s*$/,"") # top and tail spaces outstr = outstr.gsub(/\ss\s/,"s ").gsub(/\ss$/,"s") # move single 's's to end of prev word outstr = outstr.gsub(/\s\s+/," ") # remove multiple spaces outstr = outstr.gsub(/[,.:]$/, "") # remove trailing punctuation print outstr, ".\n" outstr = "" end