reader.close; directory.close;
pencarian.putclassname, hasilPencarian; }
} }
return pencarian;
Deskripsi: Melakukan pencarian file surat berdasarkan kata kunci yang diberikan
user. Pencarian dilakukan melalui index yang telah dibangun pada proses sebelumnya. Hasil dari pencarian adalah pertama, potongan isi surat yang
mengandung kata kunci dan kedua, lokasi surat.
4.2. Antarmuka Simpan Surat
Gambar 4.2 Antarmuka untuk penyimpanan surat.
1. Method:
getPrior String prior
File file = new Fileprior; String[] temp;
try { FileInputStream fstream = new FileInputStreamfile;
DataInputStream in = new DataInputStreamfstream; BufferedReader br = new BufferedReadernew
InputStreamReaderin; String strLine;
while strLine = br.readLine = null { temp = strLine.split=;
priorProb.puttemp[0], Double.valueOftemp[1]; }
br.close; in.close;
fstream.close; } catch Exception e {
System.out.printlne; }
Deskripsi: Berfungsi untuk mengambil data prior probabilities.
2. Method:
getCond String cond
File file = new Filecond; String classname;
String[] temp; try {
for final File fileEntry : file.listFiles { HashMapString, Double condValue = new HashMap;
classname = fileEntry.getName; classname = classname.substring0, classname.length -
4; FileInputStream fstream = new
FileInputStreamfileEntry.getAbsolutePath; DataInputStream in = new DataInputStreamfstream;
BufferedReader br = new BufferedReadernew InputStreamReaderin;
String strLine; while strLine = br.readLine = null {
temp = strLine.split=; condValue.puttemp[0], Double.valueOftemp[1];
} condProb.putclassname, condValue;
br.close; in.close;
fstream.close; }
} catch Exception e { System.out.printlne;
}
Deskripsi: Berfungsi untuk mengambil data conditional probabilities.
3. Method:
getVocab String vocab
File file = new Filevocab; try {
FileInputStream fstream = new FileInputStreamfile; DataInputStream in = new DataInputStreamfstream;
BufferedReader br = new BufferedReadernew InputStreamReaderin;
String strLine; while strLine = br.readLine = null {
vocabulary.addstrLine; }
} catch Exception e { System.out.printlne;
}
Deskripsi: Berfungsi untuk mengambil data vocabulary daftar term kata unik
dari seluruh kelas.
4. Method:
preproTestingFileString testingFile
File file = new FiletestingFile; Integer freq;
try { FileInputStream fstream = new FileInputStreamfile;
DataInputStream in = new DataInputStreamfstream; BufferedReader br = new BufferedReadernew
InputStreamReaderin; String strLine;
String term, syn; boolean check;
while strLine = br.readLine = null { Scanner sc = new ScannerstrLine;
while sc.hasNext { check = false;
Iterator iter = prepro.stopWords.iterator; term = sc.next.toLowerCase;
term = term.replaceAll[a-z 0-9], ;
if term.length = 1 { continue;
} syn = this.prepro.synonym.getterm;
if syn = null { term = syn;
} if prepro.stopWords.containsterm {
term = porter.stemmingterm; freq = testing.getterm;
testing.putterm, freq == null ? 1 : freq + 1; }
} sc.close;
} br.close;
in.close; fstream.close;
} catch Exception e { System.out.printlne;
}
Deskripsi: Berfungsi sebagai proses preprocessing untuk data testing.
Perbedaannya dengan preprocessing untuk data training adalah inputnya. Data untuk proses testing adalah file tunggal, sedangkan untuk training berupa file
kolektif yang terbagi dalam beberapa folder.
5. Method:
Matching
String termInVocab; String termInTest;
int freq; for Map.EntryString, Integer entry : testing.entrySet {
termInTest = entry.getKey; freq = entry.getValue;
Iterator iter = vocabulary.iterator; while iter.hasNext {
if iter.next.equalstermInTest { match.puttermInTest, freq;
} }
}
Deskripsi: Berfungsi untuk menemukan term yang sama – sama muncul dalam
data training model dan testing. 6.
Method: getProbability
double prob, value, priorScore; String term;
Integer freq; double sum;
double highestScore = 0; HashMapString, Double countCond = new HashMap;
for String classname : condProb.keySet { sum = 1;
prob = 0; HashMapString, Double temp = new HashMap;
temp = condProb.getclassname; for Map.EntryString, Integer entry : match.entrySet {
term = entry.getKey; freq = entry.getValue;
for Map.EntryString, Double condEntry : temp.entrySet {
if term.equalscondEntry.getKey { value = Math.powcondEntry.getValue, freq;
sum = sum value; break;
} }
} priorScore = priorProb.getclassname;
prob = priorScore sum; System.out.printlnclassname + = + prob;
if prob highestScore { highestScore = prob;
highestProb = classname; }
} return highestProb;
Deskripsi: Berfungsi untuk menghitung probabilitas data testing terhadap data
training model. Probabilitas tertinggi terhadap sebuah kelas akan menjadi hasil dari klasifikasi. Method ini menerapakan persamaan no. 3 hal. 15.
4.3. Antarmuka Training