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 > >;
200 template <
template <
typename >
class XALLOC >
201 using MissingValType = std::vector< std::string, XALLOC< std::string > >;
218 using size_type = std::size_t;
219 using difference_type = std::ptrdiff_t;
232 template <
template <
typename >
class XALLOC >
233 DatabaseTable(
const MissingValType< XALLOC >& missing_symbols,
245 DatabaseTable(
const DatabaseTable< ALLOC >& from,
const allocator_type& alloc);
251 DatabaseTable(DatabaseTable< ALLOC >&& from,
const allocator_type& alloc);
299 const std::size_t input_column,
300 const bool unique_column =
true);
324 const std::size_t input_column,
325 const bool unique_column =
true);
344 template <
template <
typename >
class XALLOC >
347 const std::size_t input_column,
348 std::vector< std::string, XALLOC< std::string > > missing_symbols,
349 const bool unique_column =
true);
365 void eraseTranslators(
const std::size_t k,
const bool k_is_input_col =
false);
430 virtual void setVariableNames(
const std::vector< std::string, ALLOC< std::string > >& names,
431 const bool from_external_object =
true)
final;
465 virtual void ignoreColumn(
const std::size_t k,
const bool from_external_object =
true)
final;
490 std::size_t
domainSize(
const std::size_t k,
const bool k_is_input_col =
false)
const;
527 bool needsReordering(
const std::size_t k,
const bool k_is_input_col =
false)
const;
548 void reorder(
const std::size_t k,
const bool k_is_input_col =
false);
584 virtual void insertRow(
const std::vector< std::string, ALLOC< std::string > >& new_row)
final;
596 virtual void insertRow(Row< DBTranslatedValue >&& new_row,
597 const IsMissing contains_missing_data)
final;
609 virtual void insertRow(
const Row< DBTranslatedValue >& new_row,
610 const IsMissing contains_missing_data)
final;
619 virtual void insertRow(
const Row< DBCell >& new_row)
final;
628 virtual void insertRow(Row< DBCell >&& new_row)
final;
640 virtual void insertRows(Matrix< DBTranslatedValue >&& new_rows,
641 const DBVector< IsMissing >& rows_have_missing_vals)
final;
652 virtual void insertRows(
const Matrix< DBTranslatedValue >& new_rows,
653 const DBVector< IsMissing >& rows_have_missing_vals)
final;
662 virtual void insertRows(Matrix< DBCell >&& new_rows)
final;
671 virtual void insertRows(
const Matrix< DBCell >& new_rows)
final;
674 virtual void clear()
final;
689 #ifndef DOXYGEN_SHOULD_SKIP_THIS 693 DBTranslatorSet< ALLOC > _translators_;
696 Set< std::size_t, ALLOC< std::size_t > > _ignored_cols_;
700 bool _isRowCompatible_(
const Row< DBTranslatedValue >& row)
const;
707 std::size_t _getKthIndex_(
const std::size_t k,
const bool k_is_input_col)
const;
713 DBVector< std::size_t > _getKthIndices_(
const std::size_t k,
const bool k_is_input_col)
const;
734 template <
typename Functor1,
typename Functor2 >
735 void _threadProcessDatabase_(Functor1& exec_func, Functor2& undo_func);
745 #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