-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProcessText.php
119 lines (104 loc) · 4.64 KB
/
ProcessText.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
<?php
class ProcessText
{
function index()
{
require_once('lib/core/TextPrepocessing.php');
require_once('lib/Tfidf.php');
include 'koneksi.php';
echo "<h2>Text Mining Metode TF-IDF</h2>";
echo "<br><br>";
$textPrepocessing = new TextPrepocessing();
$tfidf = new Tfidf();
// CASE FOLDING
mysqli_query($conn, "TRUNCATE case_folding");
$queryCaseFolding = mysqli_query($conn, "SELECT * FROM documents") or die(mysqli_error($conn));
foreach ($queryCaseFolding as $key => $val) {
$id_dok = $val['doc_id'];
$kalimat_asli = $val['complaint'];
$kode_disposisi = $val['code_disposition'];
$caseFolding = $textPrepocessing->caseFolding($kalimat_asli);
$masukan1 = mysqli_query($conn, "INSERT INTO case_folding VALUES('','$caseFolding','$id_dok','$kode_disposisi')");
}
if ($masukan1 == 1) {
echo "> Case Folding berhasil";
echo "<br>";
// TOKENISASI
mysqli_query($conn, "TRUNCATE token"); //kosongkan isi field
$queryTokenization = mysqli_query($conn, "SELECT * FROM case_folding") or die(mysqli_error($conn));
while ($row = mysqli_fetch_array($queryTokenization)) {
$hasilToken = [];
$kalimat_asli = $row['case_folding'];
$id_dok = $row['doc_id'];
$kode_disposisi = $row['code_disposition'];
$tokenization = $textPrepocessing->tokenization($kalimat_asli);
$masukkan2 = mysqli_query($conn, "INSERT INTO token VALUES('','$tokenization','$id_dok', '$kode_disposisi')");
unset($hasilToken);
}
if ($masukkan2 == 1) {
echo "> Tokenitation berhasil";
echo "<br>";
// FILTERING
mysqli_query($conn, "TRUNCATE filtering");
$query = mysqli_query($conn, "SELECT * FROM token") or die(mysqli_error($conn));
while ($row = mysqli_fetch_array($query)) {
$hasilFilter = [];
$doc_id = $row['doc_id'];
$kode_disposisi = $row['code_disposition'];
$filtering = $textPrepocessing->filtering($row['term']);
$masukkan3 = mysqli_query($conn, "INSERT INTO filtering VALUES('', '$filtering','$doc_id', '$kode_disposisi')");
unset($hasilFilter);
}
if ($masukkan3 == 1) {
echo "> Filtering berhasil";
echo "<br>";
// STEMMING
mysqli_query($conn, "TRUNCATE stemming");
$query = mysqli_query($conn, "SELECT * FROM filtering") or die(mysqli_error($conn));
while ($row = mysqli_fetch_array($query)) {
$hasilStem = [];
$hasil;
$kata = $row['term'];
$id_dok = $row['doc_id'];
$kode_disposisi = $row['code_disposition'];
$stemming = $textPrepocessing->stemming($kata);
$masukkan4 = mysqli_query($conn, "INSERT INTO stemming VALUES('','$stemming','$id_dok','$kode_disposisi')");
unset($hasilStem);
}
if ($masukkan4 == 1) {
echo "> Stemming berhasil.";
echo "<br>";
// HITUNG TF
if ($tfidf->hitungTf() == 1) {
echo "> Hitung TF berhasil";
echo "<br>";
// HITUNG IDF
if ($tfidf->hitungIdf() == 1) {
echo "> Hitung IDF berhasil";
echo "<br>";
} else {
echo "> Hitung IDF gagal";
die;
}
} else {
echo "> Hitung TF gagal";
die;
}
} else {
echo "> Stemming gagal.";
die;
}
} else {
echo "> Filtering gagal";
die;
}
} else {
echo "> Tokenitation gagal";
die;
}
} else {
echo "> Case Folding gagal";
die;
}
}
}