<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/python

import random
import types


def Eval(item):
  if type(t) is str:
    return t

  if hasattr(item, 'values'):
    slot = random.uniform(sum(item.values()))
    for selection, weight in item.items():
      slot -= weight
      if slot &lt;= 0:
        return Eval(selection)

  return Eval(random.choice(t))

Noun = (
  'act',
  'ad',
  'ale',
  'ant',
  'arm',
  'ax',
  'bag',
  'bat',
  'bed',
  'bey',
  'boy',
  'cad',
  'cam',
  'can',
  'cap',
  'car',
  'cat',
  'cat',
  'cog',
  'dad',
  'dam',
  'dog',
  'dud',
  'ed',
  'fig',
  'fun',
  'gal',
  'gem',
  'gnu',
  'goo',
  'gum',
  'hat',
  'hex',
  'hub',
  'hut',
  'ice',
  'id',
  'jet',
  'kid',
  'lip',
  'log',
  'mac',
  'man',
  'mop',
  'nap',
  'owl',
  'ox',
  'paw',
  'pet',
  'pie',
  'pie',
  'pup',
  'rib',
  'spa',
  'sum',
  'tar',
  'tie',
  'tin',
  'toe',
  'top',
  'top',
  'tot',
  'tux',
  'yen',
  'zoo',
)

Determiner = (
  'a',
  'her',
  'his',
  'its',
  'my',
  'our',
  'the',
)

Joiner = (
  'and',
  'at',
  'ate',
  'for',
  'got',
  'had',
  'in',
  'is',
  'met',
  'of',
  'on',
  'or',
  'saw',
  'to',
  'was',
  'wed',
  'wet',
)


Adj = (
  'bad',
  'big',
  'fey',
  'hot',
  'new',
  'odd',
  'old',
  'one',
  'pop',
  'rad',
  'red',
  'sad',
  'tan',
  'toy',
  'wow',
)

SubjectPronoun = (
  'he',
  'i',
  'it',
  'she',
  'we',
  'you',
)

ObjectPronoun = (
  'her',
  'him',
  'it',
  'me',
  'us',
  'you',
)

#Sentence = Sequence(
#  SelectRandom(

#PerhapsAdjNone = Sequence(
#  SelectWeighted({Empty: 60, Adj: 40}),
#  Noun

AdjNoun = Sequence(Determiner, PerhapsAdj, Noun)

Sentence = Sequence(AdjNoun, Joiner, AdjNoun)

LOOPS = 32

def AToAn(word, next_word=''):
  if word == 'a' and next_word and next_word[0] in 'aeiou':
    return 'an'
  else:
    return word

def AToAnSentence(words):
  if words:
    for i in xrange(len(words) - 1):
      yield AToAn(words[i], words[i + 1])
    yield words[-1]

for i in xrange(LOOPS):
  s = Sentence()
  s = AToAnSentence(list(s))
  print ' '.join(list(AToAnSentence(Sentence()))).capitalize() + '.'
  # print ' '.join(Sentence()).capitalize() + '.'


perhaps_adj_len = 1 + len(Adj)
adj_noun_len = len(Determiner) * perhaps_adj_len * len(Noun)
total_len =  adj_noun_len * len(Joiner) * adj_noun_len

print "Total search space:"
print "perhaps_adj_len", perhaps_adj_len
print "adj_noun_len", adj_noun_len
print "total_len", total_len
</pre></body></html>