LISTING PROGRAM
I.
Bahasa C#
1.1.
Maximal Shift
#endregion
#region MaximalShift struct pattern
{
public int loc; public char c; }
int [] minShift; int [] adaptedGS; pattern [] pat;
void computeMinshift(string x) {
int i, j;
for (i = 0; i < x.Length; ++i){ for (j = i - 1; j >= 0; --j)
if (x[i] == x[j]) break;
minShift[i] = i - j; }
}
void orderPattern(string x, pattern[] pat) {
int i;
for (i = 0; i < x.Length; i++) {
pat[i].loc = i; pat[i].c = x[i]; }
Array.Sort(pat, new maxShiftPcmp(minShift)); }
int matchshift(string x, int ploc, int lshift, pattern[] pat)
{
int i, j;
for (; lshift < x.Length; ++lshift) {
i = ploc;
while (--i >= 0) {
if ((j = pat[i].loc - lshift) < 0) continue;
if (pat[i].c != x[j]) break;
}
break; }
return lshift; }
void preAdaptedGS(string x, int[] adaptedGS, pattern[] pat) {
int lshift, i, ploc;
adaptedGS[0] = lshift = 1;
for (ploc = 1; ploc <= x.Length; ++ploc) {
lshift = matchshift(x, ploc, lshift, pat); adaptedGS[ploc] = lshift;
}
for (ploc = 0; ploc < x.Length; ploc++) {
lshift = adaptedGS[ploc]; while (lshift < x.Length) {
i = pat[ploc].loc - lshift;
if (i < 0 || pat[ploc].c != x[i]) break;
++lshift;
lshift = matchshift(x, ploc, lshift, pat); }
adaptedGS[ploc] = lshift; }
}
bool MS(string x, string y) {
int i, j, m = x.Length, n = y.Length, value; j = 0;
while (j <= n - m) {
i = 0;
while (i < m && pat[i].c == y[j + pat[i].loc]) ++i;
if (i >= x.Length) return true;
j += j + m < n && qsbc1.TryGetValue(y[j + m], out value) ? (value > adaptedGS[i] ? value :
adaptedGS[i]) : (qsbc1['*'] > adaptedGS[i] ? qsbc1['*'] : adaptedGS[i]);
}
1.2.
Quick Search
//disini mulai algoritma quick search #region QuickSearchLama
private void preQS() {//pencarian table QSBC int m = 0;
for (int i = 0; i < jumlahkar; i++) {
qsbc[i] = m + 1; m = m + 1;
}
for (int i = 0; i < jumlahkar; ++i) {
qsbc[i] = m - i;//didapatkan tabel qsbc }
}
//memulai algoritma quick search
#region QuickSearch
private void preQsbc(string x, Dictionary<char, int> qsbc) {
int i;
for (i = 0; i < x.Length; i++) {
if (!qsbc.ContainsKey(x[i])) {
qsbc.Add(x[i], x.Length - i); }
else {
qsbc[x[i]] = x.Length - i; }
}
qsbc.Add('*', x.Length + 1); }
private bool qs(string x, string y) {
int j = 0, n = y.Length, m = x.Length, value; while (j <= n - m)
{
if (x.Equals(y.Substring(j,m))) return true;
j += j + m < n && qsbc1.TryGetValue(y[j + m], out value) ? value : qsbc1['*'];
}
return false; }
return false; }
1.3.
Menampilkan Data
using System.Collections;
using System.Collections.Generic; using System.ComponentModel; using System.Data;
using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text;
using System.Threading.Tasks; using System.Windows.Forms; using System.IO;
namespace tugasakhir {
public partial class Form1 : Form
private void tampildata() {
string queri = "SELECT kata from kamus"; listBoxkata.Items.Clear();
koneksi tampil = new koneksi(); tampil.koneksidb();
tampil.perintah.CommandText = queri; tampil.conn.Open();
tampil.adapter.SelectCommand = tampil.perintah; tampil.conn.Close();
tampil.adapter.Fill(tampil.dt);
foreach (DataRow row in tampil.dt.Rows) {
listBoxkata.Items.Add(row[0]); }
}
private void listBoxkata_SelectedIndexChanged(object sender, EventArgs e)
{
string queri = "SELECT keterangan, produsen from kamus where kata ='" + listBoxkata.SelectedItem.ToString() + "'";
rtbhasil.Clear();
koneksi tampil = new koneksi(); tampil.koneksidb();
tampil.perintah.CommandText = queri; tampil.conn.Open();
tampil.rdr = tampil.perintah.ExecuteReader(); while (tampil.rdr.Read())
{
rtbhasil.Text = (tampil.rdr["keterangan"].ToString()); produksi.Text = (tampil.rdr["produsen"].ToString()); }
tampil.conn.Close(); }
#endregion
private void cmdms_Click(object sender, EventArgs e) {
string queri = "SELECT kata,keterangan from kamus"; rtbhasil.Clear();
tampil.perintah.CommandText = queri; tampil.conn.Open();
tampil.rdr = tampil.perintah.ExecuteReader(); Stopwatch a = new Stopwatch();
a.Start(); qsbc1.Clear();
pat = new pattern[txtcari.Text.Length];
adaptedGS = new int[txtcari.Text.Length + 1]; minShift = new int[txtcari.Text.Length]; computeMinshift(txtcari.Text);
orderPattern(txtcari.Text, pat);
preAdaptedGS(txtcari.Text, adaptedGS, pat); preQsbc(txtcari.Text, qsbc1);
while (tampil.rdr.Read()) {
if (MS(txtcari.Text, tampil.rdr["kata"].ToString())) {
listBoxkata.Items.Add(tampil.rdr["kata"].ToString()); }
}
if (listBoxkata.Items.Count == 0)
listBoxkata.Items.Add("Kata Tidak Ditemukan"); a.Stop();
rtms.Text =
(int.Parse(a.Elapsed.ToString("fffffff")) / 10000f).ToString() + " ms";
string [] waktu = (rtms.Text.Split(new char [] {' '})); if (!hasilolah1.ContainsKey(txtcari.Text))
{
hasilolah1.Add(txtcari.Text, double.Parse(waktu[0])); }
else {
if (hasilolah1[txtcari.Text] > double.Parse(waktu[0])) hasilolah1[txtcari.Text] = double.Parse(waktu[0]); }
//MessageBox.Show(hasilolah.Count.ToString()); tampil.rdr.Close();
tampil.conn.Close(); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
var katams = hasilolah1.Keys.ToArray(); var waktums = hasilolah1.Values.ToArray(); var kataqs = hasilolah2.Keys.ToArray(); var waktuqs = hasilolah2.Values.ToArray(); for (int i = 0; i < katams.Length; i++) {
file.WriteLine(katams[i].ToString() + " " + waktums[i].ToString() + " Maximal Shift"); }
for (int i = 0; i < kataqs.Length; i++) {
file.Close(); }
} }
namespace tugasakhir {
partial class Form1
{
/// <summary>
/// Required designer variable. /// </summary>
private System.ComponentModel.IContainer components = null; ///<param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose(); }
base.Dispose(disposing); }
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary>
private void InitializeComponent() {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.label1 = new System.Windows.Forms.Label();
this.txtcari = new System.Windows.Forms.TextBox(); this.cmdqs = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.produksi = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label();
this.groupBox4 = new System.Windows.Forms.GroupBox(); this.rtqs = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox(); this.label3 = new System.Windows.Forms.Label();
this.rtms = new System.Windows.Forms.TextBox();
this.rtbhasil = new System.Windows.Forms.RichTextBox(); this.listBoxkata = new System.Windows.Forms.ListBox(); this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox4.SuspendLayout(); this.groupBox3.SuspendLayout(); this.SuspendLayout();
//
// groupBox1 //
this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.txtcari);
this.groupBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.groupBox1.ForeColor =
System.Drawing.Color.MidnightBlue;
this.groupBox1.Location = new System.Drawing.Point(14, 14);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(356, 69); this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false; this.groupBox1.Text = "Pencarian"; //
// label1 //
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(7, 30); this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(76, 16); this.label1.TabIndex = 0;
this.label1.Text = "Input Kata"; //
// txtcari //
this.txtcari.Location = new System.Drawing.Point(91, 27); this.txtcari.Name = "txtcari";
this.txtcari.Size = new System.Drawing.Size(226, 22); this.txtcari.TabIndex = 0;
this.txtcari.TextChanged += new
System.EventHandler(this.txtcari_TextChanged); //
// cmdqs //
this.cmdqs.BackColor = System.Drawing.Color.Silver;
this.cmdqs.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cmdqs.ForeColor = System.Drawing.Color.MidnightBlue; this.cmdqs.Location = new System.Drawing.Point(407, 14); this.cmdqs.Name = "cmdqs";
this.cmdqs.Size = new System.Drawing.Size(76, 69); this.cmdqs.TabIndex = 1;
this.cmdqs.Text = "&Cari";
this.cmdqs.UseVisualStyleBackColor = false; this.cmdqs.Click += new
System.EventHandler(this.cmdcari_Click); //
// button1 //
this.button1.BackColor = System.Drawing.Color.Silver; this.button1.Location = new System.Drawing.Point(505, 432);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 32); this.button1.TabIndex = 3;
this.button1.Text = "&Hapus";
this.button1.Click += new
System.EventHandler(this.button1_Click); //
// groupBox2 //
this.groupBox2.BackColor = System.Drawing.Color.Silver; this.groupBox2.Controls.Add(this.produksi);
this.groupBox2.Controls.Add(this.label2); this.groupBox2.Controls.Add(this.groupBox4); this.groupBox2.Controls.Add(this.groupBox3); this.groupBox2.Controls.Add(this.rtbhasil); this.groupBox2.Controls.Add(this.listBoxkata);
this.groupBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.groupBox2.ForeColor =
System.Drawing.Color.MidnightBlue;
this.groupBox2.Location = new System.Drawing.Point(16, 114);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(654, 296); this.groupBox2.TabIndex = 6;
this.groupBox2.TabStop = false; this.groupBox2.Text = "Hasil "; //
// produksi //
this.produksi.Location = new System.Drawing.Point(89, 258);
this.produksi.Name = "produksi";
this.produksi.Size = new System.Drawing.Size(225, 22); this.produksi.TabIndex = 5;
//
// label2 //
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(5, 260); this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(69, 16); this.label2.TabIndex = 4;
this.label2.Text = "Produksi"; //
// groupBox4 //
this.groupBox4.Controls.Add(this.rtqs); this.groupBox4.Controls.Add(this.label4);
this.groupBox4.ForeColor =
System.Drawing.Color.MidnightBlue;
this.groupBox4.Location = new System.Drawing.Point(375, 139);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(273, 93); this.groupBox4.TabIndex = 3;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Quick Search"; //
// rtqs //
this.rtqs.Size = new System.Drawing.Size(153, 22); this.rtqs.TabIndex = 1;
//
// label4 //
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(6, 42); this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(103, 16); this.label4.TabIndex = 0;
this.label4.Text = "Running Time"; //
// groupBox3 //
this.groupBox3.Controls.Add(this.label3); this.groupBox3.Controls.Add(this.rtms);
this.groupBox3.ForeColor =
System.Drawing.Color.MidnightBlue;
this.groupBox3.Location = new System.Drawing.Point(376, 41);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(272, 91); this.groupBox3.TabIndex = 2;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Maximal Shift"; //
// label3 //
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(6, 45); this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(103, 16); this.label3.TabIndex = 1;
this.label3.Text = "Running Time"; //
// rtms //
this.rtms.Location = new System.Drawing.Point(113, 42); this.rtms.Name = "rtms";
this.rtms.Size = new System.Drawing.Size(153, 22); this.rtms.TabIndex = 0;
//
// rtbhasil //
this.rtbhasil.Location = new System.Drawing.Point(188, 28);
this.rtbhasil.Name = "rtbhasil";
this.rtbhasil.Size = new System.Drawing.Size(174, 213); this.rtbhasil.TabIndex = 1;
this.rtbhasil.Text = ""; //
// listBoxkata //
this.listBoxkata.ForeColor =
System.Drawing.Color.MidnightBlue;
this.listBoxkata.FormattingEnabled = true; this.listBoxkata.ItemHeight = 16;
this.listBoxkata.Location = new System.Drawing.Point(15, 27);
this.listBoxkata.Size = new System.Drawing.Size(169, 212);
this.listBoxkata.TabIndex = 0;
this.listBoxkata.SelectedIndexChanged += new
System.EventHandler(this.listBoxkata_SelectedIndexChanged );
// // Form1 //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font; this.AutoValidate =
System.Windows.Forms.AutoValidate.EnableAllowFocusChange; this.BackgroundImage =
((System.Drawing.Image)(resources.GetObject("$this.Backgr oundImage")));
this.ClientSize = new System.Drawing.Size(682, 468); this.Controls.Add(this.groupBox2);
this.Controls.Add(this.cmdqs); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Controls.Add(this.groupBox1);
this.Font = new System.Drawing.Font("Microsoft SansSerif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Name = "Form1";
this.Text = "Kamus Farmakologi"; this.FormClosing += new
System.Windows.Forms.FormClosingEventHandler(this.Form1_F ormClosing);
this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.groupBox4.ResumeLayout(false); this.groupBox4.PerformLayout(); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Button cmdqs;
private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox txtcari; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.TextBox produksi; private System.Windows.Forms.Label label2;
private System.Windows.Forms.GroupBox groupBox4; private System.Windows.Forms.TextBox rtqs;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox rtms;
private System.Windows.Forms.RichTextBox rtbhasil; private System.Windows.Forms.ListBox listBoxkata; }