aGrUM  0.13.2
gum::learning::IDBInitializer< ALLOC > Class Template Referenceabstract

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

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

+ Inheritance diagram for gum::learning::IDBInitializer< ALLOC >:

Public Member Functions

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

Public Types

enum  InputType : char { InputType::STRING, InputType::DBCELL }
 the enumeration indicating the type of the data the IDBInitializer expects as input data More...
 
using allocator_type = ALLOC< std::string >
 type for the allocators passed in arguments of methods More...
 

Protected Member Functions

IDBInitializer< ALLOC > & operator= (const IDBInitializer< ALLOC > &from)
 copy operator More...
 
IDBInitializer< ALLOC > & operator= (IDBInitializer< ALLOC > &&from)
 move operator More...
 
virtual std::vector< std::string, ALLOC< std::string > > _variableNames ()=0
 ask the child class for the names of the variables More...
 
virtual const std::vector< std::string, ALLOC< std::string > > & _currentStringRow ()
 asks the child class for the content of the current row using strings More...
 
virtual const DBRow< DBCell, ALLOC > & _currentDBCellRow ()
 asks the child class for the content of the current row using dbcells More...
 
virtual bool _nextRow ()=0
 indicates whether there is a next row to read (and point on it) More...
 

Detailed Description

template<template< typename > class ALLOC>
class gum::learning::IDBInitializer< ALLOC >

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.

Definition at line 114 of file IDBInitializer.h.

Member Typedef Documentation

template<template< typename > class ALLOC>
using gum::learning::IDBInitializer< ALLOC >::allocator_type = ALLOC< std::string >

type for the allocators passed in arguments of methods

Definition at line 121 of file IDBInitializer.h.

Member Enumeration Documentation

template<template< typename > class ALLOC>
enum 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 118 of file IDBInitializer.h.

118 : char { STRING, DBCELL };

Constructor & Destructor Documentation

template<template< typename > class ALLOC>
gum::learning::IDBInitializer< ALLOC >::IDBInitializer ( const InputType  type,
const allocator_type alloc 
)

default constructor

Parameters
typeindicates what type of data will be read by the IDBInitializer when it will try to fill the database.
allocThe allocator that will be used by all methods
template<template< typename > class ALLOC>
gum::learning::IDBInitializer< ALLOC >::IDBInitializer ( const IDBInitializer< ALLOC > &  from)

copy constructor

template<template< typename > class ALLOC>
gum::learning::IDBInitializer< ALLOC >::IDBInitializer ( const IDBInitializer< ALLOC > &  from,
const allocator_type alloc 
)

copy constructor with a given allocator

template<template< typename > class ALLOC>
gum::learning::IDBInitializer< ALLOC >::IDBInitializer ( IDBInitializer< ALLOC > &&  from)

move constructor

template<template< typename > class ALLOC>
gum::learning::IDBInitializer< ALLOC >::IDBInitializer ( IDBInitializer< ALLOC > &&  from,
const allocator_type alloc 
)

move constructor with a given allocator

template<template< typename > class ALLOC>
virtual gum::learning::IDBInitializer< ALLOC >::~IDBInitializer ( )
virtual

destructor

Member Function Documentation

template<template< typename > class ALLOC>
virtual const DBRow< DBCell, ALLOC >& gum::learning::IDBInitializer< ALLOC >::_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

template<template< typename > class ALLOC>
virtual const std::vector< std::string, ALLOC< std::string > >& gum::learning::IDBInitializer< ALLOC >::_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::DBInitializerFromSQL< ALLOC >, and gum::learning::DBInitializerFromCSV< ALLOC >.

template<template< typename > class ALLOC>
virtual bool gum::learning::IDBInitializer< ALLOC >::_nextRow ( )
protectedpure virtual

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

Implemented in gum::learning::DBInitializerFromSQL< ALLOC >, and gum::learning::DBInitializerFromCSV< ALLOC >.

template<template< typename > class ALLOC>
virtual std::vector< std::string, ALLOC< std::string > > gum::learning::IDBInitializer< ALLOC >::_variableNames ( )
protectedpure virtual

ask the child class for the names of the variables

Implemented in gum::learning::DBInitializerFromSQL< ALLOC >, and gum::learning::DBInitializerFromCSV< ALLOC >.

template<template< typename > class ALLOC>
virtual IDBInitializer< ALLOC >* gum::learning::IDBInitializer< ALLOC >::clone ( ) const
pure virtual
template<template< typename > class ALLOC>
virtual IDBInitializer< ALLOC >* gum::learning::IDBInitializer< ALLOC >::clone ( const allocator_type alloc) const
pure virtual

virtual copy constructor with a given allocator

Implemented in gum::learning::DBInitializerFromSQL< ALLOC >, and gum::learning::DBInitializerFromCSV< ALLOC >.

template<template< typename > class ALLOC>
template<template< template< typename > class > class DATABASE>
void gum::learning::IDBInitializer< ALLOC >::fillDatabase ( DATABASE< ALLOC > &  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::genericBNLearner::__readFile(), gum::learning::genericBNLearner::Database::Database(), and gum::learning::readFile().

+ Here is the caller graph for this function:

template<template< typename > class ALLOC>
allocator_type gum::learning::IDBInitializer< ALLOC >::getAllocator ( ) const

returns the allocator used

template<template< typename > class ALLOC>
IDBInitializer< ALLOC >& gum::learning::IDBInitializer< ALLOC >::operator= ( const IDBInitializer< ALLOC > &  from)
protected

copy operator

template<template< typename > class ALLOC>
IDBInitializer< ALLOC >& gum::learning::IDBInitializer< ALLOC >::operator= ( IDBInitializer< ALLOC > &&  from)
protected

move operator

template<template< typename > class ALLOC>
std::size_t gum::learning::IDBInitializer< ALLOC >::throwingColumn ( ) const

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

template<template< typename > class ALLOC>
const std::vector< std::string, ALLOC< std::string > >& gum::learning::IDBInitializer< ALLOC >::variableNames ( )

returns the names of the variables in the input dataset

Referenced by gum::learning::genericBNLearner::__readFile(), gum::learning::genericBNLearner::Database::Database(), and gum::learning::readFile().

+ Here is the caller graph for this function:


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