|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectweka.core.converters.AbstractLoader
weka.core.converters.DatabaseLoader
public class DatabaseLoader
Reads Instances from a Database. Can read a database in batch or incremental mode.
In inremental mode MySQL and HSQLDB are supported.
For all other DBMS set a pseudoincremental mode is used:
In pseudo incremental mode the instances are read into main memory all at once and then incrementally provided to the user.
For incremental loading the rows in the database table have to be ordered uniquely.
The reason for this is that every time only a single row is fetched by extending the user query by a LIMIT clause.
If this extension is impossible instances will be loaded pseudoincrementally. To ensure that every row is fetched exaclty once, they have to ordered.
Therefore a (primary) key is necessary.This approach is chosen, instead of using JDBC driver facilities, because the latter one differ betweeen different drivers.
If you use the DatabaseSaver and save instances by generating automatically a primary key (its name is defined in DtabaseUtils), this primary key will be used for ordering but will not be part of the output. The user defined SQL query to extract the instances should not contain LIMIT and ORDER BY clauses (see -Q option).
In addition, for incremental loading, you can define in the DatabaseUtils file how many distinct values a nominal attribute is allowed to have. If this number is exceeded, the column will become a string attribute.
In batch mode no string attributes will be created.
-url <JDBC URL> The JDBC URL to connect to. (default: from DatabaseUtils.props file)
-user <name> The user to connect with to the database. (default: none)
-password <password> The password to connect with to the database. (default: none)
-Q <query> SQL query of the form SELECT <list of columns>|* FROM <table> [WHERE] to execute. (default: Select * From Results0)
-P <list of column names> List of column names uniquely defining a DB row (separated by ', '). Used for incremental loading. If not specified, the key will be determined automatically, if possible with the used JDBC driver. The auto ID column created by the DatabaseSaver won't be loaded.
-I Sets incremental loading
Loader,
Serialized Form| Field Summary |
|---|
| Fields inherited from interface weka.core.converters.Loader |
|---|
BATCH, INCREMENTAL, NONE |
| Constructor Summary | |
|---|---|
DatabaseLoader()
Constructor |
|
| Method Summary | |
|---|---|
void |
connectToDatabase()
Opens a connection to the database |
String |
customPropsFileTipText()
The tip text for this property. |
File |
getCustomPropsFile()
Returns the custom properties file in use, if any. |
Instances |
getDataSet()
Return the full data set in batch mode (header and all intances at once). |
String |
getKeys()
Gets the key columns' name |
Instance |
getNextInstance(Instances structure)
Read the data set incrementally---get the next instance in the data set or returns null if there are no more instances to get. |
String[] |
getOptions()
Gets the setting |
String |
getPassword()
Returns the database password |
String |
getQuery()
Gets the query to execute against the database |
String |
getRevision()
Returns the revision string. |
boolean |
getSparseData()
Gets whether data is to be returned as a set of sparse instances |
Instances |
getStructure()
Determines and returns (if possible) the structure (internally the header) of the data set as an empty set of instances. |
String |
getUrl()
Gets the URL |
String |
getUser()
Gets the user name |
String |
globalInfo()
Returns a string describing this Loader |
String |
keysTipText()
the tip text for this property |
Enumeration |
listOptions()
Lists the available options |
static void |
main(String[] options)
Main method. |
String |
passwordTipText()
the tip text for this property |
String |
queryTipText()
the tip text for this property |
void |
reset()
Resets the Loader ready to read a new data set using set options |
void |
resetOptions()
Resets the Loader to the settings in either the default DatabaseUtils.props or any property file that the user has specified via setCustomPropsFile(). |
void |
resetStructure()
Resets the structure of instances |
void |
setCustomPropsFile(File value)
Sets the custom properties file to use. |
void |
setEnvironment(Environment env)
Set the environment variables to use. |
void |
setKeys(String keys)
Sets the key columns of a database table |
void |
setOptions(String[] options)
Sets the options. |
void |
setPassword(String password)
Sets user password for the database |
void |
setQuery(String q)
Sets the query to execute against the database |
void |
setSource()
Sets the database url using the DatabaseUtils file |
void |
setSource(String url)
Sets the database url |
void |
setSource(String url,
String userName,
String password)
Sets the database url, user and pw |
void |
setSparseData(boolean s)
Sets whether data should be encoded as sparse instances |
void |
setUrl(String url)
Sets the database URL |
void |
setUser(String user)
Sets the database user |
String |
sparseDataTipText()
Returns the tip text for this property |
String |
urlTipText()
the tip text for this property |
String |
userTipText()
the tip text for this property |
| Methods inherited from class weka.core.converters.AbstractLoader |
|---|
setRetrieval, setSource, setSource |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DatabaseLoader()
throws Exception
Exception - if initialization fails| Method Detail |
|---|
public String globalInfo()
public void setEnvironment(Environment env)
setEnvironment in interface EnvironmentHandlerenv - the environment variables to usepublic void resetOptions()
public void reset()
reset in interface Loaderreset in class AbstractLoaderException - if an error occurs while disconnecting from the databasepublic void resetStructure()
public void setQuery(String q)
q - the query to executepublic String getQuery()
public String queryTipText()
public void setKeys(String keys)
keys - a String containing the key columns in a comma separated list.public String getKeys()
public String keysTipText()
public void setCustomPropsFile(File value)
value - the custom props file to load database parameters from,
use null or directory to disable custom properties.public File getCustomPropsFile()
public String customPropsFileTipText()
public void setUrl(String url)
setUrl in interface DatabaseConverterurl - string with the database URLpublic String getUrl()
getUrl in interface DatabaseConverterpublic String urlTipText()
public void setUser(String user)
setUser in interface DatabaseConverteruser - the database user namepublic String getUser()
getUser in interface DatabaseConverterpublic String userTipText()
public void setPassword(String password)
setPassword in interface DatabaseConverterpassword - the passwordpublic String getPassword()
public String passwordTipText()
public String sparseDataTipText()
public void setSparseData(boolean s)
s - true if data should be encoded as a set of sparse instancespublic boolean getSparseData()
public void setSource(String url,
String userName,
String password)
url - the database urluserName - the user namepassword - the passwordpublic void setSource(String url)
url - the database url
public void setSource()
throws Exception
Exception - if something goes wrongpublic void connectToDatabase()
public Instances getStructure()
throws IOException
getStructure in interface LoadergetStructure in class AbstractLoaderIOException - if an error occurs
public Instances getDataSet()
throws IOException
getDataSet in interface LoadergetDataSet in class AbstractLoaderIOException - if there is no source or parsing fails
public Instance getNextInstance(Instances structure)
throws IOException
getNextInstance in interface LoadergetNextInstance in class AbstractLoaderstructure - the dataset header information, will get updated in
case of string or relational attributes
IOException - if there is an error during parsingpublic String[] getOptions()
getOptions in interface OptionHandlerpublic Enumeration listOptions()
listOptions in interface OptionHandler
public void setOptions(String[] options)
throws Exception
-url <JDBC URL> The JDBC URL to connect to. (default: from DatabaseUtils.props file)
-user <name> The user to connect with to the database. (default: none)
-password <password> The password to connect with to the database. (default: none)
-Q <query> SQL query of the form SELECT <list of columns>|* FROM <table> [WHERE] to execute. (default: Select * From Results0)
-P <list of column names> List of column names uniquely defining a DB row (separated by ', '). Used for incremental loading. If not specified, the key will be determined automatically, if possible with the used JDBC driver. The auto ID column created by the DatabaseSaver won't be loaded.
-I Sets incremental loading
setOptions in interface OptionHandleroptions - the options
Exception - if options cannot be setpublic String getRevision()
getRevision in interface RevisionHandlerpublic static void main(String[] options)
options - the options
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||