00001 package edu.tum.cs.bayesnets.learning;
00002
00003 import edu.ksu.cis.bnj.ver3.core.*;
00004 import java.sql.Connection;
00005 import java.sql.DriverManager;
00006 import java.sql.ResultSet;
00007 import java.sql.SQLException;
00008 import java.sql.Statement;
00009 import edu.tum.cs.bayesnets.core.BeliefNetworkEx;
00010 import weka.core.Instance;
00011 import edu.ksu.cis.bnj.ver3.core.BeliefNode;
00012
00017 public abstract class Learner {
00018
00022 protected BeliefNetworkEx bn;
00023
00027 protected BeliefNode[] nodes;
00028
00032 protected boolean finished = false;
00033
00038 public Learner(BeliefNetworkEx bn) {
00039 this.bn = bn;
00040 nodes = this.bn.bn.getNodes();
00041 }
00042
00047 public Learner(BeliefNetwork bn) {
00048 this.bn = new BeliefNetworkEx(bn);
00049 nodes = this.bn.bn.getNodes();
00050 }
00051
00059 public BeliefNetworkEx getNetwork() {
00060 return bn;
00061 }
00062
00071 public void learn(String sqlQuery, String dbConnectString) throws Exception, SQLException {
00072
00073 Connection conn = DriverManager.getConnection(dbConnectString);
00074
00075
00076 Statement stmt = conn.createStatement();
00077 ResultSet rs = stmt.executeQuery(sqlQuery);
00078
00079 learn(rs);
00080 }
00081
00088 public void finish() throws Exception {
00089 if(!finished) {
00090 end_learning();
00091 finished = true;
00092 }
00093 }
00094
00099 protected abstract void end_learning() throws Exception;
00100
00101 public abstract void learn(ResultSet rs) throws Exception;
00102 }