A simple Markov Chain for text generation in Clojure
A simple Markov Chain for text generation in Clojure
(add-entry dictionary entry)
Update dictionary
with an entry
tuple.
If the look-up already exists, cons the current transition to the list of transitions
Update `dictionary` with an `entry` tuple. If the look-up already exists, cons the current transition to the list of transitions
(build-markov-dictionary tuple-set)
Collapse tuple-set
into a look-up dictionary
Collapse `tuple-set` into a look-up dictionary
(concat-with-space s1 s2)
Return s1
concatenated with s2
with a space between the two strings
Return `s1` concatenated with `s2` with a space between the two strings
Regex pattern to find words that start sentences
Regex pattern to find words that start sentences
(load-data! path window-length)
Load the file at path
and split it into tuples of size window-length
Load the file at `path` and split it into tuples of size `window-length`
(markov-sentence sentence-starters sentence-bodies window-length)
Build a sentence starting with a random element in sentence-starters
, and
recursively navigate the markov model in sentence-bodies
, whose transition windows
are sized by window-length
Build a sentence starting with a random element in `sentence-starters`, and recursively navigate the markov model in `sentence-bodies`, whose transition windows are sized by `window-length`
(markov-sentences sentence-starters sentence-bodies window-length sentences)
Generate sentences
repeatedly
Generate `sentences` repeatedly
This is a loose regex detection for string terminators. Needs to be more robust
This is a loose regex detection for string terminators. Needs to be more robust
(search-text stem window-length)
Take window-length
words from the end of sentence
to use as the look-up for the next markov transition
Take `window-length` words from the end of `sentence` to use as the look-up for the next markov transition
(sentence-ended? text)
Boolean predicate that returns true iff text
contains terminal punctuation
Boolean predicate that returns true iff `text` contains terminal punctuation
(single-window-to-tuple window)
Split window
into a look-up and a transition tuple
Split `window` into a look-up and a transition tuple
(starts-sentence? text-window)
Boolean predicate that returns true iff the first word of text-window
starts with a capital letter
Boolean predicate that returns true iff the first word of `text-window` starts with a capital letter
(string-to-sliding-window string window-length)
Convert string
into a series of sliding windows that will be sliced into
a window and a transition word, hence incrementing the partition window.
Convert `string` into a series of sliding windows that will be sliced into a window and a transition word, hence incrementing the partition window.
(write-sentences tuples window-length copies)
Generate copies
sentences from the tuples
where each transition window is window-length
Generate `copies` sentences from the `tuples` where each transition window is `window-length`
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close