NAME
StupidMarkov - A stupid Markov chain implementation.
SYNOPSIS
use StupidMarkov;
my $mm = StupidMarkov->new();
while (my $line = <>) {
chomp $line;
next if !defined $line;
foreach my $word (split(/ /, $line)) {
$mm->addItem($word);
}
}
print $mm->getNextItem(), " " for (0 .. $mm->getItemCount());
DESCRIPTION
BIG FAT NOTE: THIS IS A /REALLY/ STUPID IMPLEMENTATION! It works (for the most part) for me. I didn't write it to be a complete implementation, or even a sane one. If you're looking for something other than a toy, please check the SEE ALSO section for ideas, or search CPAN for something else. =o)
StupidMarkov is a really simply and really stupid implementaiton of a Markov chain that I wrote in a fit of insomnia at midnight, after realizing I'd never understood what a Markov chain was, spending five minutes reading the Wikipedia entry on it, and then taking ten minutes to implement it. The output using the above synopsis and this paragraph results in output like the following:
"is a fit of insomnia at midnight, after realizing I'd never
understood what a really stupid implementaiton of insomnia at
midnight, after realizing I'd never understood what a Markov chain
that I wrote in a Markov chain that I wrote in a Markov chain that I
wrote in output like the Wikipedia entry on it, and this paragraph
results in a Markov chain that I wrote"
METHODS
- new
-
Create a new StupidMarkov chain.
- getItemCount
-
Return the number of items that have been added to the chain. Note that this number is cumulative, and does not count uniqueness.
- getProbabilities
-
Return a reference to the internal probability hash of items to hash of next items to integer probabilities. Probably not very useful.
- getState
-
Return the current item that is used as the internal state.
- addItem
-
Add an item to the Markov chain.
- getNextItem
-
Generate the next item in the Markov chain. Takes an optional argument that represents the start state. If no argument is provided, the first item passed to addItem is used instead.
REFERENCES
Wikipedia: http://en.wikipedia.org/Markov_chain
REVISION HISTORY
SEE ALSO
Please consider using the below, as they are much better implementations than StupidMarkov could ever hope to be.
AUTHOR
June R. Tate-Gans <june@theonelab.com>
LICENSE
Copyright 2009 June R. Tate-Gans, all rights reserved.
StupidMarkov is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNEESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have recieved a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
BUGS
Please report any bugs or feature requests to bug-stupidmarkov at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=StupidMarkov. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc StupidMarkov
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN