类 DatabaseLoader
java.lang.Object
weka.core.converters.AbstractLoader
weka.core.converters.DatabaseLoader
- 所有已实现的接口:
Serializable
,BatchConverter
,DatabaseConverter
,IncrementalConverter
,Loader
,OptionHandler
,RevisionHandler
public class DatabaseLoader
extends AbstractLoader
implements BatchConverter, IncrementalConverter, DatabaseConverter, OptionHandler
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. Valid options are:
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. Valid options are:
-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
-
字段概要
从接口继承的字段 weka.core.converters.Loader
BATCH, INCREMENTAL, NONE
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明void
Opens a connection to the databaseReturn the full data set in batch mode (header and all intances at once).getKeys()
Gets the key columns' namegetNextInstance
(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[]
Gets the settingReturns the database passwordgetQuery()
Gets the query to execute against the databaseReturns the revision string.Determines and returns (if possible) the structure (internally the header) of the data set as an empty set of instances.getUrl()
Gets the URLgetUser()
Gets the user nameReturns a string describing this Loaderthe tip text for this propertyLists the available optionsstatic void
Main method.the tip text for this propertythe tip text for this propertyvoid
reset()
Resets the Loader ready to read a new data setvoid
Resets the structure of instancesvoid
Sets the key columns of a database tablevoid
setOptions
(String[] options) Sets the options.void
setPassword
(String password) Sets user password for the databasevoid
Sets the query to execute against the databasevoid
Sets the database url using the DatabaseUtils filevoid
Sets the database urlvoid
Sets the database url, user and pwvoid
Sets the database URLvoid
Sets the database userthe tip text for this propertythe tip text for this property从类继承的方法 weka.core.converters.AbstractLoader
setRetrieval, setSource, setSource
-
构造器详细资料
-
DatabaseLoader
Constructor- 抛出:
Exception
- if initialization fails
-
-
方法详细资料
-
globalInfo
Returns a string describing this Loader- 返回:
- a description of the Loader suitable for displaying in the explorer/experimenter gui
-
reset
Resets the Loader ready to read a new data set- 指定者:
reset
在接口中Loader
- 覆盖:
reset
在类中AbstractLoader
- 抛出:
Exception
- if an error occurs while disconnecting from the database
-
resetStructure
public void resetStructure()Resets the structure of instances -
setQuery
Sets the query to execute against the database- 参数:
q
- the query to execute
-
getQuery
Gets the query to execute against the database- 返回:
- the query
-
queryTipText
the tip text for this property- 返回:
- the tip text
-
setKeys
Sets the key columns of a database table- 参数:
keys
- a String containing the key columns in a comma separated list.
-
getKeys
Gets the key columns' name- 返回:
- name of the key columns'
-
keysTipText
the tip text for this property- 返回:
- the tip text
-
setUrl
Sets the database URL- 指定者:
setUrl
在接口中DatabaseConverter
- 参数:
url
- string with the database URL
-
getUrl
Gets the URL- 指定者:
getUrl
在接口中DatabaseConverter
- 返回:
- the URL
-
urlTipText
the tip text for this property- 返回:
- the tip text
-
setUser
Sets the database user- 指定者:
setUser
在接口中DatabaseConverter
- 参数:
user
- the database user name
-
getUser
Gets the user name- 指定者:
getUser
在接口中DatabaseConverter
- 返回:
- name of database user
-
userTipText
the tip text for this property- 返回:
- the tip text
-
setPassword
Sets user password for the database- 指定者:
setPassword
在接口中DatabaseConverter
- 参数:
password
- the password
-
getPassword
Returns the database password- 返回:
- the database password
-
passwordTipText
the tip text for this property- 返回:
- the tip text
-
setSource
Sets the database url, user and pw- 参数:
url
- the database urluserName
- the user namepassword
- the password
-
setSource
Sets the database url- 参数:
url
- the database url
-
setSource
Sets the database url using the DatabaseUtils file- 抛出:
Exception
- if something goes wrong
-
connectToDatabase
public void connectToDatabase()Opens a connection to the database -
getStructure
Determines and returns (if possible) the structure (internally the header) of the data set as an empty set of instances.- 指定者:
getStructure
在接口中Loader
- 指定者:
getStructure
在类中AbstractLoader
- 返回:
- the structure of the data set as an empty set of Instances
- 抛出:
IOException
- if an error occurs
-
getDataSet
Return the full data set in batch mode (header and all intances at once).- 指定者:
getDataSet
在接口中Loader
- 指定者:
getDataSet
在类中AbstractLoader
- 返回:
- the structure of the data set as an empty set of Instances
- 抛出:
IOException
- if there is no source or parsing fails
-
getNextInstance
Read the data set incrementally---get the next instance in the data set or returns null if there are no more instances to get. If the structure hasn't yet been determined by a call to getStructure then method does so before returning the next instance in the data set.- 指定者:
getNextInstance
在接口中Loader
- 指定者:
getNextInstance
在类中AbstractLoader
- 参数:
structure
- the dataset header information, will get updated in case of string or relational attributes- 返回:
- the next instance in the data set as an Instance object or null if there are no more instances to be read
- 抛出:
IOException
- if there is an error during parsing
-
getOptions
Gets the setting- 指定者:
getOptions
在接口中OptionHandler
- 返回:
- the current setting
-
listOptions
Lists the available options- 指定者:
listOptions
在接口中OptionHandler
- 返回:
- an enumeration of the available options
-
setOptions
Sets the options. Valid options are:-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
在接口中OptionHandler
- 参数:
options
- the options- 抛出:
Exception
- if options cannot be set
-
getRevision
Returns the revision string.- 指定者:
getRevision
在接口中RevisionHandler
- 返回:
- the revision
-
main
Main method.- 参数:
options
- the options
-