Skip to content

Commit

Permalink
Add Alliteration Generator.
Browse files Browse the repository at this point in the history
This generator returns 2-word alliterative adjective/animal name pairs.

Code updated by @nubs to match standards of the project, but otherwise
code was written by @chadicus.

Closes #5.
  • Loading branch information
chadicus authored and nubs committed Jul 30, 2015
1 parent be07ce5 commit 2461641
Show file tree
Hide file tree
Showing 6 changed files with 849 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ The video game name generator is based off of [prior](http://videogamena.me/) [a
* *Neurotic Jackhammer Detective*
* *My Little Mountain Climber Conflict*
* *Small-Time Princess vs. The Space Mutants*

## Alliterative Names
The alliteration name generator is based off of a list of [adjectives](http://grammar.yourdictionary.com/parts-of-speech/adjectives/list-of-adjective-words.html) and a list of [animals](https://animalcorner.co.uk/animals/).

#### Examples
* *Agreeable Anaconda*
* *Disturbed Duck*
* *Misty Meerkat*
* *Prickly Pig*
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nubs/random-name-generator",
"description": "A library to create interesting, sometimes entertaining, random names.",
"keywords": ["random", "generator", "video game"],
"keywords": ["random", "generator", "video game", "alliteration"],
"authors": [
{
"name": "Spencer Rinehart",
Expand Down
59 changes: 59 additions & 0 deletions src/Alliteration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
namespace Nubs\RandomNameGenerator;

use Cinam\Randomizer\Randomizer;

/**
* Defines an alliterative name generator.
*/
class Alliteration implements Generator
{
/** @type array The definition of the potential adjectives. */
protected $_adjectives;

/** @type array The definition of the potential nouns. */
protected $_nouns;

/** @type Cinam\Randomizer\Randomizer The random number generator. */
protected $_randomizer;

/**
* Initializes the Alliteration Generator with the default word lists.
*
* @api
* @param \Cinam\Randomizer\Randomizer $randomizer The random number generator.
*/
public function __construct(Randomizer $randomizer = null)
{
$this->_randomizer = $randomizer;
$this->_adjectives = file(__DIR__ . '/adjectives.txt', FILE_IGNORE_NEW_LINES);
$this->_nouns = file(__DIR__ . '/nouns.txt', FILE_IGNORE_NEW_LINES);
}

/**
* Gets a randomly generated alliterative name.
*
* @api
* @return string A random alliterative name.
*/
public function getName()
{
$adjective = $this->_getRandomWord($this->_adjectives);
$noun = $this->_getRandomWord($this->_nouns, $adjective[0]);

return ucwords("{$adjective} {$noun}");
}

/**
* Get a random word from the list of words, optionally filtering by starting letter.
*
* @param array $words An array of words to choose from.
* @param string $startingLetter The desired starting letter of the word.
* @return string The random word.
*/
protected function _getRandomWord(array $words, $startingLetter = null)
{
$wordsToSearch = $startingLetter === null ? $words : preg_grep("/^{$startingLetter}/", $words);
return $this->_randomizer ? $this->_randomizer->getArrayValue($wordsToSearch) : $wordsToSearch[array_rand($wordsToSearch)];
}
}
233 changes: 233 additions & 0 deletions src/adjectives.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
adorable
adventurous
aggressive
agreeable
alert
alive
amused
angry
annoyed
annoying
anxious
arrogant
ashamed
attractive
average
awful
bad
beautiful
better
bewildered
black
bloody
blue
blue-eyed
blushing
bored
brainy
brave
breakable
bright
busy
calm
careful
cautious
charming
cheerful
clean
clear
clever
cloudy
clumsy
colorful
combative
comfortable
concerned
condemned
confused
cooperative
courageous
crazy
creepy
crowded
cruel
curious
cute
dangerous
dark
dead
defeated
defiant
delightful
depressed
determined
different
difficult
disgusted
distinct
disturbed
dizzy
doubtful
drab
dull
eager
easy
elated
elegant
embarrassed
enchanting
encouraging
energetic
enthusiastic
envious
evil
excited
expensive
exuberant
fair
faithful
famous
fancy
fantastic
fierce
filthy
fine
foolish
fragile
frail
frantic
friendly
frightened
funny
gentle
gifted
glamorous
gleaming
glorious
good
gorgeous
graceful
grieving
grotesque
grumpy
handsome
happy
healthy
helpful
helpless
hilarious
homeless
homely
horrible
hungry
hurt
ill
important
impossible
inexpensive
innocent
inquisitive
itchy
jealous
jittery
jolly
joyous
kind
lazy
light
lively
lonely
long
lovely
lucky
magnificent
misty
modern
motionless
muddy
mushy
mysterious
nasty
naughty
nervous
nice
nutty
obedient
obnoxious
odd
old-fashioned
open
outrageous
outstanding
panicky
perfect
plain
pleasant
poised
poor
powerful
precious
prickly
proud
puzzled
quaint
real
relieved
repulsive
rich
scary
selfish
shiny
shy
silly
sleepy
smiling
smoggy
sore
sparkling
splendid
spotless
stormy
strange
stupid
successful
super
talented
tame
tender
tense
terrible
testy
thankful
thoughtful
thoughtless
tired
tough
troubled
ugliest
ugly
uninterested
unsightly
unusual
upset
uptight
vast
victorious
vivacious
wandering
weary
wicked
wide-eyed
wild
witty
worrisome
worried
wrong
xenophobic
xanthous
xerothermic
yawning
yellowed
yucky
zany
zealous
Loading

0 comments on commit 2461641

Please sign in to comment.