download
<?php
$comment=$_GET["comment"];
$user=$_GET["user"];
require_once __DIR__ . '/vendor/autoload.php';
//error_reporting(0);
$initos = new \Sastrawi\Stemmer\StemmerFactory();
$bikinos = $initos->createStemmer();
$stemming=$bikinos->stem($comment);
$stemmingnew=strtolower($stemming);
$ak=getStopNumber();
$ar=getStopWords();
$wordStop=$stemmingnew;
for($i=0;$i<count($ar);$i++){
$wordStop =str_replace($ar[$i]." ","", $wordStop);
}
for($i=0;$i<count($ak);$i++){
$wordStop =str_replace($ak[$i],"", $wordStop);
}
$juduluji=str_replace(" "," ", $wordStop);
//=====================================================
$stemming=$juduluji;
?>
<table width="80%">
<tr>
<td height="24"><label for="nim">User</label>
<td>:<td colspan="2"><?php echo $user;?></td>
</tr>
<tr>
<td height="24"><label for="nim">Comment</label>
<td>:<td colspan="2"><?php echo $comment;?></td>
</tr>
<tr>
<td height="24"><label for="nim">Casefolding</label>
<td>:<td colspan="2"><?php echo strtolower($comment);?></td>
</tr>
<tr>
<td height="24"><label for="nim">Stemming</label>
<td>:<td colspan="2"><?php echo $stemmingnew;?></td>
</tr>
<tr>
<td height="24"><label for="nim">Wordstop</label>
<td>:<td colspan="2"><?php echo $stemming;?></td>
</tr>
</table>
<?php
//======================================
$sql="select * from `data_training` order by `id` asc"; // limit 0,4
$arr=getData($conn,$sql);
$i=0;
$arNorm[$i]=$stemming;
$arKomentar[$i]=$comment;
$arKode[$i]=0;
$arKat[$i]="?";
$arKe[$i]="Dokumen ke-".($i);
$TOT[$i]=0;
$gabungan=$stemming." ";
foreach($arr as $d) {
$i++;
$id=$d["id"];
$komentar=$d["komentar"];
$label=$d["label"];
$normalisasi=$d["normalisasi"];
$arKode[$i]=$id;
$arKat[$i]=$label;
$arKomentar[$i]=$komentar;
$arNorm[$i]=$normalisasi;
$arKe[$i]="Dokumen ke-".($i);
$TOT[$i]=0;
$gabungan.=$normalisasi." ";
}
$jumk=$i;
//======================================
$arAsli=explode(" ",$gabungan);
$arUnix0=array_unique($arAsli);
$ii=0;
for($i=0;$i<count($arUnix0);$i++){
if($arUnix0[$i]==""){}
else{
$arUnix[$ii]=$arUnix0[$i];
$ii++;
}
}
$jumb=count($arUnix);
echo"<table width='100%' border='1'>";
echo"<tr><td>Kata";
echo"<td>Q";
for($i=0;$i<$jumk;$i++){
$u=$i+1;
echo"<td>D".$u;
}
echo"<td>df";
echo"<td>IDF";
echo"<td>QDF";
for($i=0;$i<$jumk;$i++){
$u=$i+1;
echo"<td>QD".$u;
}
for($i=0;$i<$jumk;$i++){
$u=$i+1;
echo"<td>QDFxQD".$u;
}
for($i=0;$i<=$jumk;$i++){
if($i==0){
echo"<td>QDF<sup>2</sup>";
}
else{
$u=$i;
echo"<td>QD$u<sup>2</sup>";
}
}
echo"</tr>";
$bar=count($arUnix);
for($i=0;$i<$bar;$i++){
$kata=$arUnix[$i];
$hitung=0;
echo"<tr><td>".$kata."</td>";
$jumada=0;
for($j=0;$j<=$jumk;$j++){
$ada=getHit($kata,$arNorm[$j]);
$MA[$i][$j]=$ada;
if($ada>0){
$jumada++;
}
echo"<td>".$ada;
}
// $log=log($jumk+1,10)/$jumada;
$log=log(($jumk)/$jumada,10);
$log=abs($log);
echo"<td>$jumada</td>";//idf
echo"<td>log($jumk/$jumada)=$log";
for($j=0;$j<=$jumk;$j++){
$ada=$MA[$i][$j];
$N[$i][$j]=$ada * $log;//X
$N2[$i][$j]=pow($N[$i][$j],2);
$TOT[$j]=$TOT[$j]+$N[$i][$j];
echo "<td>=$ada x $log";//.$N[$i][$j];//
}
for($j=1;$j<=$jumk;$j++){
$NN[$i][$j-1]=$N[$i][0] * $N[$i][$j];
echo "<td>".$NN[$i][$j-1];//Y
$TOT1[$j-1]+=$NN[$i][$j-1];//QDFxDF1...
}
for($j=0;$j<=$jumk;$j++){
echo "<td>".$N2[$i][$j];//Z
$TOT2[$j]+=$N2[$i][$j];
}
echo"</tr>";
}//for i
//------------------------------------
echo"<tr><td>Kata";
echo"<td>Q";
for($i=0;$i<$jumk;$i++){
$u=$i+1;
echo"<td>D".$u;
}
echo"<td>df";
echo"<td>IDF";
echo"<td>QDF";
for($i=0;$i<$jumk;$i++){
$u=$i+1;
echo"<td>QD".$u;
}
for($i=0;$i<$jumk;$i++){
echo"<td>".$TOT1[$i];
}
for($i=0;$i<=$jumk+1;$i++){
echo"<td>".$TOT2[$i];
}
echo"</tr>";
echo"</table>";
$Q=pow($TOT2[0],0.5);
//TOT1 mulai dari 0 krn tak ada Q
//TOT2 mulai dari 1 krn ada Q
$gab.="Qvalue=$TOT2[0]<sup>0.5</sup> =".$Q."<br><br>";
$gab.="Cosine Similarity Terhadap tiap-tiap dokumen:<br>";
$gab."<ol>";
for($i=1;$i<=$jumk;$i++){
$E=pow($TOT2[$i],0.5);
$ES=$TOT2[$i]."<sup>0.5</sup>";
$QS=$TOT2[0]."<sup>0.5</sup>";
$D=pow(($TOT2[0]) * $TOT1[$i-1],0.5);
$DS="(".$TOT2[0]." x ".$TOT1[$i-1].")<sup>0.5</sup>";
//==========================================
$H[$i]=$D/($Q * $E)+0;
$PRO[$i]=round($H[$i]*100,2);
//$kes="<font color='green'>Negatif</font>";
$CS="CSvalue<sub>$i</sub> =$DS/($QS x ".$ES.")";
$komentar=$arKomentar[$i];
$kategori=$arKat[$i];
$rekapitulasi=$arNorm[$i]."<br> =>".$CS.", #<i>Label $kategori</i>";
//==========================================OUT
$hsl="<li>Comment $i :<b>".$komentar."</b><br> =>Proses Normalisasi: $rekapitulasi
<br> =><i>Bobot Cosine Similariry: $PRO[$i] %</i>";
$gab.=$hsl;
$hasilPro[$i-1]=$PRO[$i];
$hasilRekap[$i-1]=$hsl;
$hasilKomentar[$i-1]=$komentar;
$hasilNorm[$i-1]=$arNorm[$i];
$hasilKategori[$i-1]=$arKat[$i];
}
$gab.="</ol>";
echo $gab;
$array_count = count($hasilPro);
for($x = 0; $x < $array_count; $x++){
for($a = 0 ; $a < $array_count - 1 ; $a++){
if($a < $array_count ){
if($hasilPro[$a] < $hasilPro[$a + 1] ){
swap($hasilPro, $a, $a+1);
swap($hasilRekap, $a, $a+1);
swap($hasilKomentar, $a, $a+1);
swap($hasilNorm, $a, $a+1);
swap($hasilKategori, $a, $a+1);
}
}
}
}
$K=5;
$gab="<h3><b>Pengurutan Nilai K=$K besar</b></h3>";
$gab.="<ul>";
$J1=0;
$J2=0;
for($x = 0; $x < $array_count; $x++){
$gab.=$hasilRekap[$x];
if($hasilKategori[$x]==1){$J1++;}
else{$J2++;}
}
$gab.="<ul>";
$kes="LABEL 1";
if($J2>$J1){
$kes="LABEL 0";
}
echo $gab;
echo"<h3>HASIL KATEGORI $kes</h3><hr>";
?>
</div>
</div>
+++++++++++++++++++++++++++++++
comment.php
<?php
require_once __DIR__ . '/vendor/autoload.php';
$initos = new \Sastrawi\Stemmer\StemmerFactory();
$bikinos = $initos->createStemmer();
$ak=getStopNumber();
$ar=getStopWords();
function getUJUI($bikinos, $comment,$ak,$ar,$conn){
$stemming=$bikinos->stem($comment);
$stemmingnew=strtolower($stemming);
$wordStop=$stemmingnew;
for($i=0;$i<count($ar);$i++){
$wordStop =str_replace($ar[$i]." ","", $wordStop);
}
for($i=0;$i<count($ak);$i++){
$wordStop =str_replace($ak[$i],"", $wordStop);
}
$juduluji=str_replace(" "," ", $wordStop);
//=====================================================
$stemming=$juduluji;
$sql="select * from `data_training` order by `id` asc"; // limit 0,4
$arr=getData($conn,$sql);
$i=0;
$arNorm[$i]=$stemming;
$arKomentar[$i]=$comment;
$arKode[$i]=0;
$arKat[$i]="?";
$arKe[$i]="Dokumen ke-".($i);
$TOT[$i]=0;
$gabungan=$stemming." ";
foreach($arr as $d) {
$i++;
$id=$d["id"];
$komentar=$d["komentar"];
$label=$d["label"];
$normalisasi=$d["normalisasi"];
$arKode[$i]=$id;
$arKat[$i]=$label;
$arKomentar[$i]=$komentar;
$arNorm[$i]=$normalisasi;
$arKe[$i]="Dokumen ke-".($i);
$TOT[$i]=0;
$gabungan.=$normalisasi." ";
}
$jumk=$i;
//======================================
$arAsli=explode(" ",$gabungan);
$arUnix0=array_unique($arAsli);
$ii=0;
for($i=0;$i<count($arUnix0);$i++){
if($arUnix0[$i]==""){}
else{
$arUnix[$ii]=$arUnix0[$i];
$ii++;
}
}
$jumb=count($arUnix);
$bar=count($arUnix);
for($i=0;$i<$bar;$i++){
$kata=$arUnix[$i];
$hitung=0;
$jumada=0;
for($j=0;$j<=$jumk;$j++){
$ada=getHit($kata,$arNorm[$j]);
$MA[$i][$j]=$ada;
if($ada>0){
$jumada++;
}
}
$log=log(($jumk)/$jumada,10);
$log=abs($log);
for($j=0;$j<=$jumk;$j++){
$ada=$MA[$i][$j];
$N[$i][$j]=$ada * $log;//X
$N2[$i][$j]=pow($N[$i][$j],2);
$TOT[$j]=$TOT[$j]+$N[$i][$j];
}
for($j=1;$j<=$jumk;$j++){
$NN[$i][$j-1]=$N[$i][0] * $N[$i][$j];
$TOT1[$j-1]+=$NN[$i][$j-1];//QDFxDF1...
}
for($j=0;$j<=$jumk;$j++){
$TOT2[$j]+=$N2[$i][$j];
}
}//for i
$Q=pow($TOT2[0],0.5);
for($i=1;$i<=$jumk;$i++){
$E=pow($TOT2[$i],0.5);
$ES=$TOT2[$i]."<sup>0.5</sup>";
$QS=$TOT2[0]."<sup>0.5</sup>";
$D=pow(($TOT2[0]) * $TOT1[$i-1],0.5);
$DS="(".$TOT2[0]." x ".$TOT1[$i-1].")<sup>0.5</sup>";
//==========================================
$H[$i]=$D/($Q * $E)+0;
$PRO[$i]=round($H[$i]*100,2);
$CS="CSvalue<sub>$i</sub> =$DS/($QS x ".$ES.")";
$komentar=$arKomentar[$i];
$kategori=$arKat[$i];
$rekapitulasi=$arNorm[$i]."<br> =>".$CS.", #<i>Label $kategori</i>";
//==========================================OUT
$hsl="<li>Comment $i :<b>".$komentar."</b><br> =>Proses Normalisasi: $rekapitulasi
<br> =><i>Bobot Cosine Similariry: $PRO[$i] %</i>";
$gab.=$hsl;
$hasilPro[$i-1]=$PRO[$i];
$hasilRekap[$i-1]=$hsl;
$hasilKomentar[$i-1]=$komentar;
$hasilNorm[$i-1]=$arNorm[$i];
$hasilKategori[$i-1]=$arKat[$i];
}
$gab.="</ol>";
$array_count = count($hasilPro);
for($x = 0; $x < $array_count; $x++){
for($a = 0 ; $a < $array_count - 1 ; $a++){
if($a < $array_count ){
if($hasilPro[$a] < $hasilPro[$a + 1] ){
swap($hasilPro, $a, $a+1);
swap($hasilRekap, $a, $a+1);
swap($hasilKomentar, $a, $a+1);
swap($hasilNorm, $a, $a+1);
swap($hasilKategori, $a, $a+1);
}
}
}
}
$K=5;
$gab="<h3><b>Pengurutan Nilai K=$K besar</b></h3>";
$gab.="<ul>";
$J1=0;
$J2=0;
for($x = 0; $x < $array_count; $x++){
$gab.=$hasilRekap[$x];
if($hasilKategori[$x]==1){$J1++;}
else{$J2++;}
}
$gab.="<ul>";
$kes="LABEL 1";
if($J2>$J1){
$kes="LABEL 0";
}
//echo $gab;
return $kes;
}//fungsi
?>
<div class="container-fluid">
<h1 align="center">INSTAGRAM</h1>
<div class="row">
<div class="col-sm-12">
<h4>Komentar</h4>
<ul class="list-group">
<?php
foreach ($comments->data as $media) {
$username_comment = $media->from->username;
$text = $media->text;
$id_post = $media_id;
$cek = mysqli_query($con, "SELECT * FROM comment WHERE username_comment LIKE '$username_comment' AND comment LIKE '$text' AND id_post='$id_post' ");
$itung = mysqli_num_rows($cek);
$see = mysqli_fetch_assoc($cek);
$username = $see['username_comment'];
$comment = $see['comment'];
$idpost = $see['id_post'];
if ($itung==0) {
// echo "kurang dari 0";
$addcomment = mysqli_query($conn, "INSERT INTO comment (username_comment, comment, id_post) VALUES ('$username_comment','$text','$id_post') ") or die (mysqli_error($con));
}else{
// echo "lebih banyak dari 0";
$update = mysqli_query($conn, "UPDATE comment SET username_comment='$username_comment', comment='$text', id_post='$id_post' WHERE username_comment LIKE '$username' AND comment LIKE '$comment' AND id_post='$idpost' ");
}
}
?>
<?php
$query = mysqli_query($conn, "SELECT * FROM comment WHERE id_post='$id_post' ");
while ($fetch = mysqli_fetch_assoc($query)) {
?>
<li class="list-group-item list-group-item-success">
<b><?php
$user=$fetch['username_comment'];
$comment=$fetch['comment'];
$hsl=getUJUI($bikinos, $comment,$ak,$ar,$con);
echo $user; ?>
</b>
:
<?php echo $comment; ?>
|
<a href="index.php?page=cs&comment=<?php echo $comment;?>&user=<?php echo $user;?>">TFIDF =><?php echo $hsl;?></a>
</li>
<?php
}
?>
</ul>
</div>
</div>
</div>
<img src="analisa.png" width="30" width="30">
base.php
<?php
function RP($rupiah){return number_format($rupiah,"2",",",".");}?>
<?php
function WKT($sekarang){
$tanggal = substr($sekarang,8,2)+0;
$bulan = substr($sekarang,5,2);
$tahun = substr($sekarang,0,4);
$judul_bln=array(1=> "Januari", "Februari", "Maret", "April", "Mei","Juni", "Juli", "Agustus", "September","Oktober", "November", "Desember");
$wk=$tanggal." ".$judul_bln[(int)$bulan]." ".$tahun;
return $wk;
}
?>
<?php
function WKTP($sekarang){
$tanggal = substr($sekarang,8,2)+0;
$bulan = substr($sekarang,5,2);
$tahun = substr($sekarang,2,2);
$judul_bln=array(1=> "Jan", "Feb", "Mar", "Apr", "Mei","Jun", "Jul", "Agu", "Sep","Okt", "Nov", "Des");
$wk=$tanggal." ".$judul_bln[(int)$bulan]."'".$tahun;
return $wk;
}
?>
<?php
function BAL($tanggal){
$arr=explode(" ",$tanggal);
if($arr[1]=="Januari"||$arr[1]=="January"){$bul="01";}
else if($arr[1]=="Februari"||$arr[1]=="February"){$bul="02";}
else if($arr[1]=="Maret"||$arr[1]=="March"){$bul="03";}
else if($arr[1]=="April"){$bul="04";}
else if($arr[1]=="Mei"||$arr[1]=="May"){$bul="05";}
else if($arr[1]=="Juni"||$arr[1]=="June"){$bul="06";}
else if($arr[1]=="Juli"||$arr[1]=="July"){$bul="07";}
else if($arr[1]=="Agustus"||$arr[1]=="August"){$bul="08";}
else if($arr[1]=="September"){$bul="09";}
else if($arr[1]=="Oktober"||$arr[1]=="October"){$bul="10";}
else if($arr[1]=="November"){$bul="11";}
else if($arr[1]=="Nopember"){$bul="11";}
else if($arr[1]=="Desember"||$arr[1]=="December"){$bul="12";}
return "$arr[2]-$bul-$arr[0]";
}
?>
<?php
function BALP($tanggal){
$arr=split(" ",$tanggal);
if($arr[1]=="Jan"){$bul="01";}
else if($arr[1]=="Feb"){$bul="02";}
else if($arr[1]=="Mar"){$bul="03";}
else if($arr[1]=="Apr"){$bul="04";}
else if($arr[1]=="Mei"){$bul="05";}
else if($arr[1]=="Jun"){$bul="06";}
else if($arr[1]=="Jul"){$bul="07";}
else if($arr[1]=="Agu"){$bul="08";}
else if($arr[1]=="Sep"){$bul="09";}
else if($arr[1]=="Okt"){$bul="10";}
else if($arr[1]=="Nov"){$bul="11";}
else if($arr[1]=="Nop"){$bul="11";}
else if($arr[1]=="Des"){$bul="12";}
return "$arr[2]-$bul-$arr[0]";
}
?>
<?php
function process($conn,$sql){
$s=false;
$conn->autocommit(FALSE);
try {
$rs = $conn->query($sql);
if($rs){
$conn->commit();
$last_inserted_id = $conn->insert_id;
$affected_rows = $conn->affected_rows;
$s=true;
}
}
catch (Exception $e) {
echo 'fail: ' . $e->getMessage();
$conn->rollback();
}
$conn->autocommit(TRUE);
return $s;
}
function getJum($conn,$sql){
$rs=$conn->query($sql);
$jum= $rs->num_rows;
$rs->free();
return $jum;
}
function getField($conn,$sql){
$rs=$conn->query($sql);
$rs->data_seek(0);
$d= $rs->fetch_assoc();
$rs->free();
return $d;
}
function getData($conn,$sql){
$rs=$conn->query($sql);
$rs->data_seek(0);
$arr = $rs->fetch_all(MYSQLI_ASSOC);
//foreach($arr as $row) {
// echo $row['nama_kelas'] . '*<br>';
//}
$rs->free();
return $arr;
}
function getNorm($bikinos,$instagram){
$stemming=$bikinos->stem($instagram);
$stemmingnew=strtolower($stemming);
$ak=getStopNumber();
$ar=getStopWords();
$wordStop=$stemmingnew;
for($i=0;$i<count($ar);$i++){
$wordStop =str_replace($ar[$i]." ","", $wordStop);
}
for($i=0;$i<count($ak);$i++){
$wordStop =str_replace($ak[$i],"", $wordStop);
}
$instagramuji=str_replace(" "," ", $wordStop);
//=====================================================
$stemming=$instagramuji;
return $stemming;
}
?>
<?php
function getHit($kal,$kalimat){
$ar=explode(" ",$kalimat);
$ada=0;
for($i=0;$i<count($ar);$i++){
if($kal==$ar[$i]){$ada++;}
}//for
return $ada;
}
?>
<?php
function getStopWords()
{
return array(
'yang', 'untuk','kereta','roda','api', 'pada', 'ke', 'para', 'namun', 'menurut', 'antara', 'dia', 'dua',
'ia', 'seperti', 'jika', 'jika', 'sehingga', 'kembali', 'dan', 'tidak', 'ini', 'karena',
'kepada', 'oleh', 'saat', 'harus', 'sementara', 'setelah', 'belum', 'kami', 'sekitar',
'bagi', 'serta', 'di', 'dari', 'telah', 'sebagai', 'masih', 'hal', 'ketika', 'adalah',
'itu', 'dalam', 'bisa', 'bahwa', 'atau', 'hanya', 'kita', 'dengan', 'akan', 'juga',
'ada', 'mereka', 'sudah', 'saya', 'terhadap', 'secara', 'agar', 'lain', 'anda',
'begitu', 'mengapa', 'kenapa', 'yaitu', 'yakni', 'daripada', 'itulah', 'lagi', 'maka',
'tentang', 'demi', 'dimana', 'kemana', 'pula', 'sambil', 'sebelum', 'sesudah', 'supaya',
'guna', 'kah', 'pun', 'sampai', 'sedangkan', 'selagi', 'sementara', 'tetapi', 'apakah',
'kecuali', 'sebab', 'selain', 'seolah', 'seraya', 'seterusnya', 'tanpa', 'agak', 'boleh',
'dapat', 'dsb', 'dst', 'dll', 'dahulu', 'dulunya', 'anu', 'demikian', 'tapi', 'ingin',
'juga', 'nggak', 'mari', 'nanti', 'melainkan', 'oh', 'ok', 'seharusnya', 'sebetulnya',
'setiap', 'setidaknya', 'sesuatu', 'pasti', 'saja', 'toh', 'ya', 'walau', 'tolong',
'tentu', 'amat', 'apalagi', 'bagaimanapun'
);
}
function getStopNumber()
{
return array(
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '@', '#', '$', '%'
);
}
function getUnix($array){
error_reporting(0);
$unique = array_flip(array_flip($array));
//print_r($unique);
$jd=count($array);
//echo $jd."#<br>";
$m=0;
for($i=0;$i<$jd;$i++){
if(strlen($unique[$i])>0){
//echo "$m =".$unique[$i]."<br>";
$M[$m]=$unique[$i];
$m++;
}
}
return $M;
}
function swap(&$arr, $a, $b) {
$tmp = $arr[$a];
$arr[$a] = $arr[$b];
$arr[$b] = $tmp;
}
?>
Tidak ada komentar:
Posting Komentar