[jboss-svn-commits] JBL Code SVN: r19270 - labs/jbossrules/contrib/machinelearning/dt_examples/src/java/examples.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Mar 27 17:59:06 EDT 2008


Author: gizil
Date: 2008-03-27 17:59:06 -0400 (Thu, 27 Mar 2008)
New Revision: 19270

Modified:
   labs/jbossrules/contrib/machinelearning/dt_examples/src/java/examples/CarExample.java
   labs/jbossrules/contrib/machinelearning/dt_examples/src/java/examples/NurseryExample.java
Log:
less code for reading data

Modified: labs/jbossrules/contrib/machinelearning/dt_examples/src/java/examples/CarExample.java
===================================================================
--- labs/jbossrules/contrib/machinelearning/dt_examples/src/java/examples/CarExample.java	2008-03-27 21:41:18 UTC (rev 19269)
+++ labs/jbossrules/contrib/machinelearning/dt_examples/src/java/examples/CarExample.java	2008-03-27 21:59:06 UTC (rev 19270)
@@ -1,5 +1,6 @@
 package examples;
 
+import id3.BocukFileExample;
 import id3.DecisionTree;
 import id3.DecisionTreeBuilder;
 import id3.FactSetFactory;
@@ -18,6 +19,18 @@
 	
 	
 	public static final void main(final String[] args) throws Exception {
+		
+		/*
+		 * | class values 
+		 * 		unacc, acc, good, vgood
+		 * | attributes
+		 * 		buying: vhigh, high, med, low. 
+		 * 		maint: vhigh, high, med, low. 
+		 * 		doors: 2, 3, 4, 5, more. 
+		 * 		persons: 2, 4, more. 
+		 * 		lug_boot: small, med, big.
+		 * 		safety: low, med, high.
+		 */
 
 		int action = 1; /* create the drl */
 		//int action = 2; /* parse the drl */
@@ -25,7 +38,8 @@
 		String drlFile = new String("cars"+".drl");
 		switch (action) {
 		case 1:
-			readCars(drlFile);
+			Object car = new Car();
+			BocukFileExample.processFileExample(car, drlFile, "../data/car/car.data.txt", ",", "target");
 			
 			break;
 		case 2:
@@ -60,49 +74,7 @@
 		}
 
 	}	
-	
-	public static void readCars(String file) {
-		
-		/*
-		 * | class values 
-		 * 		unacc, acc, good, vgood
-		 * | attributes
-		 * 		buying: vhigh, high, med, low. 
-		 * 		maint: vhigh, high, med, low. 
-		 * 		doors: 2, 3, 4, 5, more. 
-		 * 		persons: 2, 4, more. 
-		 * 		lug_boot: small, med, big.
-		 * 		safety: low, med, high.
-		 */
 
-		Car emptyCar = new Car();
-		String filename = "../data/car/car.data.txt";
-		String separator = ",";	
-		WorkingMemory simple = new WorkingMemory();
-		
-		//FactSetFactory.readObjectData(simple, filename, separator, emptyCar);
-		
-		try {
-			FactSetFactory.fromFileAsObject(simple, emptyCar.getClass(), filename, separator);
-			DecisionTreeBuilder bocuk = new DecisionTreeBuilder();
-
-			long dt = System.currentTimeMillis();
-			DecisionTree bocuksTree = bocuk.build(simple, emptyCar.getClass().getName(), "target", null);
-			dt = System.currentTimeMillis() - dt;
-			System.out.println("Time" + dt + "\n" + bocuksTree);
-
-			RulePrinter my_printer = new RulePrinter();
-			my_printer.printer(bocuksTree, "examples", "src/rules/examples/"+file);
-			
-		} catch (Exception e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-
-		
-	}
-
-
 }
 
 

Modified: labs/jbossrules/contrib/machinelearning/dt_examples/src/java/examples/NurseryExample.java
===================================================================
--- labs/jbossrules/contrib/machinelearning/dt_examples/src/java/examples/NurseryExample.java	2008-03-27 21:41:18 UTC (rev 19269)
+++ labs/jbossrules/contrib/machinelearning/dt_examples/src/java/examples/NurseryExample.java	2008-03-27 21:59:06 UTC (rev 19270)
@@ -1,10 +1,6 @@
 package examples;
 
-import id3.DecisionTree;
-import id3.DecisionTreeBuilder;
-import id3.FactSetFactory;
-import id3.RulePrinter;
-import id3.WorkingMemory;
+import id3.BocukFileExample;
 
 import java.io.InputStreamReader;
 import java.io.Reader;
@@ -18,6 +14,7 @@
 	
 	
 	public static final void main(final String[] args) throws Exception {
+		
 
 		int action = 1; /* create the drl */
 		//int action = 2; /* parse the drl */
@@ -25,7 +22,8 @@
 		String drlFile = new String("nurseries"+".drl");
 		switch (action) {
 		case 1:
-			readNursery(drlFile);
+			Object nurse = new Nursery();
+			BocukFileExample.processFileExample(nurse, drlFile, "../data/nursery/nursery.data.txt", ",", "classnursery");
 			
 			break;
 		case 2:
@@ -63,48 +61,9 @@
 
 	}	
 	
-	public static void readNursery(String file) {
-		
-		/*
-		 * | class values 
-		 * 		unacc, acc, good, vgood
-		 * | attributes
-		 * 		buying: vhigh, high, med, low. 
-		 * 		maint: vhigh, high, med, low. 
-		 * 		doors: 2, 3, 4, 5, more. 
-		 * 		persons: 2, 4, more. 
-		 * 		lug_boot: small, med, big.
-		 * 		safety: low, med, high.
-		 */
+	
 
-		Nursery emptyCar = new Nursery();
-		String filename = "../data/nursery/nursery.data.txt";
-		String separator = ",";	
-		WorkingMemory simple = new WorkingMemory();
-		
-		//FactSetFactory.readObjectData(simple, filename, separator, emptyCar);
-		
-		try {
-			FactSetFactory.fromFileAsObject(simple, emptyCar.getClass(), filename, separator);
-			DecisionTreeBuilder bocuk = new DecisionTreeBuilder();
 
-			long dt = System.currentTimeMillis();
-			DecisionTree bocuksTree = bocuk.build(simple, emptyCar.getClass().getName(), "classnursery", null);
-			dt = System.currentTimeMillis() - dt;
-			System.out.println("Time" + dt + "\n" + bocuksTree);
-
-			RulePrinter my_printer = new RulePrinter();
-			my_printer.printer(bocuksTree, "examples", "src/rules/examples/"+file);
-			
-		} catch (Exception e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-
-		
-	}
-
-
 }
 
 




More information about the jboss-svn-commits mailing list