Perbandingan Algoritma Not So Naive Dengan Algoritma Two Way Pada Aplikasi Kamus Bahasa Indonesia - Bahasa Arab Berbasis Android
A-1
DatabaseAccess
public class DatabaseAccsess {
private SQLiteOpenHelper openHelper;
public static SQLiteDatabase database;
private static DatabaseAccsess instance;
private DatabaseAccsess(Context context) {
this.openHelper = new DatabaseHelper(context);
}
public static DatabaseAccsess getInstance(Context context) {
if (instance == null) {
instance = new DatabaseAccsess(context);
}
return instance;
}
public void open() {
this.database = openHelper.getWritableDatabase();
}
public void close() {
if (database != null) {
this.database.close();
}
}
}
DatabaseHelper
public class DatabaseHelper extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "db_kamus_arab.db";
private static final int DATABASE_VERSION = 1;
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
}
Hal2
Button cari;
Button tentang;
Button keluar;
Button profil;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hal2_activity);
cari = (Button) findViewById(R.id.buttonCari);
cari.setOnClickListener(this);
tentang = (Button) findViewById(R.id.buttonTtg);
tentang.setOnClickListener(this);
keluar = (Button) findViewById(R.id.buttonKeluar);
keluar.setOnClickListener(this);
profil = (Button) findViewById(R.id
Universitas Sumatera Utara
A-2
MainActivity
public class MainActivity extends Activity {
TextView t;
Button b;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setSplash();
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void setSplash() {
new Thread() {
public void run() {
try {
Thread.sleep(2500);
} catch (Exception e) {
}
Intent i = new Intent(MainActivity.this, Hal2_Class.class);
MainActivity.this.finish();
startActivity(i);
}
}.start();
}
}
}
public void onClick(View view) {
if (view == cari) {
Intent a = new Intent(this, MainActivityBaru.class);
startActivity(a);
} else if (view == tentang) {
Intent a = new Intent(this, TentangActivity.class);
startActivity(a);
} else if (view == keluar) {
new AlertDialog.Builder(this)
.setMessage("Apa anda ingin Exit?")
.setCancelable(false)
.setPositiveButton("Yes", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id)
{
Hal2_Class.this.finish();
}
Universitas Sumatera Utara
A-3
})
.setNegativeButton("No", null)
.show();
}
}
}
Tab Pager Adapter
int mNumOfTabs;
public TabPagerAdapter(FragmentManager fm, int NumOfTabs) {
super(fm);
this.mNumOfTabs = NumOfTabs;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0 :
NSN_Fragments tabTW = new NSN_Fragments();
return tabTW;
case 1 :
TW_Fragments tabNSN = new TW_Fragments();
return tabNSN;
default:
return null;
}
}
Not So Naive
public class NSN_Fragments extends Fragment {
@Nullable
Button btncari;
ArrayList list_data;
HashMap map;
ListView lv2;
EditText cari;
String pat = "", kata="", arti ="";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.nsn_fragments, container,
false);
btncari = (Button)v.findViewById(R.id.buttonCaritbm);
list_data = new ArrayList();
lv2 = (ListView)v.findViewById(R.id.LvHasil);
cari = (EditText)v.findViewById(R.id.Caritbm);
btncari.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pat = cari.getText().toString();
DatabaseHelper helper = new
DatabaseHelper(NSN_Fragments.this.getContext());
SQLiteDatabase database = helper.getReadableDatabase();
Universitas Sumatera Utara
A-4
Cursor cursor = database.query("db_kamus_arab", new
String[]{"kata", "arti"}, null, null, null, null, "kata");
int ketemu = 0, i = 0;
int urutan = 0;
//
NSN c = new NSN(pat.toUpperCase());
//
try {
list_data.clear();
long t = System.currentTimeMillis();
if (cursor != null) {
cursor.moveToFirst();
do {
kata= cursor.getString(0);
arti = cursor.getString(1);
if (pat.length() = 0 && x[i] == y[i + j])
--i;
j += per;
} else
j += (i - ell);
}
}
}
public static MyResult maxSuf(char[] x, int m) {
int ms, j, k, p;
char a, b;
ms = -1;
j = 0;
k = 1;
p = 1;
while (j + k < m) {
a = x[j + k];
b = x[ms + k];
if (a < b) {
j += k;
k = 1;
p = j - ms;
}
else {
if (a == b)
if (k != p)
++k;
else {
Universitas Sumatera Utara
A-9
j += p;
k = 1;
}
else { /* a > b */
ms = j;
j = ms + 1;
k = 1;
p = 1;
}
}
}
return new MyResult(ms,p);
}
/* Computing of the maximal suffix for >= */
public static MyResult maxSufTilde(char[] x, int m) {
int ms, j, k, p;
char a, b;
ms = -1;
j = 0;
k = 1;
p = 1;
while (j + k < m) {
a = x[j + k];
b = x[ms + k];
if (a > b) {
j += k;
k = 1;
p = j - ms;
}
else
if (a == b)
if (k!=p)
++k;
else {
j += p;
k = 1;
}
else { /* a < b */
ms = j;
j = ms + 1;
k = 1;
p = 1;
}
}
return new MyResult(ms,p);
}
public int memcmp(char[] x, char[] y, int i)
{
int max;
if(x.length>y.length)
max = y.length;
else
max = x.length;
for(int j=i; jy[j])
return 1;
else if(x[j]
DatabaseAccess
public class DatabaseAccsess {
private SQLiteOpenHelper openHelper;
public static SQLiteDatabase database;
private static DatabaseAccsess instance;
private DatabaseAccsess(Context context) {
this.openHelper = new DatabaseHelper(context);
}
public static DatabaseAccsess getInstance(Context context) {
if (instance == null) {
instance = new DatabaseAccsess(context);
}
return instance;
}
public void open() {
this.database = openHelper.getWritableDatabase();
}
public void close() {
if (database != null) {
this.database.close();
}
}
}
DatabaseHelper
public class DatabaseHelper extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "db_kamus_arab.db";
private static final int DATABASE_VERSION = 1;
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
}
Hal2
Button cari;
Button tentang;
Button keluar;
Button profil;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hal2_activity);
cari = (Button) findViewById(R.id.buttonCari);
cari.setOnClickListener(this);
tentang = (Button) findViewById(R.id.buttonTtg);
tentang.setOnClickListener(this);
keluar = (Button) findViewById(R.id.buttonKeluar);
keluar.setOnClickListener(this);
profil = (Button) findViewById(R.id
Universitas Sumatera Utara
A-2
MainActivity
public class MainActivity extends Activity {
TextView t;
Button b;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setSplash();
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void setSplash() {
new Thread() {
public void run() {
try {
Thread.sleep(2500);
} catch (Exception e) {
}
Intent i = new Intent(MainActivity.this, Hal2_Class.class);
MainActivity.this.finish();
startActivity(i);
}
}.start();
}
}
}
public void onClick(View view) {
if (view == cari) {
Intent a = new Intent(this, MainActivityBaru.class);
startActivity(a);
} else if (view == tentang) {
Intent a = new Intent(this, TentangActivity.class);
startActivity(a);
} else if (view == keluar) {
new AlertDialog.Builder(this)
.setMessage("Apa anda ingin Exit?")
.setCancelable(false)
.setPositiveButton("Yes", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id)
{
Hal2_Class.this.finish();
}
Universitas Sumatera Utara
A-3
})
.setNegativeButton("No", null)
.show();
}
}
}
Tab Pager Adapter
int mNumOfTabs;
public TabPagerAdapter(FragmentManager fm, int NumOfTabs) {
super(fm);
this.mNumOfTabs = NumOfTabs;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0 :
NSN_Fragments tabTW = new NSN_Fragments();
return tabTW;
case 1 :
TW_Fragments tabNSN = new TW_Fragments();
return tabNSN;
default:
return null;
}
}
Not So Naive
public class NSN_Fragments extends Fragment {
@Nullable
Button btncari;
ArrayList list_data;
HashMap map;
ListView lv2;
EditText cari;
String pat = "", kata="", arti ="";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.nsn_fragments, container,
false);
btncari = (Button)v.findViewById(R.id.buttonCaritbm);
list_data = new ArrayList();
lv2 = (ListView)v.findViewById(R.id.LvHasil);
cari = (EditText)v.findViewById(R.id.Caritbm);
btncari.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pat = cari.getText().toString();
DatabaseHelper helper = new
DatabaseHelper(NSN_Fragments.this.getContext());
SQLiteDatabase database = helper.getReadableDatabase();
Universitas Sumatera Utara
A-4
Cursor cursor = database.query("db_kamus_arab", new
String[]{"kata", "arti"}, null, null, null, null, "kata");
int ketemu = 0, i = 0;
int urutan = 0;
//
NSN c = new NSN(pat.toUpperCase());
//
try {
list_data.clear();
long t = System.currentTimeMillis();
if (cursor != null) {
cursor.moveToFirst();
do {
kata= cursor.getString(0);
arti = cursor.getString(1);
if (pat.length() = 0 && x[i] == y[i + j])
--i;
j += per;
} else
j += (i - ell);
}
}
}
public static MyResult maxSuf(char[] x, int m) {
int ms, j, k, p;
char a, b;
ms = -1;
j = 0;
k = 1;
p = 1;
while (j + k < m) {
a = x[j + k];
b = x[ms + k];
if (a < b) {
j += k;
k = 1;
p = j - ms;
}
else {
if (a == b)
if (k != p)
++k;
else {
Universitas Sumatera Utara
A-9
j += p;
k = 1;
}
else { /* a > b */
ms = j;
j = ms + 1;
k = 1;
p = 1;
}
}
}
return new MyResult(ms,p);
}
/* Computing of the maximal suffix for >= */
public static MyResult maxSufTilde(char[] x, int m) {
int ms, j, k, p;
char a, b;
ms = -1;
j = 0;
k = 1;
p = 1;
while (j + k < m) {
a = x[j + k];
b = x[ms + k];
if (a > b) {
j += k;
k = 1;
p = j - ms;
}
else
if (a == b)
if (k!=p)
++k;
else {
j += p;
k = 1;
}
else { /* a < b */
ms = j;
j = ms + 1;
k = 1;
p = 1;
}
}
return new MyResult(ms,p);
}
public int memcmp(char[] x, char[] y, int i)
{
int max;
if(x.length>y.length)
max = y.length;
else
max = x.length;
for(int j=i; jy[j])
return 1;
else if(x[j]