aGrUM  0.13.2
gum::learning::DBRowGeneratorParser< ALLOC > Class Template Reference

the class used to read a row in the database and to transform it into a set of DBRow instances that can be used for learning. More...

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

Public Member Functions

Constructors / Destructors
 DBRowGeneratorParser (const typename DatabaseTable< ALLOC >::Handler &handler, const DBRowGeneratorSet< ALLOC > &generator_set, const allocator_type &alloc=allocator_type())
 default constructor More...
 
 DBRowGeneratorParser (const DBRowGeneratorParser< ALLOC > &from)
 copy constructor More...
 
 DBRowGeneratorParser (const DBRowGeneratorParser< ALLOC > &from, const allocator_type &alloc)
 copy constructor with a given allocator More...
 
 DBRowGeneratorParser (DBRowGeneratorParser< ALLOC > &&filter)
 move constructor More...
 
 DBRowGeneratorParser (DBRowGeneratorParser< ALLOC > &&filter, const allocator_type &alloc)
 move constructor with a given allocator More...
 
virtual DBRowGeneratorParser< ALLOC > * clone () const
 virtual copy constructor More...
 
virtual DBRowGeneratorParser< ALLOC > * clone (const allocator_type &alloc) const
 virtual copy constructor with a given allocator More...
 
virtual ~DBRowGeneratorParser ()
 destructor More...
 
Operators
DBRowGeneratorParser< ALLOC > & operator= (const DBRowGeneratorParser< ALLOC > &from)
 copy operator More...
 
DBRowGeneratorParser< ALLOC > & operator= (DBRowGeneratorParser< ALLOC > &&from)
 move operator More...
 
Accessors / Modifiers
bool hasRows ()
 returns true if there are still rows that can be output by the DBRowGeneratorParser More...
 
const DBRow< DBTranslatedValue, ALLOC > & row ()
 returns a new output row with its corresponding weight More...
 
void reset ()
 resets the parser More...
 
DatabaseTable< ALLOC >::Handler & handler ()
 returns the handler used by the parser More...
 
const DatabaseTable< ALLOC >::Handler & handler () const
 returns the handler used by the parser More...
 
DBRowGeneratorSet< ALLOC > & generatorSet ()
 returns the generator set that is actually used More...
 
const DBRowGeneratorSet< ALLOC > & generatorSet () const
 returns the generator set that is actually used More...
 
void setColumnsOfInterest (const std::vector< std::size_t, ALLOC< std::size_t >> &cols_of_interest)
 sets the columns of interest: the output DBRow needs only contain values fot these columns More...
 
void setColumnsOfInterest (std::vector< std::size_t, ALLOC< std::size_t >> &&cols_of_interest)
 sets the columns of interest: the output DBRow needs only contain values fot these columns More...
 
allocator_type getAllocator () const
 returns the allocator used More...
 

Public Types

using allocator_type = ALLOC< DBTranslatedValue >
 type for the allocators passed in arguments of methods More...
 

Detailed Description

template<template< typename > class ALLOC = std::allocator>
class gum::learning::DBRowGeneratorParser< ALLOC >

the class used to read a row in the database and to transform it into a set of DBRow instances that can be used for learning.

A DBRowGeneratorParser contains a handler on a DatabaseTable that enables it to parse DBRows contained in the DatabaseTable. It also contains a DBRowGeneratorSet that is used to create output rows for each parsed DBRow. Note that if the DBRowGeneratorSet is empty, then DBRowGeneratorParser simply outputs each parsed DBRow without additional processing. To understand the difference between a DBRowGeneratorParser and a DBRowGeneratorSet, the latter is designed to take as input only one DBRow instance and to produce some output DBRow instances, whereas the former is designed to parse the content of a DatabaseTable and to produce from them some output DBRow instances.

Usage example:
// create and fill a database
.....
// create a vector with the types of the columns of database
const std::vector<gum::learning::DBTranslatedValueType>
// create a generator set
gum::learning::MyGenerator<> generator1 ( col_types, 6 );
gum::learning::MyGenerator2<> generator2 ( col_types, 4 );
genset.insertGenerator ( generator1 );
genset.insertGenerator ( generator2 );
// create the DBRowGeneratorParser
parser ( database.handler (), genset );
// use the parser to parse all the database and to apply all the
// transformations induced by generator1 and generator2
while ( parser.hasRows () ) {
const auto& dbrow = parser.row();
// do something with dbrow
}

Definition at line 86 of file DBRowGeneratorParser.h.

Member Typedef Documentation

template<template< typename > class ALLOC = std::allocator>
using gum::learning::DBRowGeneratorParser< ALLOC >::allocator_type = ALLOC<DBTranslatedValue>

type for the allocators passed in arguments of methods

Definition at line 90 of file DBRowGeneratorParser.h.

Constructor & Destructor Documentation

template<template< typename > class ALLOC = std::allocator>
gum::learning::DBRowGeneratorParser< ALLOC >::DBRowGeneratorParser ( const typename DatabaseTable< ALLOC >::Handler &  handler,
const DBRowGeneratorSet< ALLOC > &  generator_set,
const allocator_type alloc = allocator_type() 
)

default constructor

template<template< typename > class ALLOC = std::allocator>
gum::learning::DBRowGeneratorParser< ALLOC >::DBRowGeneratorParser ( const DBRowGeneratorParser< ALLOC > &  from)

copy constructor

template<template< typename > class ALLOC = std::allocator>
gum::learning::DBRowGeneratorParser< ALLOC >::DBRowGeneratorParser ( const DBRowGeneratorParser< ALLOC > &  from,
const allocator_type alloc 
)

copy constructor with a given allocator

template<template< typename > class ALLOC = std::allocator>
gum::learning::DBRowGeneratorParser< ALLOC >::DBRowGeneratorParser ( DBRowGeneratorParser< ALLOC > &&  filter)

move constructor

template<template< typename > class ALLOC = std::allocator>
gum::learning::DBRowGeneratorParser< ALLOC >::DBRowGeneratorParser ( DBRowGeneratorParser< ALLOC > &&  filter,
const allocator_type alloc 
)

move constructor with a given allocator

template<template< typename > class ALLOC = std::allocator>
virtual gum::learning::DBRowGeneratorParser< ALLOC >::~DBRowGeneratorParser ( )
virtual

destructor

Member Function Documentation

template<template< typename > class ALLOC = std::allocator>
virtual DBRowGeneratorParser<ALLOC>* gum::learning::DBRowGeneratorParser< ALLOC >::clone ( ) const
virtual

virtual copy constructor

template<template< typename > class ALLOC = std::allocator>
virtual DBRowGeneratorParser<ALLOC>* gum::learning::DBRowGeneratorParser< ALLOC >::clone ( const allocator_type alloc) const
virtual

virtual copy constructor with a given allocator

template<template< typename > class ALLOC = std::allocator>
DBRowGeneratorSet<ALLOC>& gum::learning::DBRowGeneratorParser< ALLOC >::generatorSet ( )

returns the generator set that is actually used

template<template< typename > class ALLOC = std::allocator>
const DBRowGeneratorSet<ALLOC>& gum::learning::DBRowGeneratorParser< ALLOC >::generatorSet ( ) const

returns the generator set that is actually used

template<template< typename > class ALLOC = std::allocator>
allocator_type gum::learning::DBRowGeneratorParser< ALLOC >::getAllocator ( ) const

returns the allocator used

template<template< typename > class ALLOC = std::allocator>
DatabaseTable<ALLOC>::Handler& gum::learning::DBRowGeneratorParser< ALLOC >::handler ( )

returns the handler used by the parser

template<template< typename > class ALLOC = std::allocator>
const DatabaseTable<ALLOC>::Handler& gum::learning::DBRowGeneratorParser< ALLOC >::handler ( ) const

returns the handler used by the parser

template<template< typename > class ALLOC = std::allocator>
bool gum::learning::DBRowGeneratorParser< ALLOC >::hasRows ( )

returns true if there are still rows that can be output by the DBRowGeneratorParser

The usual way of calling this method is to encapsulate it into a while loop whose stopping condition is when the handler has no more rows. This loop shall be inside a try-catch statement that enables to stop properly the loop when the NotFound exception is raised. In most practical cases, this exception will never be raised, but if you use a row generator that enables to return 0 row (say, for instance an intelligent EM that does not return any row when there are too many missing data) and if the last rows of the database are such that this generator will return no row, then the exception will be raised. Actually, it is not efficient to parse all the database to detect such a case before trying to return the rows, especially because this situation is very unlikely to occur. So a correct code to use method row () is like:

try {
while ( parser.hasRows () ) {
const auto& row = parser.row ();
do_whatever_you_want_with_the_row... ;
}
}
catch ( NotFound& ) { // stop, there are no more rows to process }
template<template< typename > class ALLOC = std::allocator>
DBRowGeneratorParser<ALLOC>& gum::learning::DBRowGeneratorParser< ALLOC >::operator= ( const DBRowGeneratorParser< ALLOC > &  from)

copy operator

template<template< typename > class ALLOC = std::allocator>
DBRowGeneratorParser<ALLOC>& gum::learning::DBRowGeneratorParser< ALLOC >::operator= ( DBRowGeneratorParser< ALLOC > &&  from)

move operator

template<template< typename > class ALLOC = std::allocator>
void gum::learning::DBRowGeneratorParser< ALLOC >::reset ( )

resets the parser

template<template< typename > class ALLOC = std::allocator>
const DBRow<DBTranslatedValue,ALLOC>& gum::learning::DBRowGeneratorParser< ALLOC >::row ( )

returns a new output row with its corresponding weight

The usual way of calling this method is to encapsulate it into a while loop whose stopping condition is when the handler has no more rows. This loop shall be inside a try-catch statement that enables to stop properly the loop when the NotFound exception is raised. In most practical cases, this exception will never be raised, but if you use a row generator that enables to return 0 row (say, for instance an intelligent EM that does not return any row when there are too many missing data) and if the last rows of the database are such that this generator will return no row, then the exception will be raised. Actually, it is not efficient to parse all the database to detect such a case before trying to return the rows, especially because this situation is very unlikely to occur. So a correct code to use method row () is like:

try {
while ( parser.hasRows () ) {
const auto& row = parser.row ();
do_whatever_you_want_with_the_row... ;
}
}
catch ( NotFound& ) { // stop, there are no more rows to process }
template<template< typename > class ALLOC = std::allocator>
void gum::learning::DBRowGeneratorParser< ALLOC >::setColumnsOfInterest ( const std::vector< std::size_t, ALLOC< std::size_t >> &  cols_of_interest)

sets the columns of interest: the output DBRow needs only contain values fot these columns

This method is useful, e.g., for EM-like algorithms that need to know which unobserved variables/values need be filled.

Exceptions
OperationNotAllowedis raised if the generator set has already started generating output rows and is currently in a state where the generation is not completed yet (i.e., we still need to call the generate() method to complete it).
template<template< typename > class ALLOC = std::allocator>
void gum::learning::DBRowGeneratorParser< ALLOC >::setColumnsOfInterest ( std::vector< std::size_t, ALLOC< std::size_t >> &&  cols_of_interest)

sets the columns of interest: the output DBRow needs only contain values fot these columns

This method is useful, e.g., for EM-like algorithms that need to know which unobserved variables/values need be filled.

Exceptions
OperationNotAllowedis raised if the generator set has already started generating output rows and is currently in a state where the generation is not completed yet (i.e., we still need to call the generate() method to complete it).

Member Data Documentation

template<template< typename > class ALLOC = std::allocator>
DBRowGeneratorSet<ALLOC> gum::learning::DBRowGeneratorParser< ALLOC >::__generator_set
private

the set of DBRow generators (might be empty)

Definition at line 258 of file DBRowGeneratorParser.h.

template<template< typename > class ALLOC = std::allocator>
std::size_t gum::learning::DBRowGeneratorParser< ALLOC >::__generator_size
private

the size of the generator set

Definition at line 261 of file DBRowGeneratorParser.h.

template<template< typename > class ALLOC = std::allocator>
DatabaseTable<ALLOC>::Handler gum::learning::DBRowGeneratorParser< ALLOC >::__handler
private

the handler that is really used to parse the database

Definition at line 255 of file DBRowGeneratorParser.h.


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