The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 16, 2019, 09:58:58 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: markov class/function?  (Read 4129 times)
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« on: November 10, 2007, 10:58:40 PM »

So. anyone have one for PHP. come on now, i know a bunch of you do.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: November 10, 2007, 11:30:33 PM »

::shifts in the shadows, ears perk up. Waits patiently for the bunny::
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #2 on: November 11, 2007, 08:15:33 AM »

lol. I know RSSGM has one in it, but I am just looking for a self contained one. google insnt being helpful at the moment.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
arms
Expert
****
Offline Offline

Posts: 235



View Profile
« Reply #3 on: November 11, 2007, 09:38:55 AM »

yacg has one. i don't know how closely related it is to the rssgm one.
Logged
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #4 on: November 11, 2007, 10:24:32 AM »

ah yes, yacg. though, do I want to be downloading something from busin3ss... lol
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
deregular
Expert
****
Offline Offline

Posts: 172


View Profile
« Reply #5 on: November 11, 2007, 10:08:24 PM »

Here nb, I just stripped it from the markov hook in yacg and threw a couple of @'s in there to suppress errors. Works though.

Code:
function markov($combo,$gran = '2', $num = '200') {
$i = "";
$nr_files = "";

//$combo = utf8_encode($combo);
$combo = htmlentities($combo);
$combo = preg_replace('/\s\s+/', ' ', $combo);
$combo = preg_replace('/\n|\r/', '', $combo);
$chickenfeet=explode(".",$combo);
shuffle($chickenfeet);
$combo="";
$combo=implode(".",$chickenfeet);
$G = $gran;
$O = $num;
$output = "";
$combo = $combo;
$LETTERS_LINE = 65;
$textwords = array();
$textwords = explode(" ", $combo);
$loopmax = count($textwords) - ($G - 2) - 1;
$frequency_table = array();
for ($j = 0; $j < $loopmax; $j++) {
$key_string = "";
$end = $j + $G;
for ($k = $j; $k < $end; $k++) {
$key_string .= $textwords[$k].' ';
}
@$frequency_table[$key_string] .= $textwords[$j + $G]." ";
}
$buffer = "";
$lastwords = array();
for ($i = 0; $i < $G; $i++) {
$lastwords[] = $textwords[$i];
$buffer .= " ".$textwords[$i];
}
for ($i = 0; $i < $O; $i++) {
$key_string = "";
for ($j = 0; $j < $G; $j++) {
$key_string .= $lastwords[$j]." ";
}
if (@$frequency_table[$key_string]) {
$possible = explode(" ", trim($frequency_table[$key_string]));
mt_srand();
$c = count($possible);
$r = mt_rand(1, $c) - 1;
$nextword = $possible[$r];
$buffer .= " $nextword";
if (strlen($buffer) >= $LETTERS_LINE) {
$output .= $buffer;
$buffer = "";
}
for ($l = 0; $l < $G - 1; $l++) {
$lastwords[$l] = $lastwords[$l + 1];
}
$lastwords[$G - 1] = $nextword;
} else {
$lastwords = array_splice($lastwords, 0, count($lastwords));
for ($l = 0; $l < $G; $l++) {
$lastwords[] = $textwords[$l];
$buffer .= ' '.$textwords[$l];
}
}
}

return trim($output);
}
Logged
leadegr00t
n00b
*
Offline Offline

Posts: 8



View Profile WWW
« Reply #6 on: November 12, 2007, 06:11:27 AM »

Is this any use?
http://www.boogybonbon.com/2007/11/09/php-markov-chain-class/
Smiley
Logged

No links in signatures please
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #7 on: November 12, 2007, 08:52:22 AM »

thanks guys, those will work.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!