aGrUM  0.14.2
DBTranslator.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  ***************************************************************************/
28 #ifndef GUM_LEARNING_DB_TRANSLATOR_H
29 #define GUM_LEARNING_DB_TRANSLATOR_H
30 
31 #include <string>
32 #include <limits>
33 #include <vector>
34 #include <utility>
35 
36 #include <agrum/agrum.h>
37 #include <agrum/core/bijection.h>
38 #include <agrum/core/set.h>
41 
42 
43 namespace gum {
44 
45  namespace learning {
46 
47 
113  template < template < typename > class ALLOC = std::allocator >
114  class DBTranslator : private ALLOC< DBTranslatedValue > {
115  public:
117  using allocator_type = ALLOC< DBTranslatedValue >;
118 
119  // ##########################################################################
121  // ##########################################################################
122 
124 
126 
140  template < template < typename > class XALLOC >
141  DBTranslator(
142  DBTranslatedValueType val_type,
143  const std::vector< std::string, XALLOC< std::string > >& missing_symbols,
144  const bool editable_dictionary = true,
145  std::size_t max_dico_entries = std::numeric_limits< std::size_t >::max(),
146  const allocator_type& alloc = allocator_type());
147 
149 
161  DBTranslator(
162  DBTranslatedValueType val_type,
163  const bool editable_dictionary = true,
164  std::size_t max_dico_entries = std::numeric_limits< std::size_t >::max(),
165  const allocator_type& alloc = allocator_type());
166 
168  DBTranslator(const DBTranslator< ALLOC >& from);
169 
171  DBTranslator(const DBTranslator< ALLOC >& from, const allocator_type& alloc);
172 
175 
177  DBTranslator(DBTranslator< ALLOC >&& from, const allocator_type& alloc);
178 
180  virtual DBTranslator< ALLOC >* clone() const = 0;
181 
183  virtual DBTranslator< ALLOC >* clone(const allocator_type& alloc) const = 0;
184 
186  virtual ~DBTranslator();
187 
189 
190 
191  // ##########################################################################
193  // ##########################################################################
194 
196 
198  DBTranslatedValue operator<<(const std::string& str);
199 
201  std::string operator>>(const DBTranslatedValue translated_val);
202 
204 
205 
206  // ##########################################################################
208  // ##########################################################################
209 
211 
213 
250  virtual DBTranslatedValue translate(const std::string& str) = 0;
251 
253 
264  virtual std::string
265  translateBack(const DBTranslatedValue translated_val) const = 0;
266 
268 
277  virtual std::size_t domainSize() const = 0;
278 
280  virtual bool hasEditableDictionary() const;
281 
283  virtual void setEditableDictionaryMode(bool new_mode);
284 
305  virtual bool needsReordering() const = 0;
306 
319  virtual HashTable< std::size_t,
320  std::size_t,
321  ALLOC< std::pair< std::size_t, std::size_t > > >
322  reorder() = 0;
323 
326 
328  bool isMissingSymbol(const std::string& str) const;
329 
331  virtual const Variable* variable() const = 0;
332 
334  void setVariableName(const std::string& str) const;
335 
337  void setVariableDescription(const std::string& str) const;
338 
340 
346 
349 
351  bool isMissingValue(const DBTranslatedValue& val) const;
352 
354  virtual DBTranslatedValue missingValue() const = 0;
355 
357 
358 
359  protected:
360  // ##########################################################################
362  // ##########################################################################
363 
365 
368 
371 
373 
374 
377 
379  std::size_t _max_dico_entries;
380 
383 
385 
390  mutable Bijection< std::size_t,
391  std::string,
392  ALLOC< std::pair< float, std::string > > >
394 
397  };
398 
399 
400  } /* namespace learning */
401 
402 } /* namespace gum */
403 
404 // always include the template implementation
406 
407 #endif /* GUM_LEARNING_DB_TRANSLATOR_H */
The union class for storing the translated values in learning databases.
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:393
Base class for every random variable.
Definition: variable.h:63
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:117
virtual DBTranslatedValue missingValue() const =0
returns the translation of a missing value
Sets of elements (i.e.
std::size_t _max_dico_entries
the maximum number of entries that the dictionary is allowed to contain
Definition: DBTranslator.h:379
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
gum is the global namespace for all aGrUM entities
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:676
virtual ~DBTranslator()
destructor
The base class for all the tabular databases&#39; cell translators.
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:162
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:382
The base class for all the tabular database cell translators.
Definition: DBTranslator.h:114
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:396
bool _is_dictionary_dynamic
indicates whether the dictionary can be updated or not
Definition: DBTranslator.h:376
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:1803
std::string operator>>(const DBTranslatedValue translated_val)
alias for method translateBack
Base class for random variable.
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
Set of pairs of elements with fast search for both elements.