<div id="main container-fluid card">
<div class="card-header">
<h2 class="h2 mt-3">Analisa TFIDF</h2>
<p class="h6 font-weight-normal">
<strong>Base of Comment Intagram API Web</strong>
<?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($con,$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>
AUTOMATC KODE:
</div>
PENGEMBANGAN BS SAMPAI AUTOMATIC KODE
<?php
include "connection.php";
$media_id = $_GET['media_id'];
$comments = $instagram->getMediaComments($media_id);
// echo '<pre>';
// print_r($comments);
// echo '<pre>';
// die();
require_once __DIR__ . '/vendor/autoload.php';
$initos = new \Sastrawi\Stemmer\StemmerFactory();
$bikinos = $initos->createStemmer();
$ak=getStopNumber();
$ar=getStopWords();
function getUJUI($bikinos, $comment,$ak,$ar,$con){
$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($con,$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($con, "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($con, "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($con, "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">
Tidak ada komentar:
Posting Komentar