Paste: markov-mini

Author: bb
Mode: factor
Date: Sat, 27 Dec 2008 21:04:00
Plain Text |
: add-line ( chain line -- chain )
    " " split 2 clump [ first2 1 2 [ swap associate ] times [ '[ swap _ [ H{ } clone or [ '[ swap _ at+ ] assoc-each ] keep ] change-at ] assoc-each ] keep ] each ;

: walk ( chain word -- response )
    0 -rot [ dupd swap at dup [ >alist [ swap ] assoc-map random-weighted* ] [ ] if rot 1+ dup 15 < [ -rot ] dip dupd and ] [ dup ] [ 3drop ] produce " " join ;

! H{ } "I love python" add-line "I love factor" add-line "I love python a lot" add-line "I" walk -- "love python a lot"

New Annotation

Summary:
Author:
Mode:
Body: