home *** CD-ROM | disk | FTP | other *** search
/ Between Heaven & Hell 2 / BetweenHeavenHell.cdr / 300 / 245 / brekdown.doc < prev    next >
Text File  |  1985-02-06  |  9KB  |  150 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.                                      BREAK DOWN
  8.                        A text analysis and generation program
  9.                                written in TURBO Pascal
  10.                         copyright 1985 by Neil J.  Rubenking
  11.  
  12.                                 requires DOS 2.0, 96K
  13.  
  14.           I.AN ANALOGY
  15.                There  is  a  fairly  commonly  believed  "fact" that if you
  16.           set  millions  of  monkeys  typing  at  random  on   millions  of
  17.           typewriters for  millions of  years, they  would eventually crank
  18.           out all the world's  great literature.   Deep  down inside, BREAK
  19.           DOWN is  just one  of those monkeys, but this monkey is educated.
  20.           BREAK DOWN "reads" a text  and  creates  a  frequency  table that
  21.           gives it  some method  in its madness.  The output can be surpri-
  22.           singly similar to the input.  
  23.  
  24.           II.  WHAT DOES IT DO?
  25.                To analyze a text, BREAK  DOWN  looks  at  it  in  chunks of
  26.           a particular  size (one less than the "order") and keeps a record
  27.           of what characters occur  immediately  after  that  pattern.   If
  28.           the  chunk  is  new  to  the  frequency table, it is added to the
  29.           table.  Its frequency  array is  initially all  zeros, except for
  30.           the  current  next  character.    If  the chunk already exists in
  31.           the table, its frequency array  is  incremented  by  one  for the
  32.           current next  character.  Then the "chunk" is shifted one charac-
  33.           ter to the right and the process goes on -- that is,  the chunk's
  34.           first  character  is  dropped  and  the  current  next  character
  35.           is tacked onto the end.
  36.  
  37.           III. WHAT MAKES IT SPECIAL?
  38.                Checking to see if  the chunk  is present  would be  quite a
  39.           task if  the frequency  table were stored sequentially.  Fortuna-
  40.           tely, BORLAND International sells a product  called TURBO TOOLBOX
  41.           that implements  fast indexed  storage, using  the B-Tree system.
  42.           (For a discussion of B-Tress and TURBO TOOLBOX,  see the February
  43.           1985 PC  Tech Journal).   The  chunks of  text are  stored in the
  44.           B-Tree index file -- they are the KEYS.   The  data file contains
  45.           only the  frequency arrays.   Ordinarily,  the KEYS would also be
  46.           stored in the data file,  but  this  redundancy  is  not strictly
  47.           necessary.    Since  the  data  file  can conceivably contain one
  48.           record for every BYTE in the source, we  want to  keep the record
  49.           size to  a minimum.  (This "worst case" would occur if NO pattern
  50.           in the text occurred more than once.)
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.           IV.  WHAT ARE THE INPUT LIMITS?
  58.                At present, BREAK DOWN  tracks  34  characters.    These are
  59.           the  26  lower-case  alphabetic  characters,  the  space, period,
  60.           comma, dash, question mark, number symbol  and single  quote, and
  61.           ASCII character  20, the  paragraph symbol.  If a line is shorter
  62.           than the  constant  "LineWidth"  (currently  set  to  55),  it is
  63.           considered to have ended "early" with a hard Carriage Return, and
  64.           is marked  with the  paragraph symbol  at the  end.   In the pre-
  65.           processing phase (procedure "CleanUp"), all letters are converted
  66.           to lower-case, all numbers are  reduced  to  a  single  # symbol,
  67.           double quotes become single quotes, and all unused punctuation is
  68.           removed.  It would, of course, be possible to track  more charac-
  69.           ters, but each character adds a byte to every record.
  70.  
  71.           V.   HOW DOES IT WORK?
  72.                To  generate  a  new  text,  BREAK  DOWN selects at random a
  73.           KEY that begins with  a space  (i.e., one  that doesn't  start in
  74.           the middle  of a word.)  It then looks up the frequency array for
  75.           that KEY and  selects  the  next  character  at  random  from the
  76.           characters with  non-zero frequency, weighted by the frequencies.
  77.           This character is added to the  current output  line, and  to the
  78.           current KEY  chunk.   If the paragraph symbol is encountered, the
  79.           line is automatically ended.  Also, the current line ends  at the
  80.           first space  encountered after its length surpasses the LineWidth
  81.           constant.  The first alphabetic character after a period,question
  82.           mark, or line end is capitalized.
  83.  
  84.           VI.  HOW SHOULD I SET IT UP?
  85.                BREAK DOWN  is a prime candidate for RAMDisk operation.  The
  86.           B-Tree file access  limits  the  number  of  disk  accesses quite
  87.           a  bit,  but  there  are  still several accesses for each BYTE in
  88.           the source file.  The data  file of  a text  under 10K  in length
  89.           will  definitely  fit  on  one  floppy,  but  an  11K  file could
  90.           conceivably run over that length.   You are  expected to  be sure
  91.           you have  enough space.  You may distribute your files to various
  92.           disk drives -- a likely  arrangement  is  .DAT  file  on  drive B
  93.           and source, .INX file, and BREAK DOWN program on drive A.
  94.  
  95.           VII. TIPS FOR USE
  96.                The  higher  the  order,  the  more  intelligible the output
  97.           will be.   However,  a high  order and  a short  text will mostly
  98.           just  regenerate  the  original.    Experiment with various texts
  99.           and various orders.  You can  use the  [L]ist option  to see just
  100.           what sort  of records  are being  generated.  BREAK DOWN has been
  101.           tried on a 100K text file, with the Order set  to the  maximum of
  102.           8.   It took over 6 hours and generated a 1.8 megabyte data file,
  103.           but it worked.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.           VIII.     DEFAULT OPTIONS
  111.                BREAK DOWN will prompt you for the Order each time  you make
  112.           a selection  from the menu.  After you have entered an Order, you
  113.           can just hit <return> for the previous value.  The MAIN file name
  114.           works the  same way -- after the first time you enter it, hitting
  115.           <return> will  recall the  same name.   The default  for the .DAT
  116.           and .INX  drives, and the output file, if any, is the same as the
  117.           source file.  Thus, if you have  [A]nalyzed a  text with  all its
  118.           files on one drive, you can fill in the blanks for [G]enerating a
  119.           travesty by repeatedly hitting <return>.
  120.  
  121.           IX.  ADVANCED (?) USE
  122.                The [M]erge option lets you combine two data files, possibly
  123.           from  wildly  different  sources.    The  data and index files of
  124.           the"source" will be permanently changed, so you may  want to keep
  125.           a copy.   You  can also  "read in"  another text into an existing
  126.           data file.   Use  this  option  to  build  up  a  frequency table
  127.           "model" of a particular author, or to make bizarre hybrids.
  128.  
  129.           X.   WHAT'S IT GOOD FOR?
  130.                BREAK  DOWN  is  a moderately sophisticated database program
  131.           with almost no "serious" uses.  However, there  are all  kinds of
  132.           non-serious uses  for it.   Read  in three  or four "letters from
  133.           camp" and then let the PC generate more.   Generate  new speeches
  134.           based  on  Our  President's  proclamations.   Find out what Lewis
  135.           Carroll would have written had he been a Zen Master.   Or examine
  136.           the program  itself to  see how  the TURBO TOOLBOX can be used to
  137.           manage other sorts of data.  
  138.  
  139.           XI.  CREDITS
  140.                This  program  was  inspired  by  the  TRAVESTY  program  in
  141.           the November  1984 BYTE  magazine, by  Kenner and O'Rourke.  They
  142.           in turn were inspired by an article in the Scientific American of
  143.           November  1983  by  Brian  Hayes.   Both these articles make good
  144.           reading.  TURBO  TOOLBOX  and  TURBO  Pascal  are  available from
  145.           BORLAND International, 4113 Scotts Valley Road, Scotts Valley, CA
  146.           95066.  BREAK DOWN itself was  written  by  Neil  J.   Rubenking.
  147.           This program may be freely used and copied, but I retain the sole
  148.           right to SELL it.  Users Groups and  Software Clubs  may charge a
  149.           reasonable price for the disk and copying/handling charges.   
  150.