Lingua::EN::Namegame - Creates a "Name-Game" verse from a name (or word)


Lingua-EN-Namegame documentation Contained in the Lingua-EN-Namegame distribution.

Index


Code Index:

NAME

Top

Lingua::EN::Namegame - Creates a "Name-Game" verse from a name (or word)

VERSION

Top

This document describes version 0.04 of Lingua::EN::Namegame, released January 01, 2003.

SYNOPSIS

Top

	use Lingua::EN::Namegame;

	$verse = name2verse ('Marsha');

	print $verse;

Or, more simply, at your OS command prompt:

	name2verse.pl  Marsha		# script provided with module

Output

	Marsha Marsha 
	    bo Barsha, 
		Banana Fanna Fo Farsha, 
		    Fee Fi Mo-arsha
			MARSHA!

Or, for extra policital correctness

	name2verse_nonprofane.pl  Bart	# script provided with module

Output

	Sorry, the verse for Bart contains a profane word.

DESCRIPTION

Top

Purpose

name2verse is a subroutine that generates a rhyming verse based on a name (or word), in accordance with the rhyming algorithm documented in the lyrics of the famous 1960's song The Name Game, by Shirley Ellis.

Background

A presentation based on this program was featured as a Lightning Talk at the North American Yet Another Perl Conference (YAPC::NA) in St. Louis MO, USA, on 6/28/2002.

Thanks to the foresight of the moderator (MJD), the presentation was scheduled as the last one for the day, providing us ample time to delve into extra-curricular shenanigans after the technical part of the presentation.

And few present will ever forget the spine-tingling effect of 300+ deranged Perl fanatics giving song to the rhyming verses for various Perl built-in functions, including map, grep, split, and of course, the especially euphonious wantarray:

	Wantarray Wantarray
	    bo Bantarray, 
		Banana Fanna Fo Fantarray, 
		    Fee Fi Mo Mantarray
			  WANTARRAY!

Notice the way this oddly chosen function name smoothly metamorphoses into a denizen of the deep in the penultimate line!

And some thought Larry had goofed up by not calling it wantlist instead. Poppycock!

Profanity Issues

Hey, that's not a bad word itself; let's try it!

	Poppycock Poppycock
	    bo Boppycock, 
		Banana Fanna Fo Foppycock, 
		    Fee Fi Mo Moppycock
		      POPPYCOCK!

Which reminds me that some actual human names, such as Bart and especially Chuck, give rise to really rousingly ribald rhymes, which has often led to embarassing outbursts of blushing and snickering in our Perl training classes. One solution is to use the supplied name2verse_nonprofane.pl script to identify and filter-out verses that are judged to contain profane words. It does this through use of the "profanity matching regex" of Damian Conway's Regexp::Common module.

RHYMING ALGORITHM

Top

This program was inspired by "One-Liner #40", in The Perl Journal #15, Fall 1999, p. 11., by Sean M. Burke, which used a simplified version of the algorithm for succinctness:

 s<^([bcdfghjklmnpqrstvwxyz]*)(\w+).*>
    <$1$2 $1$2 $1o $1$2/Bonana-Fanna-Fo-F$2/Fe Fi Mo M$2/$1$2!>i;

In contrast, this module aims to comply with the actual rhyming rules of the song, as documented in http://www.geocities.com/SunsetStrip/Palladium/1306/shirley.htm.

General Rules

1. Say the Name twice (following examples using "Dave")
	-> "Dave Dave"




2. Say "bo" and Name again, replacing Name's first letter by B
	-> "Bo Bave"

3. Say "Banana Fanna Fo" Name, replacing Name's first letter by F
	-> "banana Fanna Fo Fave"

4. Say "Fee Fi Mo" Name, replacing Name's first letter by M
	-> "Fee Fi Mo Mave"

5. Finally, exclaim Name
	-> "Dave!"

Alternate Rules

Modified versions of rules 2-4 apply to Names starting with B, F, or M.

2. B-names:

say "Bo" and then Name without the initial B:

	-> "Bo-ob" (for Bob)
	-> "Bo-rian" (for Brian)
	-> "Bo-lanche" (for Blanche)

3. F-names:

instead of "Banana Fanna Fo" Fred:

	-> "Banana Fanna" B<Fo-red>

4. M-names:

instead of "Fee Fi Mo" Marsha:

	-> "Fee Fi" B<Mo-arsha>

BUGS

Top

Please let me know if you find any bugs.

EXPORTS

Top

name2verse()

SCRIPTS

Top

name2verse.pl, name2verse_nonprofane.pl

AUTHOR

Top

	Tim Maher
	Consultix
	yumpy@cpan.org
	http://www.teachmeperl.com

SEE ALSO

Top

http://www.geocities.com/SunsetStrip/Palladium/1306/shirley.htm

LICENSE

Top

Copyright (c) 2002, Timothy F. Maher. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


Lingua-EN-Namegame documentation Contained in the Lingua-EN-Namegame distribution.

# Namegame.pm module
#########################################################+
#      From the CONSULTIX "Perl Programming" class      #+
# POB 70563, Seattle WA 98107 USA tim@consultix-inc.com #+
#  Copyright 1997-2001, Tim Maher. All Rights Reserved  #+
#########################################################+
# Tim Maher, tim@teachmeperl.com

package	Lingua::EN::Namegame;

use 5.006;	# 5.6.0 needed for "our" keyword
use strict;
use warnings;
use Carp;

require	Exporter;

our @ISA		=	qw(Exporter);
our @EXPORT		=	qw(name2verse);
our @EXPORT_OK		=	qw( );
our $VERSION		= 	'0.05';

our ($SEP);

# name_game
# A program that generates a rhyming verse from a name,
# as in the famous song "The Name Game", by Shirley Ellis

# Inspired by "One-Liner #40", in TPJ #15, Fall 1999, p. 11.
#  by Sean M. Burke:
#   s<^([bcdfghjklmnpqrstvwxyz]*)(\w+).*>
#   <$1$2 $1$2 $1o $1$2 / Bonana-Fanna-Fo-F$2 / Fe Fi Mo M$2 / $1$2!>i;

# Reworked by Tim Maher to comply with the
# rhyming rules of the song, as documented in 
# http://www.geocities.com/SunsetStrip/Palladium/1306/shirley.htm.

# GENERAL RULES:
# 1) Say the name twice 
#	"Dave  Dave"

# 2) Say "bo" and Name again, replacing Name's first letter by B
#	"Bo Bave"

# 3) Say Banana Fanna Fo Name, replacing Name's first letter by F
#	"banana Fanna Fo Fave"

# 4) Say Fee Fi Mo Name, replacing Name's first letter by M
#	"Fee Fi Mo Mave"

# 5) Say Name once more 
#	"Dave"


# ALTERNATE RULES, for Names Starting with B, F, or M
#   (e.g., Marsha)
# 2. B-names; instead of bo Bob, use Bo-ob
# 3. F-names; instead of Banana Fanna Fo Fred
#    -- Banana Fanna Fo-red
# 4. M-names; instead of Fee Fi Mo Marsha -- Fee Fi Mo-arsha


sub name2verse {

	my $name=shift;	# grab the name for making the verse
	my ($f, $s, $i, $rest, $verse);

	# need >= two word-chars, including one vowel
	unless ( defined $name  and
			$name =~ /[a-z][a-z]/i  and 
				$name =~/[aeiouy]/i ) {
		carp 'name2verse(): Name needs ',
			'two or more letters ',
			"including one vowel\n";
		return undef;
	}

	local $SEP="\n";	# meant to leak into sub indent() below
	# /^([bcdfghjklmnpqrstvwxyz]*)([a-zA-Z]+)/ 

	# Grab leading consonants (if present), and following vowels

	$name =~ /^\s*([b-df-hj-np-tv-z]*)([a-z]+)/i  or  return undef;

	$f="\u$1";	# force upper-case; "first" part (includes initial)
	$s="\L$2";	# force lower-case; "second" part
	$i=substr($f,0,1);	# force upper-case; "initial"
	$f ne '' and
		$rest=substr($f,1) . $s;	# "rest" of first part

	#print "I, rest, F, S = $i, $rest, $f, $s\n";
	# print "Using rule #2, for $f/$s\n";

	# Now construct the verse for this name

	# Rule #1: State name twice
	$verse="\u$f$s \u$f$s " . indent();

	# Rule #2: General Case; Rob -> Bo-Bob
	if ($i ne 'B') {
		$verse.="bo \uB$s, " . indent();
	}
	# Rule #2: Special Case For B-names; Bob -> Bo-ob
	else {
		$verse.="${i}o-$rest, " . indent();
	}

	# Rule #3: General Case; Tom -> Fo-Fom
	if ($i ne 'F') {			# Fo Fom
		$verse.="Banana Fanna Fo F$s, " . indent();
	}
	# Rule #3: Special Case for F-names; Fred -> Fo-red
	else {
		$verse.="Banana Fanna ${i}o-$rest, " . indent();
	}
	# Rule #4: General Case; Tom -> Mo-Mom
	if ($i ne 'M') {
		$verse.="Fee Fi Mo M$s\n\t";
	}
	# Rule #4: Special Case for M-names; Marsha -> Mo-arsha
	else {
		$verse.="Fee Fi Mo-$s\n\t";
	}
	$verse.="\U$f$s!";
	return $verse;
}
sub indent { return ${SEP}.=' '; }
1;

__DATA__

1;