> -----Original Message-----
> From: Rich Wild [mailto:[EMAIL PROTECTED]]

> Has anyone developed (in CF or otherwise) a random phrase or
sentence
> generator?

I did a simple hack, which proved fun (but v.slow) for a while.
(look at http://www.sincity.com/penn-n-teller/pcc/shaney.html, and do
a search for "Mark V. Shaney" on google)

Set up a table as such, with the following field,

word1, word2, word3, word4.

Now scan through a large block of text (Poems, Wordsworth, usenet
etc), start with the first word, put it, and the following three words
into the table.  So for something like "Once upon a time, in a land
far, far away" You'd end up with...

word1   word2   word3   word4
~~~~~ ~~~~~ ~~~~~ ~~~~~
Once    upon    a       time,
upon    a       time,   in
a       time,   in      a
time,   in      a       land
in      a       land    far,
a       land    far,    far
land    far,    far     away


The code that generates the text works along the following lines
(tweaked if you don't get any matches)...

Give it three words (i.e.. "Once", "upon" & "a")

<cfset word1 = "Once">  //  Set the first three words here
<cfset word2 = "upon">  //
<cfset word3 = "a">     //

<cfoutput>#word1# #word2# #word3#</cfoutput>

<!--- Starting a loop here would be a good idea --->
<cfquery name="getWord">
  SELECT word4
  FROM wordCollection1
  WHERE word1 = '#word1#'
  AND word2 = '#word2#'
  AND word3 = '#word3#'
</cfquery>

<!--- pick a random word 4 from the records returned (add checking for
no records --->
<cfset word4 = getWord.word4[randRange(1,getWord.recordCount)]>

<cfoutput>#word4#</cfoutput>

<!--- shift the words to get a new set of three --->
<cfset word1 = word2>
<cfset word2 = word3>
<cfset word3 = word4>

<!--- Go and do it all again, until you die, or some such --->

-------------------------------------------------------------

With a very small amount of sample text, you basically get spat back
at you exactly what go put in.  If you use too much text, then the
results will seem too much like random waffle.  With a sample text
size of about 2000-3000 you can get a very interesting result, which
sounds it should make some kinda of sense.

I did this with Jeff Noons books, the results while different, did
seem to be in the style of Jeff Noon :)

I stopped the project as there was too many hits to the database (as
you can see).  I've been waiting until I install CF5, so I can cache a
query pulling all the rows out of the table, and then query that.



This message is intended only for the use of the person(s) ("the intended 
recipient(s)") to whom it is addressed.

It may contain information which is privileged and confidential within the meaning of 
the applicable law. 
If you are not the intended recipient, please contact the sender as soon as possible.
The views expressed in this communication may not necessarily be the views held by 
Live Information Systems Limited.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to