aGrUM  0.16.0
DBTranslator.h
Go to the documentation of this file.
1 
31 #ifndef GUM_LEARNING_DB_TRANSLATOR_H
32 #define GUM_LEARNING_DB_TRANSLATOR_H
33 
34 #include <string>
35 #include <limits>
36 #include <vector>
37 #include <utility>
38 
39 #include <agrum/agrum.h>
40 #include <agrum/core/bijection.h>
41 #include <agrum/core/set.h>
44 
45 
46 namespace gum {
47 
48  namespace learning {
49 
50 
116  template < template < typename > class ALLOC = std::allocator >
117  class DBTranslator : private ALLOC< DBTranslatedValue > {
118  public:
120  using allocator_type = ALLOC< DBTranslatedValue >;
121 
122  // ##########################################################################
124  // ##########################################################################
125 
127 
129 
143  template < template < typename > class XALLOC >
144  DBTranslator(
145  DBTranslatedValueType val_type,
146  const std::vector< std::string, XALLOC< std::string > >& missing_symbols,
147  const bool editable_dictionary = true,
148  std::size_t max_dico_entries = std::numeric_limits< std::size_t >::max(),
149  const allocator_type& alloc = allocator_type());
150 
152 
164  DBTranslator(
165  DBTranslatedValueType val_type,
166  const bool editable_dictionary = true,
167  std::size_t max_dico_entries = std::numeric_limits< std::size_t >::max(),
168  const allocator_type& alloc = allocator_type());
169 
171  DBTranslator(const DBTranslator< ALLOC >& from);
172 
174  DBTranslator(const DBTranslator< ALLOC >& from, const allocator_type& alloc);
175 
178 
180  DBTranslator(DBTranslator< ALLOC >&& from, const allocator_type& alloc);
181 
183  virtual DBTranslator< ALLOC >* clone() const = 0;
184 
186  virtual DBTranslator< ALLOC >* clone(const allocator_type& alloc) const = 0;
187 
189  virtual ~DBTranslator();
190 
192 
193 
194  // ##########################################################################
196  // ##########################################################################
197 
199 
201  DBTranslatedValue operator<<(const std::string& str);
202 
204  std::string operator>>(const DBTranslatedValue translated_val);
205 
207 
208 
209  // ##########################################################################
211  // ##########################################################################
212 
214 
216 
253  virtual DBTranslatedValue translate(const std::string& str) = 0;
254 
256 
267  virtual std::string
268  translateBack(const DBTranslatedValue translated_val) const = 0;
269 
271 
280  virtual std::size_t domainSize() const = 0;
281 
283  virtual bool hasEditableDictionary() const;
284 
286  virtual void setEditableDictionaryMode(bool new_mode);
287 
308  virtual bool needsReordering() const = 0;
309 
322  virtual HashTable< std::size_t,
323  std::size_t,
324  ALLOC< std::pair< std::size_t, std::size_t > > >
325  reorder() = 0;
326 
329 
331  bool isMissingSymbol(const std::string& str) const;
332 
334  virtual const Variable* variable() const = 0;
335 
337  void setVariableName(const std::string& str) const;
338 
340  void setVariableDescription(const std::string& str) const;
341 
343 
349 
352 
354  bool isMissingValue(const DBTranslatedValue& val) const;
355 
357  virtual DBTranslatedValue missingValue() const = 0;
358 
360 
361 
362  protected:
363  // ##########################################################################
365  // ##########################################################################
366 
368 
371 
374 
376 
377 
380 
382  std::size_t _max_dico_entries;
383 
386 
388 
393  mutable Bijection< std::size_t,
394  std::string,
395  ALLOC< std::pair< float, std::string > > >
397 
400  };
401 
402 
403  } /* namespace learning */
404 
405 } /* namespace gum */
406 
407 // always include the template implementation
409 
410 #endif /* GUM_LEARNING_DB_TRANSLATOR_H */
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Bijection< std::size_t, std::string, ALLOC< std::pair< float, std::string > > > _back_dico
the bijection relating back translated values and their original strings.
Definition: DBTranslator.h:396
Base class for every random variable.
Definition: variable.h:66
DBTranslatedValue operator<<(const std::string &str)
alias for method translate
ALLOC< DBTranslatedValue > allocator_type
type for the allocators passed in arguments of methods
Definition: DBTranslator.h:120
virtual DBTranslatedValue missingValue() const =0
returns the translation of a missing value
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::size_t _max_dico_entries
the maximum number of entries that the dictionary is allowed to contain
Definition: DBTranslator.h:382
virtual DBTranslatedValue translate(const std::string &str)=0
returns the translation of a string
virtual std::string translateBack(const DBTranslatedValue translated_val) const =0
returns the original value for a given translation
void setVariableName(const std::string &str) const
sets the name of the variable stored into the translator
virtual const Variable * variable() const =0
returns the variable stored into the translator
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
DBTranslator(DBTranslatedValueType val_type, const std::vector< std::string, XALLOC< std::string > > &missing_symbols, const bool editable_dictionary=true, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max(), const allocator_type &alloc=allocator_type())
default constructor
virtual DBTranslator< ALLOC > * clone() const =0
virtual copy constructor
The union class for storing the translated values in learning databases.
The class for generic Hash Tables.
Definition: hashTable.h:679
virtual ~DBTranslator()
destructor
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual bool needsReordering() const =0
indicates whether a reordering is needed to make the translations sorted
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:165
const Set< std::string, ALLOC< std::string > > & missingSymbols() const
returns the set of missing symbols taken into account by the translator
allocator_type getAllocator() const
returns the allocator used by the translator
bool isMissingValue(const DBTranslatedValue &val) const
indicates whether a translated value corresponds to a missing value
DBTranslatedValueType
The nature of the elements handled by translators (discrete, continuous).
Set< std::string, ALLOC< std::string > > _missing_symbols
the set of missing symbols
Definition: DBTranslator.h:385
The base class for all the tabular database cell translators.
Definition: DBTranslator.h:117
DBTranslator< ALLOC > & operator=(const DBTranslator< ALLOC > &from)
copy operator
virtual void setEditableDictionaryMode(bool new_mode)
sets/unset the editable dictionary mode
DBTranslatedValueType _val_type
the type of the values translated by the translator
Definition: DBTranslator.h:399
bool _is_dictionary_dynamic
indicates whether the dictionary can be updated or not
Definition: DBTranslator.h:379
virtual std::size_t domainSize() const =0
returns the domain size of a variable corresponding to the translations
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1805
std::string operator>>(const DBTranslatedValue translated_val)
alias for method translateBack
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual HashTable< std::size_t, std::size_t, ALLOC< std::pair< std::size_t, std::size_t > > > reorder()=0
performs a reordering of the dictionary and returns a mapping from the old translated values to the n...
virtual bool hasEditableDictionary() const
indicates whether the translator has an editable dictionary or not
bool isMissingSymbol(const std::string &str) const
indicates whether a string corresponds to a missing symbol
void setVariableDescription(const std::string &str) const
sets the name of the variable stored into the translator
DBTranslatedValueType getValType() const
returns the type of values handled by the translator
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.