31 #ifndef GUM_DATABASE_TABLE_H 32 #define GUM_DATABASE_TABLE_H 40 #include <agrum/agrum.h> 41 #include <agrum/tools/core/math/math_utils.h> 42 #include <agrum/tools/core/set.h> 43 #include <agrum/tools/core/thread.h> 44 #include <agrum/tools/database/DBCell.h> 45 #include <agrum/tools/database/DBRow.h> 46 #include <agrum/tools/database/DBTranslatedValue.h> 47 #include <agrum/tools/database/IDatabaseTable.h> 48 #include <agrum/tools/database/DBTranslatorSet.h> 49 #include <agrum/tools/database/DBTranslator4ContinuousVariable.h> 185 template <
template <
typename >
class ALLOC = std::allocator >
189 template <
typename TX_DATA >
190 using DBVector = std::vector< TX_DATA, ALLOC< TX_DATA > >;
201 template <
template <
typename >
class XALLOC >
202 using MissingValType = std::vector< std::string, XALLOC< std::string > >;
221 using size_type = std::size_t;
222 using difference_type = std::ptrdiff_t;
235 template <
template <
typename >
class XALLOC >
236 DatabaseTable(
const MissingValType< XALLOC >& missing_symbols,
237 const DBTranslatorSet< ALLOC >& translators
251 const allocator_type& alloc);
257 DatabaseTable(DatabaseTable< ALLOC >&& from,
const allocator_type& alloc);
306 const std::size_t input_column,
307 const bool unique_column =
true);
331 const std::size_t input_column,
332 const bool unique_column =
true);
351 template <
template <
typename >
class XALLOC >
354 const std::size_t input_column,
355 std::vector< std::string, XALLOC< std::string > > missing_symbols,
356 const bool unique_column =
true);
373 const bool k_is_input_col =
false);
440 const std::vector< std::string, ALLOC< std::string > >& names,
441 const bool from_external_object =
true)
final;
476 const bool from_external_object =
true)
final;
502 const bool k_is_input_col =
false)
const;
540 const bool k_is_input_col =
false)
const;
561 void reorder(
const std::size_t k,
const bool k_is_input_col =
false);
598 const std::vector< std::string, ALLOC< std::string > >& new_row)
final;
610 virtual void insertRow(Row< DBTranslatedValue >&& new_row,
611 const IsMissing contains_missing_data)
final;
623 virtual void insertRow(
const Row< DBTranslatedValue >& new_row,
624 const IsMissing contains_missing_data)
final;
633 virtual void insertRow(
const Row< DBCell >& new_row)
final;
642 virtual void insertRow(Row< DBCell >&& new_row)
final;
655 insertRows(Matrix< DBTranslatedValue >&& new_rows,
656 const DBVector< IsMissing >& rows_have_missing_vals)
final;
668 insertRows(
const Matrix< DBTranslatedValue >& new_rows,
669 const DBVector< IsMissing >& rows_have_missing_vals)
final;
678 virtual void insertRows(Matrix< DBCell >&& new_rows)
final;
687 virtual void insertRows(
const Matrix< DBCell >& new_rows)
final;
690 virtual void clear()
final;
705 #ifndef DOXYGEN_SHOULD_SKIP_THIS 709 DBTranslatorSet< ALLOC > translators__;
712 Set< std::size_t, ALLOC< std::size_t > > ignored_cols__;
716 bool isRowCompatible__(
const Row< DBTranslatedValue >& row)
const;
723 std::size_t getKthIndex__(
const std::size_t k,
724 const bool k_is_input_col)
const;
730 DBVector< std::size_t > getKthIndices__(
const std::size_t k,
731 const bool k_is_input_col)
const;
752 template <
typename Functor1,
typename Functor2 >
753 void threadProcessDatabase__(Functor1& exec_func, Functor2& undo_func);
763 #include <agrum/tools/database/databaseTable_tpl.h> virtual ~DatabaseTable()
destructor
virtual void insertRow(const Row< DBTranslatedValue > &new_row, const IsMissing contains_missing_data) final
insert a new row at the end of the database
virtual void insertRows(Matrix< DBCell > &&new_rows) final
insert a set of new DBRows at the end of the database
DatabaseTable(const DatabaseTable< ALLOC > &from)
copy constructor
virtual void ignoreColumn(const std::size_t k, const bool from_external_object=true) final
makes the database table ignore from now on the kth column of the input dataset or the column parsed ...
DBVector< std::size_t > domainSizes() const
returns the domain sizes of all the variables in the database table
const DBTranslatorSet< ALLOC > & translatorSet() const
returns the set of translators
INLINE void emplace(Args &&... args)
virtual void insertRows(const Matrix< DBTranslatedValue > &new_rows, const DBVector< IsMissing > &rows_have_missing_vals) final
insert a set of new DBRows at the end of the database
virtual void insertRow(const std::vector< std::string, ALLOC< std::string > > &new_row) final
insert a new row at the end of the database
DatabaseTable(DatabaseTable< ALLOC > &&from)
move constructor
DatabaseTable(const DatabaseTable< ALLOC > &from, const allocator_type &alloc)
copy constructor with a given allocator
bool needsReordering(const std::size_t k, const bool k_is_input_col=false) const
indicates whether a reordering is needed to sort the translations of the kth translator or those of t...
std::size_t insertTranslator(const Variable &var, const std::size_t input_column, const bool unique_column=true)
insert a new translator into the database table
virtual DatabaseTable< ALLOC > * clone() const final
virtual copy constructor
virtual void insertRow(const Row< DBCell > &new_row) final
insert a new DBRow of DBCells at the end of the database
virtual const DBVector< std::size_t > inputColumns() const final
returns the set of columns of the original dataset that are present in the DatabaseTable ...
const DBTranslator< ALLOC > & translator(const std::size_t k, const bool k_is_input_col=false) const
returns either the kth translator of the database table or the first one reading the kth column of th...
virtual void insertRow(Row< DBTranslatedValue > &&new_row, const IsMissing contains_missing_data) final
insert a new DBRow at the end of the database
std::size_t domainSize(const std::size_t k, const bool k_is_input_col=false) const
returns the domain size of the kth variable of the database table or of that of the first one corresp...
virtual const DBVector< std::size_t > ignoredColumns() const final
returns the set of columns of the original dataset that are ignored
DatabaseTable< ALLOC > & operator=(const DatabaseTable< ALLOC > &from)
copy operator
DatabaseTable(DatabaseTable< ALLOC > &&from, const allocator_type &alloc)
move constructor with a given allocator
virtual void insertRow(Row< DBCell > &&new_row) final
insert a new DBRow of DBCells at the end of the database
const Variable & variable(const std::size_t k, const bool k_is_input_col=false) const
returns either the kth variable of the database table or the first one corresponding to the kth colum...
virtual void insertRows(Matrix< DBTranslatedValue > &&new_rows, const DBVector< IsMissing > &rows_have_missing_vals) final
insert a set of new DBRows at the end of the database
std::size_t insertTranslator(const Variable &var, const std::size_t input_column, std::vector< std::string, XALLOC< std::string > > missing_symbols, const bool unique_column=true)
insert a new translator into the database table
The class representing a tabular database as used by learning tasks.
virtual void clear() final
erase the content of the database, including the names of the variables
virtual void setVariableNames(const std::vector< std::string, ALLOC< std::string > > &names, const bool from_external_object=true) final
sets the names of the variables
DatabaseTable< ALLOC > & operator=(DatabaseTable< ALLOC > &&from)
move constructor
virtual void insertRows(const Matrix< DBCell > &new_rows) final
insert a set of new DBRows at the end of the database
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
DatabaseTable(const MissingValType< XALLOC > &missing_symbols, const DBTranslatorSet< ALLOC > &translators=DBTranslatorSet< ALLOC >(), const allocator_type &alloc=allocator_type())
default constructor
void reorder(const std::size_t k, const bool k_is_input_col=false)
performs a reordering of the kth translator or of the first translator parsing the kth column of the ...
void eraseTranslators(const std::size_t k, const bool k_is_input_col=false)
erases either the kth translator or all those parsing the kth column of the input dataset ...
virtual DatabaseTable< ALLOC > * clone(const allocator_type &alloc) const final
virtual copy constructor with a given allocator
void reorder()
performs a reordering of all the columns