aGrUM  0.16.0
DBTranslatorSet.h
Go to the documentation of this file.
1 
37 #ifndef GUM_LEARNING_DB_TRANSLATOR_SET_H
38 #define GUM_LEARNING_DB_TRANSLATOR_SET_H
39 
40 #include <vector>
41 #include <limits>
42 #include <type_traits>
43 
44 #include <agrum/agrum.h>
50 
51 
52 namespace gum {
53 
54  namespace learning {
55 
114  template < template < typename > class ALLOC = std::allocator >
116  public:
119 
120  // ##########################################################################
122  // ##########################################################################
123 
125 
128 
131 
134  const allocator_type& alloc);
135 
138 
141  const allocator_type& alloc);
142 
144  virtual DBTranslatorSet< ALLOC >* clone() const;
145 
147  virtual DBTranslatorSet< ALLOC >* clone(const allocator_type& alloc) const;
148 
150  virtual ~DBTranslatorSet();
151 
153 
154  // ##########################################################################
156  // ##########################################################################
157 
159 
162 
165 
167 
170  DBTranslator< ALLOC >& operator[](const std::size_t k);
171 
173 
176  const DBTranslator< ALLOC >& operator[](const std::size_t k) const;
177 
179 
180 
181  // ##########################################################################
183  // ##########################################################################
184 
186 
188 
198  template < template < template < typename > class > class Translator >
199  std::size_t insertTranslator(const Translator< ALLOC >& translator,
200  const std::size_t column,
201  const bool unique_column = true);
202 
217  template < template < typename > class XALLOC >
218  std::size_t insertTranslator(
219  const Variable& var,
220  const std::size_t column,
221  const std::vector< std::string, XALLOC< std::string > >& missing_symbols,
222  const bool unique_column = true);
223 
236  std::size_t insertTranslator(const Variable& var,
237  const std::size_t column,
238  const bool unique_column = true);
239 
254  void eraseTranslator(const std::size_t k, const bool k_is_input_col = false);
255 
257 
260  DBTranslator< ALLOC >& translator(const std::size_t k);
261 
263 
266  const DBTranslator< ALLOC >& translator(const std::size_t k) const;
267 
269 
271  DBTranslator< ALLOC >& translatorSafe(const std::size_t k);
272 
274 
276  const DBTranslator< ALLOC >& translatorSafe(const std::size_t k) const;
277 
279 
288  template < template < typename > class OTHER_ALLOC >
290  const std::vector< std::string, OTHER_ALLOC< std::string > >& row,
291  const std::size_t k) const;
292 
304  template < template < typename > class OTHER_ALLOC >
306  const std::vector< std::string, OTHER_ALLOC< std::string > >& row,
307  const std::size_t k) const;
308 
310 
320  std::string translateBack(const DBTranslatedValue translated_val,
321  const std::size_t k) const;
322 
335  std::string translateBackSafe(const DBTranslatedValue translated_val,
336  const std::size_t k) const;
337 
348  bool isMissingValue(const DBTranslatedValue translated_val,
349  const std::size_t k) const;
350 
360  bool isMissingValueSafe(const DBTranslatedValue translated_val,
361  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 
428  HashTable< std::size_t,
429  std::size_t,
430  ALLOC< std::pair< std::size_t, std::size_t > > >
431  reorder(const std::size_t k);
432 
434 
436  HashTable< std::size_t,
437  std::size_t,
438  ALLOC< std::pair< std::size_t, std::size_t > > >
439  reorderSafe(const std::size_t k);
440 
447  std::size_t inputColumn(const std::size_t k) const;
448 
453  std::size_t inputColumnSafe(const std::size_t k) const;
454 
456  std::size_t highestInputColumn() const;
457 
459  void clear();
460 
462  std::size_t nbTranslators() const;
463 
465  std::size_t size() const;
466 
469 
471  const std::vector< DBTranslator< ALLOC >*, ALLOC< DBTranslator< ALLOC >* > >&
472  translators() const;
473 
475 
476 #ifndef DOXYGEN_SHOULD_SKIP_THIS
477 
478  private:
479  // the set of all the translators
480  std::vector< DBTranslator< ALLOC >*, ALLOC< DBTranslator< ALLOC >* > >
481  __translators;
482 
483  // a vector indicating which column of the original database each
484  // translator should translate
485  std::vector< std::size_t, ALLOC< std::size_t > > __columns;
486 
487  // the highest column index read by the translators
488  std::size_t __highest_column{std::size_t(0)};
489 
491  void __copy(const DBTranslatorSet< ALLOC >& from,
492  const allocator_type& alloc);
493 
494 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
495  };
496 
497  } /* namespace learning */
498 
499 } /* namespace gum */
500 
501 // always include templated implementation
503 
504 #endif /* GUM_LEARNING_DB_TRANSLATOR_SET_H */
HashTable< std::size_t, std::size_t, ALLOC< std::pair< 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...
const Variable & variable(const std::size_t k) const
returns the variable stored into the kth translator
Base class for every random variable.
Definition: variable.h:66
ALLOC< DBTranslatedValue > allocator_type
type for the allocators passed in arguments of methods
Definition: DBTranslator.h:120
const std::vector< DBTranslator< ALLOC > *, ALLOC< DBTranslator< ALLOC > *> > & translators() const
returns the set of translators
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 ...
DBTranslatorSet< ALLOC > & operator=(const DBTranslatorSet< ALLOC > &from)
copy operator
std::string translateBack(const DBTranslatedValue translated_val, const std::size_t k) const
returns the original string that was translated into translated_val
const Variable & variableSafe(const std::size_t k) const
returns the variable stored into the kth translator
std::size_t domainSizeSafe(const std::size_t k) const
returns the domain size of the variable stored into the kth translator
std::size_t highestInputColumn() const
returns the largest input database column index read by the translators
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
DBTranslator< ALLOC > & translatorSafe(const std::size_t k)
returns the kth translator
STL namespace.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
typename DBTranslator< ALLOC >::allocator_type allocator_type
type for the allocators passed in arguments of methods
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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
std::size_t nbTranslators() const
returns the number of translators stored into the set
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
The union class for storing the translated values in learning databases.
The class for generic Hash Tables.
Definition: hashTable.h:679
DBTranslatorSet(const allocator_type &alloc=allocator_type())
default constructor
DBTranslator< ALLOC > & operator[](const std::size_t k)
returns the kth translator
std::size_t domainSize(const std::size_t k) const
returns the domain size of the variable stored into the kth translator
DBTranslator< ALLOC > & translator(const std::size_t k)
returns the kth translator
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 ...
allocator_type getAllocator() const
returns the allocator used by the translator set
The base class for all the tabular database cell translators.
Definition: DBTranslator.h:117
std::size_t insertTranslator(const Translator< ALLOC > &translator, const std::size_t column, const bool unique_column=true)
inserts a new translator at the end of the translator set
bool needsReordering(const std::size_t k) const
indicates whether a reordering is needed to make the kth translator sorted
virtual ~DBTranslatorSet()
destructor
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 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 size() const
returns the number of translators stored into the set
DBTranslatedValue translateSafe(const std::vector< std::string, OTHER_ALLOC< std::string > > &row, const std::size_t k) const
similar to method translate, except that it checks that the kth translator exists ...
bool needsReorderingSafe(const std::size_t k) const
same as method needsReordering but checks that the kth translator exists
DBTranslatedValue translate(const std::vector< std::string, OTHER_ALLOC< std::string > > &row, const std::size_t k) const
ask the kth translator to translate a string in a row of the database
void clear()
remove all the translators
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
the class for packing together the translators used to preprocess the datasets
HashTable< std::size_t, std::size_t, ALLOC< std::pair< 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< ALLOC > * clone() const
virtual copy constructor
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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 ...