aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
DBTranslatorSet.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
56#ifndef GUM_LEARNING_DB_TRANSLATOR_SET_H
57#define GUM_LEARNING_DB_TRANSLATOR_SET_H
58
59#include <limits>
60#include <vector>
61
62#include <agrum/agrum.h>
63
65
66#include <type_traits>
67
68namespace gum {
69
70 namespace learning {
71
130 class DBTranslatorSet final {
131 public:
132 // ##########################################################################
134 // ##########################################################################
135
137
140
143
146
148 virtual DBTranslatorSet* clone() const;
149
152
154
155 // ##########################################################################
157 // ##########################################################################
158
160
163
166
168
171 DBTranslator& operator[](const std::size_t k);
172
174
177 const DBTranslator& operator[](const std::size_t k) const;
178
180
181
182 // ##########################################################################
184 // ##########################################################################
185
187
189
200 const std::size_t column,
201 const bool unique_column = true);
202
217 std::size_t insertTranslator(const Variable& var,
218 const std::size_t column,
219 const std::vector< std::string >& missing_symbols,
220 const bool unique_column = true);
221
234 std::size_t insertTranslator(const Variable& var,
235 const std::size_t column,
236 const bool unique_column = true);
237
239
245 template < class Translator >
246 void changeTranslator(const Translator& new_translator, const std::size_t pos);
247
262 void eraseTranslator(const std::size_t k, const bool k_is_input_col = false);
263
265
268 DBTranslator& translator(const std::size_t k);
269
271
274 const DBTranslator& translator(const std::size_t k) const;
275
277
279 DBTranslator& translatorSafe(const std::size_t k);
280
282
284 const DBTranslator& translatorSafe(const std::size_t k) const;
285
287
296 DBTranslatedValue translate(const std::vector< std::string >& row, const std::size_t k) const;
297
309 DBTranslatedValue translateSafe(const std::vector< std::string >& row,
310 const std::size_t k) const;
311
313
323 std::string translateBack(const DBTranslatedValue translated_val, const std::size_t k) const;
324
337 std::string translateBackSafe(const DBTranslatedValue translated_val,
338 const std::size_t k) const;
339
350 bool isMissingValue(const DBTranslatedValue translated_val, const std::size_t k) const;
351
361 bool isMissingValueSafe(const DBTranslatedValue translated_val, const std::size_t k) const;
362
364
367 std::size_t domainSize(const std::size_t k) const;
368
370
372 std::size_t domainSizeSafe(const std::size_t k) const;
373
375
378 const Variable& variable(const std::size_t k) const;
379
381
383 const Variable& variableSafe(const std::size_t k) const;
384
408 bool needsReordering(const std::size_t k) const;
409
411
413 bool needsReorderingSafe(const std::size_t k) const;
414
429
431
434
441 std::size_t inputColumn(const std::size_t k) const;
442
447 std::size_t inputColumnSafe(const std::size_t k) const;
448
450 std::size_t highestInputColumn() const;
451
453 void clear();
454
456 std::size_t nbTranslators() const;
457
459 std::size_t size() const;
460
462 const std::vector< DBTranslator* >& translators() const;
463
465
466#ifndef DOXYGEN_SHOULD_SKIP_THIS
467
468 private:
469 // the set of all the translators
470 std::vector< DBTranslator* > _translators_;
471
472 // a vector indicating which column of the original database each
473 // translator should translate
474 std::vector< std::size_t > _columns_;
475
476 // the highest column index read by the translators
477 std::size_t _highest_column_{std::size_t(0)};
478
480 void _copy_(const DBTranslatorSet& from);
481
482#endif /* DOXYGEN_SHOULD_SKIP_THIS */
483 };
484
485 } /* namespace learning */
486
487} /* namespace gum */
488
489// always include templated implementation
491
492// include the inlined functions if necessary
493#ifndef GUM_NO_INLINE
495#endif /* GUM_NO_INLINE */
496
497#endif /* GUM_LEARNING_DB_TRANSLATOR_SET_H */
The set of translators stored into a row filter.
Utilities for DBTranslators.
The class for generic Hash Tables.
Definition hashTable.h:637
Base class for every random variable.
Definition variable.h:79
the class for packing together the translators used to preprocess the datasets
const DBTranslator & operator[](const std::size_t k) const
returns the kth translator
DBTranslatedValue translateSafe(const std::vector< std::string > &row, const std::size_t k) const
similar to method translate, except that it checks that the kth translator exists
std::size_t inputColumn(const std::size_t k) const
returns the column of the input database that will be read by the kth translator
std::string translateBack(const DBTranslatedValue translated_val, const std::size_t k) const
returns the original string that was translated into translated_val
void changeTranslator(const Translator &new_translator, const std::size_t pos)
substitute a translator by another one
bool needsReordering(const std::size_t k) const
indicates whether a reordering is needed to make the kth translator sorted
const DBTranslator & translatorSafe(const std::size_t k) const
returns the kth translator
void eraseTranslator(const std::size_t k, const bool k_is_input_col=false)
erases either the kth translator or those parsing the kth column of the input database
const DBTranslator & translator(const std::size_t k) const
returns the kth translator
DBTranslatorSet & operator=(const DBTranslatorSet &from)
copy operator
std::size_t domainSizeSafe(const std::size_t k) const
returns the domain size of the variable stored into the kth translator
DBTranslator & operator[](const std::size_t k)
returns the kth translator
DBTranslatorSet & operator=(DBTranslatorSet &&from)
move operator
bool needsReorderingSafe(const std::size_t k) const
same as method needsReordering but checks that the kth translator exists
std::size_t size() const
returns the number of translators stored into the set
std::size_t insertTranslator(const Variable &var, const std::size_t column, const std::vector< std::string > &missing_symbols, const bool unique_column=true)
inserts a new translator for a given variable at the end of the translator set
DBTranslator & translator(const std::size_t k)
returns the kth translator
std::size_t insertTranslator(const Variable &var, const std::size_t column, const bool unique_column=true)
inserts a new translator for a given variable at the end of the translator set
const Variable & variable(const std::size_t k) const
returns the variable stored into the kth translator
std::size_t highestInputColumn() const
returns the largest input database column index read by the translators
bool isMissingValue(const DBTranslatedValue translated_val, const std::size_t k) const
indicates whether the kth translator considers a translated_val as a missing value
DBTranslatorSet()
default constructor
const std::vector< DBTranslator * > & translators() const
returns the set of translators
const Variable & variableSafe(const std::size_t k) const
returns the variable stored into the kth translator
void clear()
remove all the translators
HashTable< std::size_t, std::size_t > reorderSafe(const std::size_t k)
same as method reorder but checks that the kth translator exists
virtual ~DBTranslatorSet()
destructor
HashTable< std::size_t, std::size_t > reorder(const std::size_t k)
performs a reordering of the dictionary and returns a mapping from the old translated values to the n...
DBTranslator & translatorSafe(const std::size_t k)
returns the kth translator
DBTranslatorSet(DBTranslatorSet &&from)
move constructor
std::size_t nbTranslators() const
returns the number of translators stored into the set
DBTranslatedValue translate(const std::vector< std::string > &row, const std::size_t k) const
ask the kth translator to translate a string in a row of the database
std::size_t inputColumnSafe(const std::size_t k) const
returns the column of the input database that will be read by the kth translator
DBTranslatorSet(const DBTranslatorSet &from)
copy constructor
std::size_t domainSize(const std::size_t k) const
returns the domain size of the variable stored into the kth translator
std::string translateBackSafe(const DBTranslatedValue translated_val, const std::size_t k) const
similar to method translateBack, except that it checks that the kth translator exists
std::size_t insertTranslator(const DBTranslator &translator, const std::size_t column, const bool unique_column=true)
inserts a new translator at the end of the translator set
virtual DBTranslatorSet * clone() const
virtual copy constructor
bool isMissingValueSafe(const DBTranslatedValue translated_val, const std::size_t k) const
similar to method isMissingValue, except that it checks that the kth translator exists
The base class for all the tabular database cell translators.
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
The union class for storing the translated values in learning databases.