aGrUM 3.1.1
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/base/database/DBCell.h>

Public Types

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

Public Member Functions

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

Public Static Accessors / Modifiers

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

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

Member Enumeration Documentation

◆ EltType

enum class 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 97 of file DBCell.h.

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

Constructor & Destructor Documentation

◆ DBCell() [1/6]

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

default constructor (ontains a missing value)

Referenced by DBCell(), DBCell(), bestDBCell(), operator=(), operator=(), operator=(), operator=(), operator=(), and operator==().

Here is the caller graph for this function:

◆ 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

References DBCell().

Here is the call graph for this function:

◆ DBCell() [6/6]

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

move constructor

References DBCell().

Here is the call graph for this function:

◆ ~DBCell()

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

destructor

Member Function Documentation

◆ bestDBCell()

DBCell gum::learning::DBCell::bestDBCell ( std::string_view str,
const std::vector< 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.

References DBCell(), and bestDBCell().

Referenced by bestDBCell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bestType()

EltType gum::learning::DBCell::bestType ( std::string_view str,
const std::vector< 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.

References bestType().

Referenced by bestType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

References convertType().

Referenced by convertType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

References integer().

Referenced by integer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isInteger()

bool gum::learning::DBCell::isInteger ( std::string_view str)
static

determines whether a string corresponds precisely to an integer

References isInteger().

Referenced by isInteger().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isMissing() [1/2]

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

indicates whether the cell contains a missing value

References isMissing().

Referenced by isMissing(), and isMissing().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isMissing() [2/2]

bool gum::learning::DBCell::isMissing ( std::string_view str,
const std::vector< std::string > & missingVals )
static

checks whether a string correspond to a missing value

References isMissing(), and MISSING.

Here is the call graph for this function:

◆ isReal()

bool gum::learning::DBCell::isReal ( std::string_view str)
static

determine whether a string corresponds precisely to a real number

References isReal().

Referenced by isReal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/5]

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

copy operator

References DBCell().

Here is the call graph for this function:

◆ operator=() [2/5]

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

assignment operator

References DBCell().

Here is the call graph for this function:

◆ operator=() [3/5]

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

assignment operator

References DBCell().

Here is the call graph for this function:

◆ operator=() [4/5]

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

assignment operator

References DBCell().

Here is the call graph for this function:

◆ operator=() [5/5]

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

move operator

References DBCell().

Here is the call graph for this function:

◆ operator==()

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

test of equality

References DBCell().

Here is the call graph for this function:

◆ 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

References real().

Referenced by real().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setInteger() [1/2]

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

sets the content of the DBCell

References setInteger().

Referenced by setInteger(), and setInteger().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setInteger() [2/2]

void gum::learning::DBCell::setInteger ( std::string_view elt)

sets the content of the DBCell from a string

Exceptions
TypeErrorif the string does not correspond to an integer

References setInteger().

Here is the call graph for this function:

◆ setMissingState()

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

sets the DBCell as a missing element

References setMissingState().

Referenced by setMissingState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setReal() [1/2]

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

sets the content of the DBCell

References setReal().

Referenced by setReal(), and setReal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setReal() [2/2]

void gum::learning::DBCell::setReal ( std::string_view elt)

sets the content of the DBCell from a string

Exceptions
TypeErrorif the string does not correspond to a real number

References setReal().

Here is the call graph for this function:

◆ setString()

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

sets the content of the DBCell

References setString().

Referenced by setString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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]

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

References stringIndex().

Referenced by stringIndex().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

std::string gum::learning::DBCell::toString ( const std::vector< 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.

References toString().

Referenced by toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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: