![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
The class representing the original values of the cells of databases. More...
#include <agrum/tools/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 | |
DBCell & | operator= (const DBCell &from) |
copy operator More... | |
DBCell & | operator= (DBCell &&from) |
move operator More... | |
DBCell & | operator= (const float x) |
assignment operator More... | |
DBCell & | operator= (const int x) |
assignment operator More... | |
DBCell & | operator= (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... | |
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.
|
strong |
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
|
static |
returns the DBCell with the best type for an element encoded as a string
|
static |
returns the best type to store a given element encoded as a string
str | the string to convert into a DBCell |
missingVals | a 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. |
try to convert the content of the DBCell into another type
int gum::learning::DBCell::integer | ( | ) | const |
|
static |
determines whether a string corresponds precisely to an integer
bool gum::learning::DBCell::isMissing | ( | ) | const |
indicates whether the cell contains a missing value
|
static |
checks whether a string correspond to a missing value
|
static |
determine whether a string corresponds precisely to a real number
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
float gum::learning::DBCell::real | ( | ) | const |
void gum::learning::DBCell::setInteger | ( | const int | x | ) |
sets the content of the DBCell
void gum::learning::DBCell::setInteger | ( | const std::string & | elt | ) |
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 | ) |
void gum::learning::DBCell::setString | ( | const std::string & | elt | ) |
sets the content of the DBCell
const std::string& gum::learning::DBCell::string | ( | ) | const |
|
static |
strings are stored into a static bijection. Get its ith string
UndefinedElement | if the index does not correspond to any string |
int gum::learning::DBCell::stringIndex | ( | ) | const |
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
UndefinedElement | is raised if the DBCell corresponds to a missing value but the set of missing values passed in argument is empty. |