aGrUM  0.13.2
gum::learning::DBCell Class Reference

The class representing the original values of the cells of databases. More...

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

Public Member Functions

Constructors / Destructors
 DBCell ()
 default constructor (ontains a missing value) More...
 
 DBCell (const float nb)
 constructor for a real number More...
 
 DBCell (const int nb)
 constructor for an integer number More...
 
 DBCell (const std::string &str)
 constructor for a string More...
 
 DBCell (const DBCell &from)
 copy constructor More...
 
 DBCell (DBCell &&from)
 move constructor More...
 
 ~DBCell ()
 destructor More...
 
Operators
DBCelloperator= (const DBCell &from)
 copy operator More...
 
DBCelloperator= (DBCell &&from)
 move operator More...
 
DBCelloperator= (const float x)
 assignment operator More...
 
DBCelloperator= (const int x)
 assignment operator More...
 
DBCelloperator= (const std::string &x)
 assignment operator More...
 
bool operator== (const DBCell &from) const
 test of equality More...
 
bool operator!= (const DBCell &from) const
 test of inequality More...
 
Accessors / Modifiers
EltType type () const noexcept
 returns the current type of the DBCell More...
 
bool convertType (const EltType newtype)
 try to convert the content of the DBCell into another type More...
 
float real () const
 returns the DBcell as a real number More...
 
void setReal (const float x)
 sets the content of the DBCell More...
 
void setReal (const std::string &elt)
 sets the content of the DBCell from a string More...
 
int integer () const
 returns the DBcell as an integer More...
 
void setInteger (const int x)
 sets the content of the DBCell More...
 
void setInteger (const std::string &elt)
 sets the content of the DBCell from a string More...
 
const std::string & string () const
 returns the DBcell as a string More...
 
int stringIndex () const
 returns the DBcell as the index of a string in a static bijection More...
 
void setString (const std::string &elt)
 sets the content of the DBCell More...
 
void setMissingState ()
 sets the DBCell as a missing element More...
 
bool isMissing () const
 indicates whether the cell contains a missing value More...
 

Public Types

enum  EltType : unsigned char { EltType::REAL, EltType::INTEGER, EltType::STRING, EltType::MISSING }
 the set of types possibly taken by the last element read More...
 

Public Static Accessors / Modifiers

template<template< typename > class ALLOC = std::allocator>
std::string toString (const std::vector< std::string, ALLOC< std::string > > &missingVals) const
 returns the content of the DBCell as a string, whatever its type More...
 
static const std::string & string (const int index)
 strings are stored into a static bijection. Get its ith string More...
 
template<template< typename > class ALLOC = std::allocator>
static EltType bestType (const std::string &str, const std::vector< std::string, ALLOC< std::string > > &missingVals)
 returns the best type to store a given element encoded as a string More...
 
template<template< typename > class ALLOC = std::allocator>
static DBCell bestDBCell (const std::string &str, const std::vector< std::string, ALLOC< std::string > > &missingVals)
 returns the DBCell with the best type for an element encoded as a string More...
 
static bool isInteger (const std::string &str)
 determines whether a string corresponds precisely to an integer More...
 
static bool isReal (const std::string &str)
 determine whether a string corresponds precisely to a real number More...
 
template<template< typename > class ALLOC = std::allocator>
static bool isMissing (const std::string &str, const std::vector< std::string, ALLOC< std::string > > &missingVals)
 checks whether a string correspond to a missing value More...
 

Detailed Description

The class representing the original values of the cells of databases.

Learning algorithms read input data, the so-called datasets, and infer their models. To be fast, they should not parse directly the original datasets, which are often databases of strings, but rather they should parse preprocessed data with types more suited for fast analysis. To do so, in aGrUM, learning algorithms parse datasets of DBTranslatedValue instances. However, sometimes, these algorithms make some decisions which, afterwards, they may realize were not so good and should be modified. For instance, when coping with continuous variables, they may use a discretization for fast learning the structure of a hybrid Bayesian network. But, given the structure found, they may try to find a better discretization. With a new discretization, the original dataset should be parsed again and mapped into new DBTranslatedValue instances. Unfortunately, reparsing, say, a CSV file or a SQL database, is time consuming. Sometimes, it is faster to read such datasets once and store them in an appropriate form that can be mapped easily into DBTranslatedValue instances. The RawDatabaseTable class is made precisely for this purpose and can be thought of as a 2-dimensional table, the elements of which are DBCell instances. The latter can actually encode compactly integers, real numbers, strings and even missing values. So they are very well suited to be the type of the cells of the RawDatabaseTable class.

Definition at line 69 of file DBCell.h.

Member Enumeration Documentation

enum gum::learning::DBCell::EltType : unsigned char
strong

the set of types possibly taken by the last element read

Enumerator
REAL 
INTEGER 
STRING 
MISSING 

Definition at line 72 of file DBCell.h.

72 : unsigned char { REAL, INTEGER, STRING, MISSING };

Constructor & Destructor Documentation

gum::learning::DBCell::DBCell ( )

default constructor (ontains a missing value)

gum::learning::DBCell::DBCell ( const float  nb)

constructor for a real number

gum::learning::DBCell::DBCell ( const int  nb)

constructor for an integer number

gum::learning::DBCell::DBCell ( const std::string &  str)

constructor for a string

gum::learning::DBCell::DBCell ( const DBCell from)

copy constructor

gum::learning::DBCell::DBCell ( DBCell &&  from)

move constructor

gum::learning::DBCell::~DBCell ( )

destructor

Member Function Documentation

template<template< typename > class ALLOC = std::allocator>
static DBCell gum::learning::DBCell::bestDBCell ( const std::string &  str,
const std::vector< std::string, ALLOC< std::string > > &  missingVals 
)
static

returns the DBCell with the best type for an element encoded as a string

Parameters
strthe string to convert into a DBCell
missingValsa vector containing the set of strings that should be interpreted as missing values. Whenever str matches one these strings, the returned DBCell represents a missing value.
template<template< typename > class ALLOC = std::allocator>
static EltType gum::learning::DBCell::bestType ( const std::string &  str,
const std::vector< std::string, ALLOC< std::string > > &  missingVals 
)
static

returns the best type to store a given element encoded as a string

Parameters
strthe string to convert into a DBCell
missingValsa vector containing the set of strings that should be interpreted as missing values. Whenever str matches one these strings, the returned EltType represents a missing value.
bool gum::learning::DBCell::convertType ( const EltType  newtype)

try to convert the content of the DBCell into another type

Returns
true if the conversion has been successfully performed.
int gum::learning::DBCell::integer ( ) const

returns the DBcell as an integer

Warning
if the cell is not of type INTEGER, the dbcell will not try to convert its content into a float, it will raise a TypeError exception.
Exceptions
TypeErrorif the DBCell is not labelled as type INTEGER
static bool gum::learning::DBCell::isInteger ( const std::string &  str)
static

determines whether a string corresponds precisely to an integer

bool gum::learning::DBCell::isMissing ( ) const

indicates whether the cell contains a missing value

template<template< typename > class ALLOC = std::allocator>
static bool gum::learning::DBCell::isMissing ( const std::string &  str,
const std::vector< std::string, ALLOC< std::string > > &  missingVals 
)
static

checks whether a string correspond to a missing value

static bool gum::learning::DBCell::isReal ( const std::string &  str)
static

determine whether a string corresponds precisely to a real number

bool gum::learning::DBCell::operator!= ( const DBCell from) const

test of inequality

DBCell& gum::learning::DBCell::operator= ( const DBCell from)

copy operator

DBCell& gum::learning::DBCell::operator= ( DBCell &&  from)

move operator

DBCell& gum::learning::DBCell::operator= ( const float  x)

assignment operator

DBCell& gum::learning::DBCell::operator= ( const int  x)

assignment operator

DBCell& gum::learning::DBCell::operator= ( const std::string &  x)

assignment operator

bool gum::learning::DBCell::operator== ( const DBCell from) const

test of equality

float gum::learning::DBCell::real ( ) const

returns the DBcell as a real number

Warning
if the cell is not of type REAL, the dbcell will not try to convert its content into a real number, it will raise a TypeError exception.
Returns
the content of the DBCell (if this is a real number)
Exceptions
TypeErrorif the DBCell is not labelled as type REAL
void gum::learning::DBCell::setInteger ( const int  x)

sets the content of the DBCell

void gum::learning::DBCell::setInteger ( const std::string &  elt)

sets the content of the DBCell from a string

Exceptions
TypeErrorif the string does not correspond to an integer
void gum::learning::DBCell::setMissingState ( )

sets the DBCell as a missing element

void gum::learning::DBCell::setReal ( const float  x)

sets the content of the DBCell

void gum::learning::DBCell::setReal ( const std::string &  elt)

sets the content of the DBCell from a string

Exceptions
TypeErrorif the string does not correspond to a real number
void gum::learning::DBCell::setString ( const std::string &  elt)

sets the content of the DBCell

const std::string& gum::learning::DBCell::string ( ) const

returns the DBcell as a string

Warning
if the cell is not of type STRING, the dbcell will not try to convert its content into a string, it will raise a TypeError exception.
Exceptions
TypeErrorif the DBCell is not labelled as type STRING
static const std::string& gum::learning::DBCell::string ( const int  index)
static

strings are stored into a static bijection. Get its ith string

Exceptions
UndefinedElementif the index does not correspond to any string
int gum::learning::DBCell::stringIndex ( ) const

returns the DBcell as the index of a string in a static bijection

All strings referenced by DBCells are stored in a bijection. This method returns the index of the string referenced by the current DBCell.

Exceptions
TypeErrorif the DBCell is not labelled as type STRING
template<template< typename > class ALLOC = std::allocator>
std::string gum::learning::DBCell::toString ( const std::vector< std::string, ALLOC< std::string > > &  missingVals) const

returns the content of the DBCell as a string, whatever its type

Exceptions
UndefinedElementis raised if the DBCell corresponds to a missing value but the set of missing values passed in argument is empty.
EltType gum::learning::DBCell::type ( ) const
noexcept

returns the current type of the DBCell


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