Postingan lainnya
Looping nya tidak bisa berhenti
Saya punya kode untuk testing data teks mining, saya ingin dia menghitung probabilitas tiap kalimat, setelah itu baru menghitung probabilitas kalimat lain, disini masalahnya, ketika berpindah kalimat, diya akan meneruskan perhitungan sebelumnya Berikut kode nya :
<?php
include "koneksi.php";
$respwc = mysqli_query($konek, "SELECT DISTINCT term,ppos,pneg,pnet FROM tbidf");
$trunpwc = mysqli_query($konek, "TRUNCATE TABLE pwc");
while($a = mysqli_fetch_array($respwc)){
$term = $a['term'];
$npos = $a['ppos'];
$nneg = $a['pneg'];
$nnet = $a['pnet'];
//echo "$n || $k <br>" ;
mysqli_query($konek, "INSERT INTO pwc (term, positif, negatif, netral) VALUES ('$term', '$npos', '$nneg', '$nnet')");
}
//$b = 'ibukota bangsawan nyaman pengaruh kalimantan';
$query = mysqli_query($konek, "SELECT * FROM dokumentrain ORDER BY iddok");
$cpos = mysqli_query($konek, "SELECT COUNT(kategori) as A FROM dokumentrain WHERE kategori='Positif'");
$arrpos = mysqli_fetch_array($cpos);
$npos = $arrpos['A'];
$cneg = mysqli_query($konek, "SELECT COUNT(kategori) as B FROM dokumentrain WHERE kategori='Negatif'");
$arrneg = mysqli_fetch_array($cneg);
$nneg = $arrneg['B'];
$cnet = mysqli_query($konek, "SELECT COUNT(kategori) as C FROM dokumentrain WHERE kategori='Netral'");
$arrnet = mysqli_fetch_array($cnet);
$nnet = $arrnet['C'];
//$numpos = mysqli_num_rows($npos);
$numdok = mysqli_num_rows($query);
$priorpositif = $npos/$numdok;
$priornegatif = $nneg/$numdok;
$priornetral = $nnet/$numdok;
$hasilpos = 1; $hasilneg = 1; $hasilnet = 1;
$resdok = mysqli_query($konek, "SELECT * FROM dokumentest ORDER by iddok");
while($row = mysqli_fetch_array($resdok)){
$iddok = $row['iddok'];
$kalimat = $row['kalimat'];
$kata = explode(" ", trim($kalimat));
foreach ($kata as $j =>$value){
$k = mysqli_query($konek, "SELECT * FROM pwc");
while($b1 = mysqli_fetch_array($k)){
$str = $b1['term'];
$nilpos = $b1['positif'];
$nilneg = $b1['negatif'];
$nilnet = $b1['netral'];
if ($kata[$j]==$str){
$hasilpos*=$nilpos;
$hasilneg*=$nilneg;
$hasilnet*=$nilnet;
}
}
$hasil1 = $hasilpos*$priorpositif;
$hasil2 = $hasilneg*$priornegatif;
$hasil3 = $hasilnet*$priornetral;
}
echo"$kalimat<br>";
echo "Nilai Positif = $hasil1 <br>";
echo "Nilai Negatif = $hasil2 <br>";
echo "Nilai Netral = $hasil3 <br>";
if ($hasil1 > $hasil2 && $hasil3){
echo "Dokumen ini Bernilai Positif<br>";
}
else if ($hasil2 > $hasil1 && $hasil3){
echo "Dokumen ini Bernilai Negatif<br>";
}
else if ($hasil3 > $hasil1 && $hasil2){
echo "Dokumen ini Bernilai Netral<br>";}
}
?>
Mohon Bantuannya Gan
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban