StupidMarkov - A stupid Markov chain implementation.
use StupidMarkov; my $mm = StupidMarkov->new(); while (my $line = <>) { chomp $line; next if !defined $line; foreach my $word (split(/ /, $line)) { $mm->add_item($word); } } print $mm->get_next_item(), " " for (0 .. $mm->get_item_count());
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"
Create a new StupidMarkov chain.
Return the number of items that have been added to the chain. Note that this number is cumulative, and does not count uniqueness.
Return a reference to the internal probability hash of items to hash of next items to integer probabilities. Probably not very useful.
Return the current item that is used as the internal state.
Add an item to the Markov chain.
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 add_item is used instead.
Wikipedia: http://en.wikipedia.org/Markov_chain
2009-05-10: Integrating apeiron's camel case is evil patch. Note that this represents an API change.
2009-05-02: First implementation and insomnia effect.
Please consider using the below, as they are much better implementations than StupidMarkov could ever hope to be.
June R. Tate-Gans <june@theonelab.com>
<june@theonelab.com>
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.
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.
bug-stupidmarkov at rt.cpan.org
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
http://rt.cpan.org/NoAuth/Bugs.html?Dist=StupidMarkov
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/StupidMarkov
CPAN Ratings
http://cpanratings.perl.org/d/StupidMarkov
Search CPAN
http://search.cpan.org/dist/StupidMarkov
To install StupidMarkov, copy and paste the appropriate command in to your terminal.
cpanm
cpanm StupidMarkov
CPAN shell
perl -MCPAN -e shell install StupidMarkov
For more information on module installation, please visit the detailed CPAN module installation guide.