Skip to content

mcmillhj/markov-perl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

NAME
    Markov::Chain

DESCRIPTION
    Given a scalar that contains a text sample (preferably a large one),
    generates new text from the sample using Order-2 Markov Chains

METHODS
    seed
        "seed" the text generator by creating Order-2 Markov Chains from the
        sample text. This step generates a hashref where the keys are every
        2-word phrase in the sample text, and the values an arrayref of all
        the values that follow those 2-word phrases in the text.

        For example, given a text of: "If debugging is the process of
        removing software bugs, then programming must be the process of
        putting them in"

           {  'of putting'        => ['them'],
              'must be'           => ['the'],
              'is the'            => ['process'],
              'then programming'  => ['must'],
              'If debugging'      => ['is'],
              'be the'            => ['process'],
              'bugs, then'        => ['programming'],
              'putting them'      => ['in'],
              'programming must'  => ['be'],
              'debugging is'      => ['the'],
              'software bugs,'    => ['then'],
              'removing software' => ['bugs,'],
              'the process'       => ['of','of'],
              'process of'        => ['removing','putting'],
              'of removing'       => ['software'],
           };

    generate
        "creates" new text based on the sample text and Order-2 Markov Chain
        hashref above by choosing a random starting place then "chaining"
        through the hashref by combining words.

        For example, if we started with word1 = 'of' and word2 = 'putting',
        we would save word1 as the first word of the new text. Word1 and
        word2 are combined to get a list of values to choose a new word from
        in this case "of putting" gives a single value 'them' which is then
        chosen to become the new word2, if there were more than a single
        value it would be chosen randomly. Word2 becomes the new word1 and
        the process repeats until we reach a new text of the specified size.

About

Text generator using 2-order Markov chains

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages