aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::learning::IDBInitializer Class Referenceabstract

The base class for initializing DatabaseTable and RawDatabaseTable instances from CSV files or SQL databases. More...

#include <agrum/base/database/IDBInitializer.h>

Inheritance diagram for gum::learning::IDBInitializer:

Public Types

enum class  InputType : char { STRING , DBCELL }
 the enumeration indicating the type of the data the IDBInitializer expects as input data More...

Public Member Functions

Constructors / Destructors
 IDBInitializer (const InputType type)
 default constructor
 IDBInitializer (const IDBInitializer &from)
 copy constructor
 IDBInitializer (IDBInitializer &&from)
 move constructor
virtual IDBInitializerclone () const =0
 virtual copy constructor
virtual ~IDBInitializer ()
 destructor
Accessors / Modifiers
const std::vector< std::string > & variableNames ()
 returns the names of the variables in the input dataset
template<class DATABASE>
void fillDatabase (DATABASE &database, const bool retry_insertion=false)
 fills the rows of the database table
std::size_t throwingColumn () const
 This method indicates which column filling raised an exception, if any, during the execution of fillDatabase.

Protected Member Functions

IDBInitializeroperator= (const IDBInitializer &from)
 copy operator
IDBInitializeroperator= (IDBInitializer &&from)
 move operator
virtual std::vector< std::string > variableNames_ ()=0
 ask the child class for the names of the variables
virtual const std::vector< std::string > & currentStringRow_ ()
 asks the child class for the content of the current row using strings
virtual const DBRow< DBCell > & currentDBCellRow_ ()
 asks the child class for the content of the current row using dbcells
virtual bool nextRow_ ()=0
 indicates whether there is a next row to read (and point on it)

Detailed Description

The base class for initializing DatabaseTable and RawDatabaseTable instances from CSV files or SQL databases.

Usage example:
// 1/ use the initializer to parse all the columns/rows of a CSV file
// the DBInitializerFromCSV class inherits from IDBInitializer<>
gum::learning::DBInitializerFromCSV<> initializer ( "asia.csv" );
const auto& var_names = initializer.variableNames ();
const std::size_t nb_vars = var_names.size ();
// we create as many translators as there are variables
for ( std::size_t i = 0; i < nb_vars; ++i )
translator_set.insertTranslator ( translator, i );
// create a DatabaseTable with these translators. For the moment, the
// DatabaseTable will be empty, i.e., it will contain no row
gum::learning::DatabaseTable<> database ( translator_set );
database.setVariableNames( initializer.variableNames () );
// use the DBInitializerFromCSV to fill the rows:
initializer.fillDatabase ( database );
// now, the database contains all the content of the CSV file
// 2/ use an IDBInitializer to initialize a DatabaseTable, but ignore
// some columns.
gum::learning::DBInitializerFromCSV<> initializer2 ( "asia.csv" );
gum::learning::DatabaseTable<> database2; // empty database
// indicate which columns of the CSV file should be read
database2.insertTranslator ( translator, 1 );
database2.insertTranslator ( translator, 3 );
database2.insertTranslator ( translator, 4 );
// sets the names of the columns correctly
database2.setVariableNames( initializer2.variableNames () );
// fill the rows:
initializer2.fillDatabase ( database2 );
// now all the rows of the CSV file have been transferred into database2,
// but only columns 1, 3 and 4 of the CSV file have been kept.
// 3/ another possibility to initialize a DatabaseTable, ignoring
// some columns:
gum::learning::DBInitializerFromCSV<> initializer3 ( "asia.csv" );
gum::learning::DatabaseTable<> database3 ( translator_set );
// here, database3 is an empty database but it contains already
// translators for all the columns of the CSV file. We shall now remove
// the columns/translators that are not wanted anymore
database3.ignoreColumn ( 0 );
database3.ignoreColumn ( 2 );
database3.ignoreColumn ( 5 );
database3.ignoreColumn ( 6 );
database3.ignoreColumn ( 7 );
// asia contains 8 columns. The above ignoreColumns keep only columns
// 1, 3 and 4.
// sets the names of the columns correctly
database3.setVariableNames( initializer3.variableNames () );
// fill the rows:
initializer3.fillDatabase ( database3 );
// now all the rows of the CSV file have been transferred into database3,
// but only columns 1, 3 and 4 of the CSV file have been kept.
The class for initializing DatabaseTable and RawDatabaseTable instances from CSV files.
The databases' cell translators for labelized variables.
the class for packing together the translators used to preprocess the datasets
std::size_t insertTranslator(const DBTranslator &translator, const std::size_t column, const bool unique_column=true)
inserts a new translator at the end of the translator set
The class representing a tabular database as used by learning tasks.
void setVariableNames(const std::vector< std::string > &names, const bool from_external_object=true) override
sets the names of the variables
std::size_t insertTranslator(const DBTranslator &translator, const std::size_t input_column, const bool unique_column=true)
insert a new translator into the database table

Definition at line 135 of file IDBInitializer.h.

Member Enumeration Documentation

◆ InputType

enum class gum::learning::IDBInitializer::InputType : char
strong

the enumeration indicating the type of the data the IDBInitializer expects as input data

Enumerator
STRING 
DBCELL 

Definition at line 139 of file IDBInitializer.h.

139: char { STRING, DBCELL };

Constructor & Destructor Documentation

◆ IDBInitializer() [1/3]

gum::learning::IDBInitializer::IDBInitializer ( const InputType type)

default constructor

Parameters
typeindicates what type of data will be read by the IDBInitializer when it will try to fill the database.

Referenced by IDBInitializer(), IDBInitializer(), clone(), operator=(), and operator=().

Here is the caller graph for this function:

◆ IDBInitializer() [2/3]

gum::learning::IDBInitializer::IDBInitializer ( const IDBInitializer & from)

copy constructor

References IDBInitializer().

Here is the call graph for this function:

◆ IDBInitializer() [3/3]

gum::learning::IDBInitializer::IDBInitializer ( IDBInitializer && from)

move constructor

References IDBInitializer().

Here is the call graph for this function:

◆ ~IDBInitializer()

virtual gum::learning::IDBInitializer::~IDBInitializer ( )
virtual

destructor

Member Function Documentation

◆ clone()

virtual IDBInitializer * gum::learning::IDBInitializer::clone ( ) const
pure virtual

virtual copy constructor

Implemented in gum::learning::DBInitializerFromCSV, and gum::learning::DBInitializerFromSQL.

References IDBInitializer().

Here is the call graph for this function:

◆ currentDBCellRow_()

virtual const DBRow< DBCell > & gum::learning::IDBInitializer::currentDBCellRow_ ( )
protectedvirtual

asks the child class for the content of the current row using dbcells

If the child class parses DBRows, this method should be overloaded

◆ currentStringRow_()

virtual const std::vector< std::string > & gum::learning::IDBInitializer::currentStringRow_ ( )
protectedvirtual

asks the child class for the content of the current row using strings

If the child class parses strings, this method should be overloaded

Reimplemented in gum::learning::DBInitializerFromCSV, and gum::learning::DBInitializerFromSQL.

◆ fillDatabase()

template<class DATABASE>
void gum::learning::IDBInitializer::fillDatabase ( DATABASE & database,
const bool retry_insertion = false )

fills the rows of the database table

This method may raise exceptions when trying to insert new rows into the database table. See Method insertRow() of the database table.

Referenced by gum::learning::IBNLearner::Database::Database(), gum::learning::IBNLearner::Database::Database(), gum::learning::readFile(), and gum::learning::IBNLearner::readFile_().

Here is the caller graph for this function:

◆ nextRow_()

virtual bool gum::learning::IDBInitializer::nextRow_ ( )
protectedpure virtual

indicates whether there is a next row to read (and point on it)

Implemented in gum::learning::DBInitializerFromCSV, and gum::learning::DBInitializerFromSQL.

◆ operator=() [1/2]

IDBInitializer & gum::learning::IDBInitializer::operator= ( const IDBInitializer & from)
protected

copy operator

References IDBInitializer().

Here is the call graph for this function:

◆ operator=() [2/2]

IDBInitializer & gum::learning::IDBInitializer::operator= ( IDBInitializer && from)
protected

move operator

References IDBInitializer().

Here is the call graph for this function:

◆ throwingColumn()

std::size_t gum::learning::IDBInitializer::throwingColumn ( ) const

This method indicates which column filling raised an exception, if any, during the execution of fillDatabase.

◆ variableNames()

const std::vector< std::string > & gum::learning::IDBInitializer::variableNames ( )

returns the names of the variables in the input dataset

Referenced by gum::learning::IBNLearner::Database::Database(), gum::learning::IBNLearner::Database::Database(), gum::learning::readFile(), and gum::learning::IBNLearner::readFile_().

Here is the caller graph for this function:

◆ variableNames_()

virtual std::vector< std::string > gum::learning::IDBInitializer::variableNames_ ( )
protectedpure virtual

ask the child class for the names of the variables

Implemented in gum::learning::DBInitializerFromCSV, and gum::learning::DBInitializerFromSQL.


The documentation for this class was generated from the following file: