-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
executable file
·137 lines (120 loc) · 4.5 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
include 'view/header.php';
if (isset($_POST['submit'])) {
$ok = 0;
$tidakOk = 0;
$notIn = 0;
$search = $_POST['key'];
$results = $twitter->search(['count' => 30, 'q' => urlencode($search), "
result_type" => "recent", 'tweet_mode' => 'extended',
'locale' => 'id']);
foreach ($results as $tweet) {
$string = $tweet->full_text;
//cleasing
$text_clean = new Clean($string);
$text_clean = $text_clean->toString();
//stem
$text_stem = $stemmer->stem($text_clean);
if (empty($text_stem)) {
$notIn++;
break;
}
// calculations:
$scores = $sentiment->score($text_stem);
$class = $sentiment->categorise($text_stem);
if ($db->query("SELECT id FROM tweets WHERE id_tweet = '$tweet->id'")->count() == 0) {
$data = [
"id_tweet" => $tweet->id,
"text_dirty" => $string,
"text_clean" => $text_clean,
"text_steam" => $text_stem,
"label" => $class,
"hastag" => $search
];
if ($db->insert("tweets", $data)) {
$ok++;
}
} else {
$tidakOk++;
}
}
}
$page = (isset($_GET['page'])) ? $_GET['page'] : 1;
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Main content -->
<section class="content container-fluid">
<div class="row">
<div class="col-md-12">
<?php if (isset($search)): ?>
<div class="alert alert-success"> <?= $ok ?> Tweet baru dimasukan, <?= $tidakOk ?> sudah ada , <?= $notIn ?> kosong </div>
<?php endif;?>
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">Ambil Data</h3>
</div>
<div class="box-body">
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="file">Kata Kunci ( hastag ) </label>
<input type="text" name="key" id="" class="form-control" required>
</div>
<div class="form-group">
<input type="submit" value="ambil" name="submit" class="btn btn-primary">
</div>
</form>
</div>
</div>
</div>
<div class="col-md-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">Daftar Barang</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<p>Total record : <?= $db->tweets->count() ?></p>
<table class="table table-bordered">
<tbody><tr>
<th>Id Tweet</th>
<th>Tweet</th>
<th>Text Clean</th>
<th>Text Stem</th>
<th>Label</th>
<th>Kunci</th>
</tr>
<?php foreach ($db->tweets->paginate(15, $page, ['id' => 'DESC']) as $tweet): ?>
<tr>
<td><?= $tweet['id_tweet'] ?></td>
<td><?= $tweet['text_dirty'] ?></td>
<td><?= $tweet['text_clean'] ?></td>
<td><?= $tweet['text_steam'] ?></td>
<td> <span class="label label-<?php
if ($tweet['label'] == 'positif') {
echo 'success';
} elseif ($tweet['label'] == 'negatif') {
echo 'danger';
} elseif ($tweet['label'] == 'netral') {
echo 'info';
}
?>"><?= $tweet['label'] ?></span> </td>
<td><?= $tweet['hastag'] ?></td>
</tr>
<?php endforeach;?>
</tbody></table>
</div>
<!-- /.box-body -->
<div class="box-footer clearfix">
<?= $db->createLinks() ?>
</div>
</div>
</div>
</div>
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<?php
include 'view/footer.php';
?>