-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.php
60 lines (48 loc) · 1.4 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sentiment Analysis Indonesia Sederhana</title>
<link rel="stylesheet" href="css/pure-min.css"></head>
<body style="margin: 0 auto;width:90%;padding:10px;">
<h2>Sentiment Analysis Indonesia Sederhana</h2>
<form class="pure-form" style="width:100%" action="" method="post">
<fieldset class="pure-group">
<textarea name="kalimat" class="pure-input-1-2" placeholder="kalimat (contoh: ahok pantas menjadi gubernur jakarta)"></textarea>
</fieldset>
<button type="submit" name="submit" class="pure-button pure-input-1-2 pure-button-primary">Uji Sentimen</button>
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])){
if (PHP_SAPI != 'cli') {
echo "<pre>";
}
$strings = array(
1 => $_POST['kalimat'],
);
require_once __DIR__ . '/autoload.php';
$sentiment = new \PHPInsight\Sentiment();
$i=1;
foreach ($strings as $string) {
// calculations:
$scores = $sentiment->score($string);
$class = $sentiment->categorise($string);
// output:
if (in_array("pos", $scores)) {
echo "Got positif";
}
echo "\n\nHasil:";
echo "\nKalimat: <b>$string</b>\n";
echo "Arah sentimen: <b>$class</b>, nilai: ";
// var_dump($scores);
foreach ($scores as $skor) {
echo $skor;
}
echo "\n\n";
$i++;
}
}
?>