milk.experiment
Class MIInstanceQuery

java.lang.Object
  |
  +--milk.experiment.MIDatabaseUtils
        |
        +--milk.experiment.MIInstanceQuery
All Implemented Interfaces:
weka.core.OptionHandler, java.io.Serializable

public class MIInstanceQuery
extends MIDatabaseUtils
implements weka.core.OptionHandler

Convert the results of a database query into instances. The jdbc driver and database to be used default to "jdbc.idbDriver" and "jdbc:idb=experiments.prp". These may be changed by creating a java properties file called DatabaseUtils.props in user.home or the current directory. eg:

 jdbcDriver=jdbc.idbDriver
 jdbcURL=jdbc:idb=experiments.prp
 

Command line use just outputs the instances to System.out.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class milk.experiment.MIDatabaseUtils
DRIVERS, EXP_INDEX_TABLE, EXP_RESULT_COL, EXP_RESULT_PREFIX, EXP_SETUP_COL, EXP_TYPE_COL, m_Connection, m_DatabaseURL, m_Debug, m_Statement, PROPERTIES, PROPERTY_FILE
 
Constructor Summary
MIInstanceQuery()
          Sets up the database drivers
 
Method Summary
 java.lang.String[] getOptions()
          Gets the current settings of InstanceQuery
 java.lang.String getQuery()
          Get the query to execute against the database
 boolean getSparseData()
          Gets whether data is to be returned as a set of sparse instances
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options
static void main(java.lang.String[] args)
          Test the class from the command line.
 java.lang.String queryTipText()
          Returns the tip text for this property
 weka.core.Instances retrieveInstances()
          Makes a database query using the query set through the -Q option to convert a table into a set of instances
 weka.core.Instances retrieveInstances(java.lang.String query)
          Makes a database query to convert a table into a set of instances
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 void setQuery(java.lang.String q)
          Set the query to execute against the database
 void setSparseData(boolean s)
          Sets whether data should be encoded as sparse instances
 java.lang.String sparseDataTipText()
          Returns the tip text for this property
 
Methods inherited from class milk.experiment.MIDatabaseUtils
arrayToString, connectToDatabase, createExperimentIndex, createExperimentIndexEntry, createResultsTable, databaseURLTipText, disconnectFromDatabase, execute, experimentIndexExists, getDatabaseURL, getResultFromTable, getResultSet, getResultsTableName, isConnected, isKeyInTable, putResultInTable, setDatabaseURL, tableExists, typeName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MIInstanceQuery

public MIInstanceQuery()
                throws java.lang.Exception
Sets up the database drivers

Throws:
java.lang.Exception - if an error occurs
Method Detail

listOptions

public java.util.Enumeration listOptions()
Returns an enumeration describing the available options

Specified by:
listOptions in interface weka.core.OptionHandler

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Parses a given list of options. Valid options are:

-S
Return a set of sparse instances rather than normal instances.

Specified by:
setOptions in interface weka.core.OptionHandler
Parameters:
options - the list of options as an array of strings
Throws:
java.lang.Exception - if an option is not supported

queryTipText

public java.lang.String queryTipText()
Returns the tip text for this property

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setQuery

public void setQuery(java.lang.String q)
Set the query to execute against the database

Parameters:
q - the query to execute

getQuery

public java.lang.String getQuery()
Get the query to execute against the database

Returns:
the query

sparseDataTipText

public java.lang.String sparseDataTipText()
Returns the tip text for this property

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setSparseData

public void setSparseData(boolean s)
Sets whether data should be encoded as sparse instances

Parameters:
s - true if data should be encoded as a set of sparse instances

getSparseData

public boolean getSparseData()
Gets whether data is to be returned as a set of sparse instances

Returns:
true if data is to be encoded as sparse instances

getOptions

public java.lang.String[] getOptions()
Gets the current settings of InstanceQuery

Specified by:
getOptions in interface weka.core.OptionHandler
Returns:
an array of strings suitable for passing to setOptions()

retrieveInstances

public weka.core.Instances retrieveInstances()
                                      throws java.lang.Exception
Makes a database query using the query set through the -Q option to convert a table into a set of instances

Returns:
the instances contained in the result of the query
Throws:
java.lang.Exception - if an error occurs

retrieveInstances

public weka.core.Instances retrieveInstances(java.lang.String query)
                                      throws java.lang.Exception
Makes a database query to convert a table into a set of instances

Parameters:
query - the query to convert to instances
Returns:
the instances contained in the result of the query
Throws:
java.lang.Exception - if an error occurs

main

public static void main(java.lang.String[] args)
Test the class from the command line. The instance query should be specified with -Q sql_query

Parameters:
args - contains options for the instance query