- GoFuckBiz.info

  - GoFuckBiz.info > - > ,
, ,

03.06.2010, 17:21   #1
jskorvin
 
  jskorvin
 
: 05.03.2009
: 365
: $45938
Question


PHP :
<?
Class MarkovChains{
    var 
$prepared = array();
    function 
MarkovChains($source){
        
$source strtolower($source);
        
$source str_replace(array ("? ""! "), "."$source);
        
$source str_replace(array (" -""- ""\t""\r""\n""|""&"'\\''/'" :"" ;"""""), ' '$source);
        
$source str_replace(array (")""(""]""[""'""\""'*''''~''{''}'), ''$source);
        
$source str_replace(" ,"","$source);
        
$source preg_replace("~(\s+\d{1,2}\s+)|(\w*\.\w+)~"" "$source);
        
$source preg_replace("~\s+~"" "$source);$sentens explode('. '$source);
        
$count_sentens count($sentens);
        for (
$j=0$j<$count_sentens; ++$j){
        
$sentens[$j] = explode(' '$sentens[$j]);
            
$count_words count($sentens[$j]) - 1;
            for (
$i=0$i $count_words; ++$i){
                
$prefix $sentens[$j][$i];
                
$this->prepared[$prefix][] = $sentens[$j][$i+1];
            }
        }
        
$keys array_keys($this->prepared);


        foreach (
$keys as $key){
            
$this->prepared[$key] = array_unique($this->prepared[$key]);
        }
    }
    function 
GenerateText($size){
        
$result_count 0;
        for (
$j=0$result_count $size; ++$j){
            
$prev array_rand($this->prepared);
            
$num mt_rand(512);
            for (
$i=0$i<$num; ++$i){
                
$sents[$j][$i] = $prev;
                ++
$result_count;
                
$p $this->prepared[$prev][mt_rand(0count($this->prepared[$prev]) - 1)];
                if (
$p == ''$p array_rand($this->prepared);
                
$prev $p;
                if (
$prev == '') break 2;
            }
        }
        foreach (
$sents as $sent){
            
$count_word=count($sent);
            if (
$count_word<=2) continue;
            if (
strlen($sent[$count_word-1]) < 4) unset($sent[$count_word-1]);
            
$sent[$count_word-2] = rtrim($sent[$count_word-2], ",:;");
            
$sent[$count_word-1] = rtrim($sent[$count_word-1], ",:;");
            
$output .= ucfirst(implode(' '$sent)).'. ';
        }
        
$output str_replace(' .''.'$output);
        return 
$output;
    }
}


$source =  file_get_contents("text.txt");
$markov = new MarkovChains($source);
$result $markov->GenerateText(100);

echo 
$result;
-
?
, .
__________________
jskorvin   
03.06.2010, 17:34   #2
chesser
 
  chesser
 
: 05.07.2009
: chesser.ru
: 2,116
: $277305
   chesser   ICQ    chesser   Skype™

for :
$sents[$j][] = "keyword";
keyword
__________________
, : vps $0.99
...
chesser   
03.06.2010, 17:37   #3
jskorvin
 
  jskorvin
 
: 05.03.2009
: 365
: $45938

:
chesser
for :
$sents[$j][] = "keyword";
keyword
! .
__________________
jskorvin   
03.06.2010, 17:40   #4
chesser
 
  chesser
 
: 05.07.2009
: chesser.ru
: 2,116
: $277305
   chesser   ICQ    chesser   Skype™

, - :
PHP :
.....
for (
$i=0$i<$num; ++$i){
                
$sents[$j][$i] = $prev;
                ++
$result_count;
                
$p $this->prepared[$prev][mt_rand(0count($this->prepared[$prev]) - 1)];
                if (
$p == ''$p array_rand($this->prepared);
                
$prev $p;
                if (
$prev == '') break 2;
                
$sents[$j][] = array_pop($this->kwds); // <<<<<<<<<<<<<<<<<<<<<<<<    
            
}

.....
$source =  file_get_contents("text.txt");
$markov = new MarkovChains($source);
$markov->kwds = array('key1''key2''key3'); // <<<<<<<<<<<<<<<<<<<<<<<<  
$result $markov->GenerateText(100); 
, , $sents[$j][0] = array_pop($this->kwds); , 1
__________________
, : vps $0.99
...
chesser   
03.06.2010, 18:40   #5
seeker
 
: 07.04.2010
: 1,622
: $0

( 100 = 100 )
:
1-50

51-100
seeker   
03.06.2010, 19:21   #6
googleum
Senior Member
 
  googleum
 
: 12.07.2008
: 475
: $357856746

, .)))
. 300-1000. . . .

. ?)
googleum   
03.06.2010, 19:29   #7
Drunk Monk
,
 
  Drunk Monk
 
: 03.03.2009
: 14,382
: $796837202

.
- , .
__________________
RivaClick.com , ! skype/icq: , , .. .
. - ! ICQ 498856221
Drunk Monk   
03.06.2010, 20:02   #8
jskorvin
 
  jskorvin
 
: 05.03.2009
: 365
: $45938

:
Drunk Monk
.
- , .
__________________
jskorvin   
03.06.2010, 20:05   #9
Drunk Monk
,
 
  Drunk Monk
 
: 03.03.2009
: 14,382
: $796837202

yes/ins/functions.php
KarlMarks . (, ). .
__________________
RivaClick.com , ! skype/icq: , , .. .
. - ! ICQ 498856221
Drunk Monk   
04.06.2010, 00:12   #10
chesser
 
  chesser
 
: 05.07.2009
: chesser.ru
: 2,116
: $277305
   chesser   ICQ    chesser   Skype™

Offtopic
__________________
, : vps $0.99
...
chesser   


« | »





© GoFuckBiz.info
Ad Management by RedTyger