Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
function Markov($text){
$len1=strlen($text);
for ($mar=0; $mar<10; $mar++){
$itog="";
$maxgen = 8888;
$nonword = "\n";
$w1 = $nonword;
$w2 = $nonword;
$words = explode(" ", $text);
foreach( $words as $word) {
$table[$w1][$w2]["xanax"][] = $word;
$w1 = $w2;
$w2 = $word;
}
$table[$w1][$w2]["xanax"][] = $nonword;
$w1 = $nonword;
$w2 = $nonword;
for($i = 0; $i < $maxgen; $i++) {
$suf = $table[$w1][$w2]["xanax"];
$t = array_rand($suf);
if($suf[$t] == $nonword) break 1;
$itog.=$suf[$t]." ";
$w1 = $w2;
$w2 = $suf[$t];
}
$len2=strlen($itog);
$len2=$len2*2;
if ($len2>$len1) {break; }
}
return $itog;
}
function GetMapPanel($mapname, $tek, $all){
for ($p=0; $p<$all; $p++){
$p2=$p+1;
if ($p*1 != $tek*1) {$pan="<a href='".$mapname.$p.".html'>[".$p2."]</a>";} else
{$pan="[".$p2."]";}
$itt.=$pan." ";
}
return $itt;
}
<?php error_reporting(0); ?>
<html>
<head>
<title></title>
</head>
<body>
<form method="POST">
<textarea name="textarea" cols="40" rows="4"></textarea><input type="text" name="len" size="24" value="50"><input type="submit">
</form>
<?
mt_srand((double)microtime()*1000000);
class Markov
{
var $source_text="";
var $links = array();
var $dictionary = array();
function load()
{
if ($this->source_text)
{
$this->source_text = preg_replace("/[\r\n\|]/s"," ",$this->source_text);
$this->source_text = trim(preg_replace("/[ ]+/s"," ",$this->source_text));
preg_match_all("/((\"[^\"]+\")|(\([^\)]+\))|([^\(\)\"'\s]+))(\s+|\z)/s",$this->source_text,$parts);
$words=$parts[1];
$count=count($words);
$prev_num=0;
$j=0;
for($i=0;$i<$count;$i++)
{
$num=array_search($words[$i],$this->dictionary,TRUE);
if ($num===false)
{
$this->dictionary[$j]=$words[$i];
$num=$j;
$j++;
}
if ($i>0)
{
if (!is_array($this->links[$prev_num])) $this->links[$prev_num]=array();
if ($num!=$prev_num) array_push($this->links[$prev_num],$num);
}
$prev_num=$num;
}
}
else return;
}
function genRaw($max_length)
{
if (!count($this->dictionary)) $this->load();
if (!($dict_cnt=count($this->dictionary)) || !($link_cnt=count($this->links))) return "";
$totalCount=0;
$totalLength=0;
$num=mt_rand(0,$dict_cnt-1);
$text="";
while($totalLength<$max_length)
{
$add_str=" ".$this->dictionary[$num];
$totalLength+=strlen($add_str);
$text.=$add_str;
$totalCount++;
if ($num<$link_cnt)
{
$j=count($this->links[$num]);
if ($j)
{
$i=mt_rand(0,$j-1);
$num=$this->links[$num][$i];
}
else $num=mt_rand(0,$dict_cnt-1);
}
else $num=mt_rand(0,$dict_cnt-1);
}
return trim($text);
}
}
$markov = new Markov();
$source = $_POST['textarea'];
$block_len = $_POST['len'];
//$source = "this is source text - you need get it from file or from web";
$markov->source_text = $source;
$result=$markov->genRaw($block_len);
echo "<br><br><br>";
echo $result;
?>
</body>
</html>