Пример #1
0
 function exampleQ()
 {
     //data dokument
     $doc1 = "Tokoh politik dari berbagai partai mengadakan rapat untuk membahas koalisi baru menjelang pemilu 2014 dan beberapa pilkada 2012 dan 2013.";
     $doc2 = "Partai politik sudah tidak dapat dipercaya. Sebagian besar partai mengutamakan kepentingan partai daripada kebutuhan rakyat";
     $doc3 = "Partai demokrat memenangkan pemilu 2009 karena figur SBY. Partai Golkar berusaha menang pada 2012. Pertandingan 2 partai ini akan seru";
     $doc4 = "Pertandingan pertama antara Persema dan Persebaya diadakan di Malang. Ini akan menguntungkan tuan rumah";
     $doc5 = "Beberapa pertandingan sepakbola yang dilakoni persebaya pada masa kampanye Pilkada 2010 Kota surabaya akan ditunda.";
     $doc6 = "Sepakbola Indonesia memang belum bangkit. Manajemen tim, pertandingan dan tiket perlu ditingkatkan, bukan hanya fokus pada kemenangan tim.";
     $kunci = "menang pertandingan";
     $hasilDoc1 = $this->Token2($doc1);
     $hasilDoc2 = $this->Token2($doc2);
     $hasilDoc3 = $this->Token2($doc3);
     $hasilDoc4 = $this->Token2($doc4);
     $hasilDoc5 = $this->Token2($doc5);
     $hasilDoc6 = $this->Token2($doc6);
     $hasilKunci = $this->Token2($kunci);
     print_r($hasilDoc1);
     echo "<br/>";
     print_r($hasilDoc2);
     echo "<br/>";
     print_r($hasilDoc3);
     echo "<br/>";
     print_r($hasilDoc4);
     echo "<br/>";
     print_r($hasilDoc5);
     echo "<br/>";
     print_r($hasilDoc6);
     echo "<br/>";
     print_r($hasilKunci);
     $gabungan = array_merge($hasilDoc1, $hasilDoc2, $hasilDoc3, $hasilDoc4, $hasilDoc5, $hasilDoc6, $hasilKunci);
     echo "<br/>";
     echo "Gabungan 2 array<br/>";
     print_r($gabungan);
     echo "<br/>";
     //echo"Array dengan tidak digabung<br/>";
     //print_r($term);
     echo "<table width='100%' border='1' style='font-size:11px;'>";
     echo "<thead>";
     echo "<tr>";
     echo "<th rowspan='2'>Term</th>";
     echo "<th colspan='8'>tf</th>";
     echo "<th>idf</th>";
     echo "<th colspan='7'>wdt = tf.idf</th>";
     echo "<th colspan='6'>WDQ*WDI</th>";
     echo "<th colspan='7'>Panjang Vektor</th>";
     echo "</tr>";
     echo "<tr>";
     echo "<th>Q</th>";
     echo "<th>D1</th>";
     echo "<th>D2</th>";
     echo "<th>D3</th>";
     echo "<th>D4</th>";
     echo "<th>D5</th>";
     echo "<th>D6</th>";
     echo "<th>df</th>";
     echo "<th>log(n/df)</th>";
     echo "<th>Q</th>";
     echo "<th>D1</th>";
     echo "<th>D2</th>";
     echo "<th>D3</th>";
     echo "<th>D4</th>";
     echo "<th>D5</th>";
     echo "<th>D6</th>";
     echo "<th>D1</th>";
     echo "<th>D2</th>";
     echo "<th>D3</th>";
     echo "<th>D4</th>";
     echo "<th>D5</th>";
     echo "<th>D6</th>";
     echo "<th>Q</th>";
     echo "<th>D1</th>";
     echo "<th>D2</th>";
     echo "<th>D3</th>";
     echo "<th>D4</th>";
     echo "<th>D5</th>";
     echo "<th>D6</th>";
     echo "</tr>";
     echo "</thead>";
     echo "<tbody>";
     foreach ($gabungan as $key => $value) {
         $nilaidf += $this->dfq($this->tfq($key, $hasilKunci));
         $nilaidf += $this->dfq($this->tfq($key, $hasilDoc1));
         $nilaidf += $this->dfq($this->tfq($key, $hasilDoc2));
         $nilaidf += $this->dfq($this->tfq($key, $hasilDoc3));
         $nilaidf += $this->dfq($this->tfq($key, $hasilDoc4));
         $nilaidf += $this->dfq($this->tfq($key, $hasilDoc5));
         $nilaidf += $this->dfq($this->tfq($key, $hasilDoc6));
         //memberikan nilai wdt
         $wdtq = $this->wdtq($this->tfq($key, $hasilKunci), $this->idfq(7, $nilaidf));
         $wdtd1 = $this->wdtq($this->tfq($key, $hasilDoc1), $this->idfq(7, $nilaidf));
         $wdtd2 = $this->wdtq($this->tfq($key, $hasilDoc2), $this->idfq(7, $nilaidf));
         $wdtd3 = $this->wdtq($this->tfq($key, $hasilDoc3), $this->idfq(7, $nilaidf));
         $wdtd4 = $this->wdtq($this->tfq($key, $hasilDoc4), $this->idfq(7, $nilaidf));
         $wdtd5 = $this->wdtq($this->tfq($key, $hasilDoc5), $this->idfq(7, $nilaidf));
         $wdtd6 = $this->wdtq($this->tfq($key, $hasilDoc6), $this->idfq(7, $nilaidf));
         //hasil total penjumlahan weightQ tiap doc
         $wq1 += $this->weightQ($wdtq, $wdtd1);
         $wq2 += $this->weightQ($wdtq, $wdtd2);
         $wq3 += $this->weightQ($wdtq, $wdtd3);
         $wq4 += $this->weightQ($wdtq, $wdtd4);
         $wq5 += $this->weightQ($wdtq, $wdtd5);
         $wq6 += $this->weightQ($wdtq, $wdtd6);
         //totala panjang vector perdokumen
         $pvq += $this->Pvector($wdtq);
         $pvq1 += $this->Pvector($wdtd1);
         $pvq2 += $this->Pvector($wdtd2);
         $pvq3 += $this->Pvector($wdtd3);
         $pvq4 += $this->Pvector($wdtd4);
         $pvq5 += $this->Pvector($wdtd5);
         $pvq6 += $this->Pvector($wdtd6);
         echo "<tr>";
         echo "<td align='center'>" . $key . "</td>";
         echo "<td align='center'>" . $this->tfq($key, $hasilDoc5) . "</td>";
         echo "<td align='center'>" . $this->tfq($key, $hasilDoc1) . "</td>";
         echo "<td align='center'>" . $this->tfq($key, $hasilDoc2) . "</td>";
         echo "<td align='center'>" . $this->tfq($key, $hasilDoc3) . "</td>";
         echo "<td align='center'>" . $this->tfq($key, $hasilDoc4) . "</td>";
         echo "<td align='center'>" . $this->tfq($key, $hasilDoc7) . "</td>";
         echo "<td align='center'>" . $this->tfq($key, $hasilDoc8) . "</td>";
         echo "<td align='center'>" . $nilaidf . "</td>";
         echo "<td align='center'>" . $this->idfq(7, $nilaidf) . "</td>";
         echo "<td align='center'>" . $wdtq . "</td>";
         echo "<td align='center'>" . $wdtd1 . "</td>";
         echo "<td align='center'>" . $wdtd2 . "</td>";
         echo "<td align='center'>" . $wdtd3 . "</td>";
         echo "<td align='center'>" . $wdtd4 . "</td>";
         echo "<td align='center'>" . $wdtd5 . "</td>";
         echo "<td align='center'>" . $wdtd6 . "</td>";
         echo "<td align='center'>" . $this->weightQ($wdtq, $wdtd1) . "</td>";
         echo "<td align='center'>" . $this->weightQ($wdtq, $wdtd2) . "</td>";
         echo "<td align='center'>" . $this->weightQ($wdtq, $wdtd3) . "</td>";
         echo "<td align='center'>" . $this->weightQ($wdtq, $wdtd4) . "</td>";
         echo "<td align='center'>" . $this->weightQ($wdtq, $wdtd7) . "</td>";
         echo "<td align='center'>" . $this->weightQ($wdtq, $wdtd8) . "</td>";
         echo "<td align='center'>" . $this->Pvector($wdtq) . "</td>";
         echo "<td align='center'>" . $this->Pvector($wdtd1) . "</td>";
         echo "<td align='center'>" . $this->Pvector($wdtd2) . "</td>";
         echo "<td align='center'>" . $this->Pvector($wdtd3) . "</td>";
         echo "<td align='center'>" . $this->Pvector($wdtd4) . "</td>";
         echo "<td align='center'>" . $this->Pvector($wdtd5) . "</td>";
         echo "<td align='center'>" . $this->Pvector($wdtd6) . "</td>";
         echo "</tr>";
         $nilaidf = 0;
     }
     echo "<tr>";
     echo "<td colspan='17'></td>";
     echo "<td align='center'><b style='color:blue;'>" . $wq1 . "</b></td>";
     echo "<td align='center'><b style='color:blue;'>" . $wq2 . "</b></td>";
     echo "<td align='center'><b style='color:blue;'>" . $wq3 . "</b></td>";
     echo "<td align='center'><b style='color:blue;'>" . $wq4 . "</b></td>";
     echo "<td align='center'><b style='color:blue;'>" . $wq5 . "</b></td>";
     echo "<td align='center'><b style='color:blue;'>" . $wq6 . "</b></td>";
     echo "<td align='center'><b style='color:red;'>" . $pvq . "</b></td>";
     echo "<td align='center'><b style='color:red;'>" . $pvq1 . "</b></td>";
     echo "<td align='center'><b style='color:red;'>" . $pvq2 . "</b></td>";
     echo "<td align='center'><b style='color:red;'>" . $pvq3 . "</b></td>";
     echo "<td align='center'><b style='color:red;'>" . $pvq4 . "</b></td>";
     echo "<td align='center'><b style='color:red;'>" . $pvq5 . "</b></td>";
     echo "<td align='center'><b style='color:red;'>" . $pvq6 . "</b></td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td colspan='17'></td>";
     echo "<td align='center'></td>";
     echo "<td align='center'></td>";
     echo "<td align='center'></td>";
     echo "<td align='center'></td>";
     echo "<td align='center'></td>";
     echo "<td align='center'></td>";
     echo "<td align='center'><b style='color:red;'>" . $this->hasilAkar($pvq) . "</b></td>";
     echo "<td align='center'><b style='color:red;'>" . $this->hasilAkar($pvq1) . "</b></td>";
     echo "<td align='center'><b style='color:red;'>" . $this->hasilAkar($pvq2) . "</b></td>";
     echo "<td align='center'><b style='color:red;'>" . $this->hasilAkar($pvq3) . "</b></td>";
     echo "<td align='center'><b style='color:red;'>" . $this->hasilAkar($pvq4) . "</b></td>";
     echo "<td align='center'><b style='color:red;'>" . $this->hasilAkar($pvq5) . "</b></td>";
     echo "<td align='center'><b style='color:red;'>" . $this->hasilAkar($pvq6) . "</b></td>";
     echo "</tr>";
     echo "</tbody>";
     echo "</table>";
     $urut = array();
     //$cs = new CosineSimilarity();
     //cosine rumus cosine = totalWeigh tiap doc / (hasilAkarQ * hasilAkarDoc^n)
     $urut[] = $this->CosineQ($wq1, $this->hasilAkar($pvq), $this->hasilAkar($pvq1));
     echo "Nilai Cosine Doc1 = " . $this->CosineQ($wq1, $this->hasilAkar($pvq), $this->hasilAkar($pvq1)) . "<br/>";
     $urut[] = $this->CosineQ($wq2, $this->hasilAkar($pvq), $this->hasilAkar($pvq2));
     echo "Nilai Cosine Doc2 = " . $this->CosineQ($wq2, $this->hasilAkar($pvq), $this->hasilAkar($pvq2)) . "<br/>";
     $urut[] = $this->CosineQ($wq3, $this->hasilAkar($pvq), $this->hasilAkar($pvq3));
     echo "Nilai Cosine Doc3 = " . $this->CosineQ($wq3, $this->hasilAkar($pvq), $this->hasilAkar($pvq3)) . "<br/>";
     $urut[] = $this->CosineQ($wq4, $this->hasilAkar($pvq), $this->hasilAkar($pvq4));
     echo "Nilai Cosine Doc4 = " . $this->CosineQ($wq4, $this->hasilAkar($pvq), $this->hasilAkar($pvq4)) . "<br/>";
     $urut[] = $this->CosineQ($wq5, $this->hasilAkar($pvq), $this->hasilAkar($pvq5));
     echo "Nilai Cosine Doc7 = " . $this->CosineQ($wq5, $this->hasilAkar($pvq), $this->hasilAkar($pvq5)) . "<br/>";
     $urut[] = $this->CosineQ($wq6, $this->hasilAkar($pvq), $this->hasilAkar($pvq6));
     echo "Nilai Cosine Doc8 = " . $this->CosineQ($wq6, $this->hasilAkar($pvq), $this->hasilAkar($pvq6)) . "<br/>";
     Arsort($urut);
     print_r($urut);
 }
Пример #2
0
function perf()
{
    static $t;
    unset($_ENV['header'], $_ENV['c']);
    GT('perf1');
    if (preg_match('~(js|css)$|(js|lastmod)\\.php~', SU) || isset($_POST['ajax'])) {
        return;
    }
    #
    //todo:ne pas executer cette fonction si header<>200 sur la page
    $x = $GLOBALS['pi'];
    if ($x['extension']) {
        #peut être vide..
        if (in_Array($x['extension'], explode(',', 'php,htm,html,fr,org,com,info,ch,tv'))) {
        } else {
            return;
        }
        #extension non autorisée
    }
    #cl('perf,j9:'.J9.','.$t.','.SU.','.print_r(,1));
    #if(!preg_match('~\.(html?|php)$~',U))return;
    if (Preg_Match("~glob=~", Q)) {
        $t = 7;
    } elseif (e(',forceperf', 1) or J9) {
        null;
    } elseif (is_numeric(H) || $t || RS == 404 || e('noperf', 1) || isset($_ENV['noperf']) || $_GET['re'] . $_GET['noperf'] . $_GET['np'] || strpos(U, '%2B%2B') || strlen(U) > 80) {
        $t = 1;
    } elseif (Preg_Match("~(js|jsr|css|rss|sm|redir)\$~", Q)) {
        $t = 2;
    } elseif (preg_match("~Tag\\.php|url(\\.|\\()data|image(/|-)png|base64|\\.(png|js|css|jsx?|jpe?g|gif|bmp|gif|ico|htc|sm)\$~", U)) {
        $t = 3;
    } elseif (!isgoodurl()) {
        $t = 4;
    } elseif (Preg_Match("~editor\\.php|officia|Tag|rss|data|xml|/(CIEL|admin|2001|adm)/|(gss|css.*)\$~i", SU) || preg_Match('~/z/~i', SU) && !preg_Match('~\\/sex|video~i', U)) {
        $t = 5;
    }
    if (preg_match("~base64|%27|\\+~", u)) {
        $t = 6;
    }
    if ($t) {
        Av('t', $t);
        return;
    }
    #FPC(ERLOGS,"noperf:$t\n",1);
    GT('fin');
    $t = 1;
    if (in_array(H, array('ben', 'localhost', '127.0.0.1'))) {
        av('H', $_ENV);
        kill();
    }
    #even if cached,if(j9)return;
    if (q) {
        null;
    } else {
        $f0 = TMP . "perf/" . trim(str_replace(array('http://', '/'), array('', '§'), SU), '§') . ".db";
        $f = TMP . "perf/" . mu . ".db";
        if (is_file($f0)) {
            rename($f0, $f);
        }
        #transition, beaucoup plus simple au final
        $x = FGC($f);
        #Faire correspondre avec fichier "mu" plutôt !!! @todo
        if (isset($_ENV['yt']['mots'])) {
            $x['mots'] = $_ENV['yt']['mots'];
        }
        $x['Memo'] = Memuse();
        #;
        $def = array('tim', 'nb', 'db');
        foreach ($def as $v) {
            if (!isset($x[$v])) {
                $x[$v] = 0;
            }
        }
        if ($x['tim'] > 9999999999) {
            $x['tim'] = $x['nb'] = 0;
        }
        #si bug gettime
        #if(!is_numeric($x['tim']))$x['tim']=0;$x['tim']+=$time;#err
        if (!is_numeric($x['nb'])) {
            $x['nb'] = 1;
        }
        $x['nb'] = $x['nb'] + 1;
        $x['avg'] = ceil($x['tim'] / $x['nb']);
        unset($x['calc'], $x['gen']);
        #if avg>800 db(,'prio'); et on peut créer fichier fpdata avec cette valeur avg afin de charger plus souvent, plus durablement le système de cache pour soulager les pages mettant bcp de temps à être pondues !!!!
        $x['db'] = explode(',', str_replace('Array', '', $x['db']));
        $x['db'] = Array_unique($x['db']);
        $x['db'] = implode(',', $x['db']);
        if (function_exists('sys_getloadavg')) {
            $sysload = implode('#', sys_getloadavg());
            $x['sys'] = date("H:i:s") . ">" . $sysload;
        }
        if (e('erver:pre', 1)) {
        } else {
            FPC($f, $x);
            Touch($f, $x['avg']);
        }
    }
    $x['db'] .= ",fin:" . $_ENV['lasttime'];
    $x['cachepath'] = CACHEPATH;
    if (!j9) {
        return;
    }
    Addurl();
    #les urls dont on s'en tape
    $edit = $y2 = null;
    #FAP(logs.'Vitale.db',Array('cp'=>cachepath,'sfn'=>$_SERVER['SCRIPT_FILENAME']));
    #$x=FGC(TMP.'cont/'.$mu.'.contenu');
    $f = TMP . 'cont/' . MU . '.contenu';
    if (is_file($f)) {
        $y = FGC($f);
        $_ENV['args'] .= " :muc:{$y['id']},len:" . $_ENV['x'];
        $edit .= "<button onclick=\"edt('?zp={$y['id']}');return false;\">e:muc:{$y['id']}</button>";
    } elseif (is_file(TMP . 'cont/' . MU)) {
        $y = FGC(TMP . 'cont/' . MU);
        e("e:mu:{$y}");
        #contient l'identifiant de la page
        $t = sql5("select sql_cache * from p.zpages2 where id={$y}");
        if ($t) {
            $edit .= "<button onclick=\"edt('?zp={$y}');return false;\">e:mu:{$y}</button>";
        } else {
            unlink(TMP . 'cont/' . MU);
        }
        #unlink si l'identifiant sql n'existe pas :)
    } elseif (isset($_POST['create'])) {
        #£todo:bad: right, that's bad, we're checking in this function, globally, if we have some postdata to edit this page contents
        $y = sql5("select id from p.zpages2 where url=\"" . SU . "\"");
        if (!$y) {
            $y = sql5("insert into p.zpages2(url)values(\"" . SU . "\")");
            if ($y) {
                FPC(TMP . 'cont/' . mu, $y);
            }
        }
    } elseif (!RU) {
        $edit .= "<form method=post><input type=hidden name=create value=1><input type=submit value=create></form>";
    }
    if (1) {
        $edit .= "<button accesskey='e' onclick=\"edt('?sfn=1');return false;\">kod</button>";
    }
    Arsort($_ENV['dbt']);
    unset($_ENV['c'], $_ENV['Adbt']);
    $x = Array_merge($_ENV, $x);
    if (is_file(CACHEPATH)) {
        $dif = " age:" . (filemtime(CACHEPATH) - NOW) . "";
    }
    if (is_Array($x['Memo'])) {
        $x['Memo'] = implode(',', $x['Memo']);
    }
    #$y=Pre($x,'nude=1');pre2console($y);
    if (isset($_ENV['debug'])) {
        $y2 = Pre($_ENV['debug'], 'nude=1');
        pre2console($y2);
    }
    #if(J11)$y=print_r(debug_backtrace(),1).$y;
    if (!strpos($_ENV['args'], 'nocss') && !AJAX) {
        $base = $x;
        header('Bs: ' . fixSer($x), 1);
        header('Cdebug: ' . str_replace(array("\r", "\n"), array('', '*'), print_r($base, 1)), 1);
        echo "\n\n<script>var y='" . jsonEnc($base) . "';var cinfo=JSON.parse(y);console.info('cinfo',cinfo);</script>";
        //todo JS debugging into header
    }
    #y.replace(/\"\"/gi,'*'),if(z2)console.info(\"%c\"+z2,'color:blue;font:10px Trebuchet MS');
    #[\"Perf:$sysload:$_ENV[lasttime] ms-\"+z]
    #.replace(/\\n +\(\\n/g,'(\\n').replace(/\\nArray\\n\(\\n\[/g,'\\nArray:\['),z2=\"$y2\".replace(/\\n +\(\\n/g,'(\\n').replace(/\\nArray\\n\(\\n\[/g,'\\nArray:\[');
    #console.info([%cPerf:$sysload:$_ENV[lasttime] ms-\"+z,'color:blue;font:10px Consolas');
    if (e('shutd')) {
        Null;
    } else {
        kill();
    }
    #Si une autre fonction de shutdown a été rajoutée par dessus - sinon fin de tout ( appel à die recursif dans foncshutdown ) !
}