Association Rule Program Using Java and Weka Library

Java program that implement Association Rule. Association Rule is one of Data Minning techniue. Therere are many algorithm that implement association rule, and this program is use Apriori Algorithm. It used to prunning some data in training process.

In data miningassociation rule learning is a popular and well researched method for discovering interesting relations between variables in large databases. Piatetsky-Shapiro[1] describes analyzing and presenting strong rules discovered in databases using different measures of interestingness. Based on the concept of strong rules, Rakesh Agrawal et al.[2] introduced association rules for discovering regularities between products in large-scale transaction data recorded by point-of-sale (POS) systems in supermarkets. For example, the rule \{\mathrm{onions, potatoes}\} \Rightarrow \{\mathrm{burger}\} found in the sales data of a supermarket would indicate that if a customer buys onions and potatoes together, he or she is likely to also buy hamburger meat. Such information can be used as the basis for decisions about marketing activities such as, e.g., promotional pricing or product placements. In addition to the above example from market basket analysis association rules are employed today in many application areas including Web usage miningintrusion detection and bioinformatics. As opposed to sequence mining, association rule learning typically does not consider the order of items either within a transaction or across transactions. (source: wikipedia)

At one time I thought would be interesting when I can implement this Association Rule in my own program. I create video to describe features on my program. And finally, I dedicate this program to windupurnomo.wordpress.com readers. Download on google project please.

 

Posted in Data Mining, Java, programming | Tagged , , , , , , , , , | 3 Comments

Passing a String by Refference in Java

In some case we need to return more than one value in one call of method. For example  on SMS Receiver process, I want to process received SMS, than return message reply and receiver number based on received SMS. In C# there is syntax out, that possible to return more than one value. But how about Java? Yes we can use call by refference, that using method parameter as input and output line. View my code to known this condition please.

public class SMSReceiver{
	private static final String BOS1_Number = "0989889876";
	private static final String BOS2_Number = "0989889890";

	public static void main(String [] args){
		String message = args[0];
		String sender = args[1];
		String receiver = "";
		smsProcessing(message, sender, receiver);

		System.out.println("To: "+receiver);
		System.out.println("Message: "+message);
	}

	private static void smsProcessing(String message, String sender, String receiver){
		String [] vars = message.split("#");

		if(vars[0].equals("BOS1")){
			message = "Dear bos1, there is message for you, "+vars[1];
			receiver = BOS1_Number;
		}else if(vars[0].equals("BOS2")){
			message = "Dear bos2, there is message for you, "+vars[1];
			receiver = BOS2_Number;
		}else{
			message = "Invalid SMS format.";
			receiver = sender;
		}
	}
}
Console Process:
javac SMSReceiver.java
java SMSReceiver BOS1#Halooooooo 09890909080
Result:
To:
Message: BOS1#Halooooooo

In fact String can not passing by Refference. But we can custom our code to do this:

  1. Using StringBuilder
  2. String included in a Class
  3. Array of String

In this section I will implement the smsProcessing method using 3 ways above:

String Builder

smsProcessing method:

private static void smsProcessing(StringBuilder message, StringBuilder sender, StringBuilder receiver){
		String[] vars = message.toString().split("#");
		if(vars[0].equals("BOS1")){
			String msg = "Dear bos1, there is message for you, "+vars[1];
			message.delete(0, message.length()).append(msg);
			receiver.delete(0, receiver.length()).append(BOS1_Number);
		}else if(vars[0].equals("BOS2")){
			String msg = "Dear bos2, there is message for you, "+vars[1];
			message.delete(0, message.length()).append(msg);
			receiver.delete(0, receiver.length()).append(BOS2_Number);
		}else{
			message.delete(0, message.length()).append("Invalid SMS format.");
			receiver.delete(0, receiver.length()).append(sender.toString());
		}
	}

Main method:

	public static void main(String [] args){
		String message = args[0];
		String sender = args[1];
		String receiver = "";

		StringBuilder m = new StringBuilder();
		StringBuilder s = new StringBuilder();
		StringBuilder r = new StringBuilder();

		m.append(message);
		m.append(sender);
		m.append(receiver);

		//smsProcessing(message, sender, receiver);
		smsProcessing(m, s, r);

		System.out.println("To: "+r.toString());
		System.out.println("Message: "+m.toString());
	}
Console Process:
javac SMSReceiver.java
java SMSReceiver BOS1#Haloooooo 09890909080
Result:
To: 0989889876
Message: Dear bos1, there is message for you, Haloooooo

Full Source code

public class SMSReceiver{
	private static final String BOS1_Number = "0989889876";
	private static final String BOS2_Number = "0989889890";

	public static void main(String [] args){
		String message = args[0];
		String sender = args[1];
		String receiver = "";

		StringBuilder m = new StringBuilder();
		StringBuilder s = new StringBuilder();
		StringBuilder r = new StringBuilder();

		m.append(message);
		m.append(sender);
		m.append(receiver);

		//smsProcessing(message, sender, receiver);
		smsProcessing(m, s, r);

		System.out.println("To: "+r.toString());
		System.out.println("Message: "+m.toString());
	}

	private static void smsProcessing(String message, String sender, String receiver){
		String [] vars = message.split("#");

		if(vars[0].equals("BOS1")){
			message = "Dear bos1, there is message for you, "+vars[1];
			receiver = BOS1_Number;
		}else if(vars[0].equals("BOS2")){
			message = "Dear bos2, there is message for you, "+vars[1];
			receiver = BOS2_Number;
		}else{
			message = "Invalid SMS format.";
			receiver = sender;
		}
	}

	private static void smsProcessing(StringBuilder message, StringBuilder sender, StringBuilder receiver){
		String[] vars = message.toString().split("#");
		if(vars[0].equals("BOS1")){
			String msg = "Dear bos1, there is message for you, "+vars[1];
			message.delete(0, message.length()).append(msg);
			receiver.delete(0, receiver.length()).append(BOS1_Number);
		}else if(vars[0].equals("BOS2")){
			String msg = "Dear bos2, there is message for you, "+vars[1];
			message.delete(0, message.length()).append(msg);
			receiver.delete(0, receiver.length()).append(BOS2_Number);
		}else{
			message.delete(0, message.length()).append("Invalid SMS format.");
			receiver.delete(0, receiver.length()).append(sender.toString());
		}
	}
}

For 2nd and 3rd method, insya Alloh i will explain in other time

Posted in Java | Tagged , , , , , , , , , | Leave a comment

Membuat Stored Procedure di SQL Server

Simple Stored Procedure

Dalam latihan pertama kita akan membuat Stored Procedure yang paling gampang, membuat Hello World. Perhatikan script berikut.

CREATE PROCEDURE Usp_MyProcedure
AS
BEGIN
  PRINT 'Hello World'
END

Usp_MyProcedure adalah nama dari Stored Procedure yang akan dibuat. Awalan Usp digunakan karena kebiasaan/kesepakatan untuk membedakan Stored Procedure yang dibuat oleh sistem dengan yang dibuat oleh user. Usp singkatan dari User Stored Procedure. Setelah memberikan nama kita berikan syntax AS. Setelah itu kita mulai memasukkan logika kita antara syntax BEGIN dan END. Kalau kita sudah sangat familiar di C begin dan end ini fungsinya mirip dengan kurung kurawal buka dan tutup ({ }). PRINT ‘Hello World’ digunakan untuk menampilkan text ‘Hello World’. Setelah script tersebut dibuat, kemudian jalankan (tekan F5 di Microsoft SQL Server Management Studio) untuk menyimpan Stored Procedure dalam database.

Menjalankan/Memanggil Stored Procedure

Untuk memanggilnya nya cukup dengan perintah berikut.

EXEC Usp_MyProcedure

Mengubah Stored Procedure

Dengan mengganti syntax create pada contoh di atas daengan ALTER.

ALTER PROCEDURE Usp_MyProcedure
AS
BEGIN
  PRINT 'New Hello World'
END

Menampilkan Text Stored Procedure yang Sudah Dibuat

SP_HELPTEXT 'Usp_MyProcedure'

Menghapus Stored Procedure

DROP PROCEDURE Usp_MyProcedure

Stored Procedure dengan Parameter

CREATE PROCEDURE Usp_WithParameter
(
@param1 int,
@param2 varchar(50)
)
AS
BEGIN
PRINT 'Param 1: '+cast(@param1 as varchar)
PRINT 'Param 2: '+@param2
END
Posted in Basis Data, Microsoft | Tagged , , , , , , , , , , | 4 Comments

Send Email On Sharepoint Web Part Programmatically

public static bool SendMail(string Subject, string Body, bool IsBodyHtml, string From, string To, string Cc, string Bcc)
	{
		bool mailSent = false;
		try
		{
			SmtpClient smtpClient = new SmtpClient();
			smtpClient.Host = "10.10.2.1";
			smtpClient.Port = 25;
			MailMessage mailMessage = new MailMessage(From, To, Subject, Body);
			if (!String.IsNullOrEmpty(Cc))
			{
				MailAddress CCAddress = new MailAddress(Cc);
				mailMessage.CC.Add(CCAddress);
			}
			if (!String.IsNullOrEmpty(Bcc))
			{
				MailAddress BCCAddress = new MailAddress(Bcc);
				mailMessage.Bcc.Add(BCCAddress);
			}
			mailMessage.IsBodyHtml = IsBodyHtml;
			smtpClient.Send(mailMessage);
			mailSent = true;
		}
		catch (Exception) { return mailSent; }
		return mailSent;
	}
}

sumber: Learning Sharepoint

Posted in Microsoft, Sharepoint | Tagged , , , , , , , | Leave a comment

Cannot connect to the configuration database (Problem: Sharepoint 2010)

Anda mungkin pernah mendapatkan error seperti ini ketika membuka Site sharepoint di lokal.

Penyebab munculnya adalah karena database (SQL Server) yang digunakan oleh sharepoint belum running.  Atau karena masalah lainnya (source: Microsoft Support):

  • Internet Information Services (IIS) is configured to run in IIS 5.0 isolation mode.
  • The account that is used by application pool does not have the required permissions to the SQL Server database.
  • Network connectivity has been lost between the Windows SharePoint Services server and the Microsoft SQL Server server.

Solusi:

  1. Start > Program > Administrative Tools > Services
  2. Cari SQL Server (Sharepoint) pastikan sudah running
Posted in Microsoft, Sharepoint | Tagged , , , , , , , , , , , , | Leave a comment

Kaos Programmer Java

Ayo tunjukan identitas mu. Tempelkan branding untuk Anda sendiri sebagai seorang Programmer Java🙂.

Kaos Java Programmer

Rp 75.000

Ketentuan Pemesanan:

  1. Silahkan isi formulir pemesanan di sini: http://tinyurl.com/744fotp
  2. Anda akan mendapat sms konfirmasi pendaftaran
  3. Silahkan melakukan pembayaran, kemudian konfirmasi pembayaran melalui SMS ke Nomor 087770859749
  4. Kaos Akan kami kirimkan

Rekening tujuan pembayaran:

  • Muamalat 909 164 11 99 a.n. Windu Purnomo
  • Mandiri 1320012219433 a.n. Windu Purnomo

Posted in Bisnis, Java | Tagged , , , , , , , | Leave a comment

Membuat People Editor di Webpart Sharepoint

sharepointSharepoint sudah menyediakan sebuah fungsi/dialog untuk melakukan pencarian terhadap user. Komponen ini dinamakan People Editor atau ada pula yang menyebutnya People Picker, sampai saat ini saya belum tahu apa perbedaan keduanya🙂. Salah satu kasus yang memerlukan komponen ini adalah misalkan pengguna sharepoint ingin melakukan query pada list dengan kriteria Created By. Nah Created By ini biasanya diisi dengan nama user yang diawali dengan domain(“domain/username”). Kalau pengguna mengetikkan nilainya secara langsung dalam sebuah textfield itu kemungkinan kesalahannya cukup besar.

Dalam posting ini saya akan menjelaskan bagaimana cara membuat WebPart yang ada komponen People Editornya ini. Saya ingin coba jelaskan dari awal banget tapi takutnya tidak terlalu fokus pada inti permasalahan. Jadi penjelasannya akan saya mulai dari kondisi  di visual studio sudah ada project sharepoint dengan item visual webpartnya (saya asumsikan pembaca sudah mengetahui cara membuat projek sharepoint dan menambahkan item visual webpart).

Hanya ada dua file yang akan kita oprek2 dalam penjelasan kali ini yaitu, file ascx dan cs pada visual webpart. Jika pembaca membuat sebuah webpart dengan nama Searcher, maka file yang akan kita ‘mainkan’ adalah SearcherUserControl.ascx dan SearcherUserControl.ascx.cs.

Yang pertama kita akan tambahkan beberapa komponen pada file SearcherUserControl.ascx nya (termasuk People Editor). Berikut ini scrip lengkapnya. Continue reading

Posted in C#, Microsoft, Sharepoint | Tagged , , , , , , , | 2 Comments