aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::learning::DBCell Class Reference

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
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 71 of file DBCell.h.

Member Enumeration Documentation

◆ EltType

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 74 of file DBCell.h.

74  : unsigned char
75  {
76  REAL,
77  INTEGER,
78  STRING,
79  MISSING
80  };

Constructor & Destructor Documentation

◆ DBCell() [1/6]

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

default constructor (ontains a missing value)

◆ DBCell() [2/6]

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

constructor for a real number

◆ DBCell() [3/6]

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

constructor for an integer number

◆ DBCell() [4/6]

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

constructor for a string

◆ DBCell() [5/6]

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

copy constructor

◆ DBCell() [6/6]

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

move constructor

◆ ~DBCell()

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

destructor

Member Function Documentation

◆ bestDBCell()

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.

◆ bestType()

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.

◆ convertType()

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.

◆ integer()

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

◆ isInteger()

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

determines whether a string corresponds precisely to an integer

◆ isMissing() [1/2]

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

indicates whether the cell contains a missing value

◆ isMissing() [2/2]

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

◆ isReal()

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

determine whether a string corresponds precisely to a real number

◆ operator!=()

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

test of inequality

◆ operator=() [1/5]

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

copy operator

◆ operator=() [2/5]

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

move operator

◆ operator=() [3/5]

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

assignment operator

◆ operator=() [4/5]

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

assignment operator

◆ operator=() [5/5]

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

assignment operator

◆ operator==()

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

test of equality

◆ real()

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

◆ setInteger() [1/2]

void gum::learning::DBCell::setInteger ( const int  x)

sets the content of the DBCell

◆ setInteger() [2/2]

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

◆ setMissingState()

void gum::learning::DBCell::setMissingState ( )

sets the DBCell as a missing element

◆ setReal() [1/2]

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

sets the content of the DBCell

◆ setReal() [2/2]

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

◆ setString()

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

sets the content of the DBCell

◆ string() [1/2]

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

◆ string() [2/2]

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

◆ stringIndex()

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

◆ toString()

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.

◆ type()

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: