Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

gollum speak translator

by Anonymous Monk
on May 23, 2003 at 13:37 UTC ( #260357=CUFP: print w/replies, xml ) Need Help??

After reading about grep's efforts at yoda-speak, I got inspired to try doing a translator for another certain CGI character with distinct language patterns. The result isn't so much a program as a regular expression grinder that breaks rather easily. It works best for simple present-tense first-person statements, which are mostly what gollum mutters anyway.

I welcome any comments or suggestions on this. I would like nothing better if someone improved on this and shared it back. Some possible enhancements might be: using a module to parse the grammar, modifying individual words one at a time so the global substitutions don't trip over each other (the order of the regular expressions is very deliberate), adding more gollum-words to the lists for the randomizer to choose from...yeah with something this primitive there are all sorts of possibilities.

Some examples to put through it:
I hate you forever
Do you like green eggs and ham
I want it back
Frodo is nice, not like Sam

#!/usr/bin/perl -w use strict; while (<>) { chomp; #call Sam 'the ____ hobbit' my @sam_list = qw(nasty rude mean); my $sam_descr = $sam_list[int rand scalar(@sam_list)]; s/\bSam\b/the $sam_descr hobbit/ig; #replace 's' at word's end with 'ses' s/([a-rt-z]{3,})s(\b)/$1ses$2/ig; #replace 's' at word's start or middle with 'sss' s/(\b\w*)[sS]([a-df-z]+\b)/$1sss$2/ig; s/\bme\b/us/ig; #call Frodo 'Master' s/\bFrodo\b/Master/ig; #replace second-person words with third-person 'it' s/your/its/ig; s/\byou\b/it/ig; s/\bare\b/is/ig; s/have/has/ig; #replace past-tense words with present-tense s/was/is/ig; s/(\b\w{3,})ed(\b)/$1s$2/ig; #replace 'i <verb>' with 'i <verb>s' naively s/^i\s(\w{4,})\b/I $1s/ig; s/\bdo\b/does/ig; #replace first-person words with third-person my @i_list = qw(we smeagol); my $i_descr = $i_list[int rand scalar(@i_list)]; s/\bi\b/$i_descr/ig; #stick a generic ending on the end (no if negatives) my $ending = ""; $ending = "no" if (m/(not)|(no)/); my @endings = ("","yess","my precioussss", "gollum"); $ending = $endings [int rand scalar(@endings)] unless ($ending eq "n +o"); $_ .= " $ending"; #capitalize the sentence $_ = ucfirst($_); print $_, "\n"; }

20030524 Edit by Corion: Changed absolute link into [id://...] style.

Replies are listed 'Best First'.
Re: gollum speak translator
by Anonymous Monk on Apr 20, 2017 at 06:13 UTC

    English actor Andy Serkis turns 53 today

Re: gollum speak translator
by Lou Wen Xi (Initiate) on Jun 11, 2003 at 13:29 UTC
    You might want to put the regexs in a seperate file. That way you can write translators without messing up the code.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://260357]
Approved by Tanalis
Front-paged by Tanalis
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2017-04-24 21:35 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (447 votes). Check out past polls.