aGrUM  0.14.2
DBTranslatorSet.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
34 #ifndef GUM_LEARNING_DB_TRANSLATOR_SET_H
35 #define GUM_LEARNING_DB_TRANSLATOR_SET_H
36 
37 #include <vector>
38 #include <limits>
39 #include <type_traits>
40 
41 #include <agrum/agrum.h>
47 
48 
49 namespace gum {
50 
51  namespace learning {
52 
111  template < template < typename > class ALLOC = std::allocator >
113  public:
116 
117  // ##########################################################################
119  // ##########################################################################
120 
122 
125 
128 
131  const allocator_type& alloc);
132 
135 
138  const allocator_type& alloc);
139 
141  virtual DBTranslatorSet< ALLOC >* clone() const;
142 
144  virtual DBTranslatorSet< ALLOC >* clone(const allocator_type& alloc) const;
145 
147  virtual ~DBTranslatorSet();
148 
150 
151  // ##########################################################################
153  // ##########################################################################
154 
156 
159 
162 
164 
167  DBTranslator< ALLOC >& operator[](const std::size_t k);
168 
170 
173  const DBTranslator< ALLOC >& operator[](const std::size_t k) const;
174 
176 
177 
178  // ##########################################################################
180  // ##########################################################################
181 
183 
185 
195  template < template < template < typename > class > class Translator >
196  std::size_t insertTranslator(const Translator< ALLOC >& translator,
197  const std::size_t column,
198  const bool unique_column = true);
199 
214  template < template < typename > class XALLOC >
215  std::size_t insertTranslator(
216  const Variable& var,
217  const std::size_t column,
218  const std::vector< std::string, XALLOC< std::string > >& missing_symbols,
219  const bool unique_column = true);
220 
233  std::size_t insertTranslator(const Variable& var,
234  const std::size_t column,
235  const bool unique_column = true);
236 
251  void eraseTranslator(const std::size_t k, const bool k_is_input_col = false);
252 
254 
257  DBTranslator< ALLOC >& translator(const std::size_t k);
258 
260 
263  const DBTranslator< ALLOC >& translator(const std::size_t k) const;
264 
266 
268  DBTranslator< ALLOC >& translatorSafe(const std::size_t k);
269 
271 
273  const DBTranslator< ALLOC >& translatorSafe(const std::size_t k) const;
274 
276 
285  template < template < typename > class OTHER_ALLOC >
287  const std::vector< std::string, OTHER_ALLOC< std::string > >& row,
288  const std::size_t k) const;
289 
301  template < template < typename > class OTHER_ALLOC >
303  const std::vector< std::string, OTHER_ALLOC< std::string > >& row,
304  const std::size_t k) const;
305 
307 
317  std::string translateBack(const DBTranslatedValue translated_val,
318  const std::size_t k) const;
319 
332  std::string translateBackSafe(const DBTranslatedValue translated_val,
333  const std::size_t k) const;
334 
345  bool isMissingValue(const DBTranslatedValue translated_val,
346  const std::size_t k) const;
347 
357  bool isMissingValueSafe(const DBTranslatedValue translated_val,
358  const std::size_t k) const;
359 
361 
364  std::size_t domainSize(const std::size_t k) const;
365 
367 
369  std::size_t domainSizeSafe(const std::size_t k) const;
370 
372 
375  const Variable& variable(const std::size_t k) const;
376 
378 
380  const Variable& variableSafe(const std::size_t k) const;
381 
405  bool needsReordering(const std::size_t k) const;
406 
408 
410  bool needsReorderingSafe(const std::size_t k) const;
411 
425  HashTable< std::size_t,
426  std::size_t,
427  ALLOC< std::pair< std::size_t, std::size_t > > >
428  reorder(const std::size_t k);
429 
431 
433  HashTable< std::size_t,
434  std::size_t,
435  ALLOC< std::pair< std::size_t, std::size_t > > >
436  reorderSafe(const std::size_t k);
437 
444  std::size_t inputColumn(const std::size_t k) const;
445 
450  std::size_t inputColumnSafe(const std::size_t k) const;
451 
453  std::size_t highestInputColumn() const;
454 
456  void clear();
457 
459  std::size_t nbTranslators() const;
460 
462  std::size_t size() const;
463 
466 
468  const std::vector< DBTranslator< ALLOC >*, ALLOC< DBTranslator< ALLOC >* > >&
469  translators() const;
470 
472 
473 #ifndef DOXYGEN_SHOULD_SKIP_THIS
474 
475  private:
476  // the set of all the translators
477  std::vector< DBTranslator< ALLOC >*, ALLOC< DBTranslator< ALLOC >* > >
478  __translators;
479 
480  // a vector indicating which column of the original database each
481  // translator should translate
482  std::vector< std::size_t, ALLOC< std::size_t > > __columns;
483 
484  // the highest column index read by the translators
485  std::size_t __highest_column{std::size_t(0)};
486 
488  void __copy(const DBTranslatorSet< ALLOC >& from,
489  const allocator_type& alloc);
490 
491 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
492  };
493 
494  } /* namespace learning */
495 
496 } /* namespace gum */
497 
498 // always include templated implementation
500 
501 #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:63
ALLOC< DBTranslatedValue > allocator_type
type for the allocators passed in arguments of methods
Definition: DBTranslator.h:117
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
The databases&#39; cell translators for range variables.
DBTranslator< ALLOC > & translatorSafe(const std::size_t k)
returns the kth translator
STL namespace.
The databases&#39; cell translators for continuous variables.
typename DBTranslator< ALLOC >::allocator_type allocator_type
type for the allocators passed in arguments of methods
The databases&#39; cell translators for discretized variables.
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
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The union class for storing the translated values in learning databases.
The class for generic Hash Tables.
Definition: hashTable.h:676
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:114
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
The base class for all the tabular databases&#39; cell translators.
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
The databases&#39; cell translators for labelized variables.
The set of translators stored into a row filter.
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 ...