module Markovian
The base module.
The Chain
represents Markov info as it’s being assembled or expanded from a text. To compensate for small sample sizes, we track multiple chains (derived from both two-word phrases and single word). Phrases are prefered, but if we can’t find a match, we’ll try with a single word.
Given a piece of text, this class returns a hash of Markov results: two-word phrases (two by default) pointing to an array of historical next words.
So, for instance, the phrase “Cats are cute, cats are annoying” would map to: {
"cats are" => [cute, annoying], "are cute" => [cats], "cute cats" => [are],
}
Notes:
-
Next words (in v1) are not unique, in order to represent weighting. There are definitely more space-compact ways to do that, but that’s left for future implementation.
-
Punctuation is for later.
-
Handling sentences or newlines is later – I’m not sure the right way to do it.
-
Capitalization is deferred for later.
This class represents a dictionary of words or phrases and the various words that can follow them. The key is an opaque value, which could represent either a single word or a phrase as desired.
This class, given a Markov chain, will attempt to construct a new text based on a given seed using the Markov associations.
Constants
- VERSION