#By Erik Nelson, June 12, 2006
#This is an experiment in random sentence generators.
#The data structure is a list of lists, with the substitutable thing at the 
#head of each one and things it can turn into on that list.

#The next thing to do: make it a recursive grammar.
#This entails I must make the substitution loop into a function
#so I can cycle it through several times.

import random

vocab = [] #an empty list to begin with
vocab.append(["#p", "\n  It can be shown that #s This is true even though the #n says #s . However, #s", "\n In spite of it all, #s #s But even a #n will #v .", "\n In conclusion, #s but #s ", "#s #s But #s Furthermore, the #n doesn't believe that #s","#s #p", "#p #p","\n All this is meaningless and #a because the #n says #s To say #s would be an oversimplification."])
vocab.append(["#s", "The #a #n likes to #v .", "A #n can't #v if it has a #n !", "Also, the #a #n is a #n .","It isn't true that #s","A #n is a #a #n that can #v .","I have decided to become a #n even though I don't #v .", "People who #v do so at their own risk because of a #n .","I can't #v with a #n .","A #n can't #v because of a #n .","The #n will never learn not to #v .","A #n and a #n can't #v together if one of them is more #a than the other.","I am a #n .","The #n can #v ."])
vocab.append( ["#n", "apple","banana","car","dog","eel","frog","grape","#n that isn't #a","#n that can't #v","rock","hammer", "snowball","brick","map" ,"thing","house","#n -eater"] )
vocab.append( ["#v", "amble","bark at a #n","cry","dump on a #n until it turns #a","eat a #n","fly like a #n","absquatulate","vomit","#v until the #n comes home","fail to #v","#v like a #n", "become #a","be a #n","walk","write","speak", "say a #n is like a #n","ride a #n","run","go shopping"] )
vocab.append( ["#a", "able","big","circular","dry","eerie","fluid", "un- #a","green","jumpy","fetid","squamous","raucous","wet","#n -like","flat","round", "#n -shaped","strange","enormous","overt"] )



teststring ="#p #p \n #s But #s Furthermore, the #n doesn't believe that #s"
print teststring, "\n The above is the ORIGINAL STRING"

def replacetokens(instring):
	stringbreakup = instring.split(" ")
	#print stringbreakup

	newword=""
	buildlist = []
	for i in stringbreakup:    
#each i is a word in the list of source words
		newword = i 
#and it remains unchanged unless it's a token
		for j in vocab:		
#each j is a LIST in the listoflists vocab
			if i == j[0]:	
#so j[0] is the substitutable token
				newword = random.choice(j[1:]) 
				#so newword is a choice from list j 
				#if the word is changed.
		
		buildlist.append(newword)
		

	#print buildlist

	#print "====================="
	#print "and now we join the words."

	outstring = " ".join(buildlist)
	return outstring

evolvestring = teststring
for i in range(1,20):
	teststring = replacetokens(teststring)
	print "\nThe ", i, "th iteration is============\n\n",teststring
print "\n"
	


    Source: geocities.com/eriknelson2002/RandomSentences

               ( geocities.com/eriknelson2002)