aGrUM  0.21.0
a C++ library for (probabilistic) graphical models
DBTranslator_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /** @file
23  * @brief The base class for all the tabular databases' cell translators
24  *
25  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26  */
27 #include <agrum/tools/database/DBTranslator.h>
28 
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 
31 namespace gum {
32 
33  namespace learning {
34 
35 
36  /// returns the allocator used by the translator
37  template < template < typename > class ALLOC >
39  DBTranslator< ALLOC >::getAllocator() const {
40  return *this;
41  }
42 
43 
44  /// returns the type of values handled by the translator
45  template < template < typename > class ALLOC >
47  return val_type_;
48  }
49 
50 
51  /// returns a Boolean indicating whether the translation is lossless or not
52  template < template < typename > class ALLOC >
53  INLINE bool DBTranslator< ALLOC >::isLossless() const {
54  return is_lossless_;
55  }
56 
57 
58  /// default constructor
59  template < template < typename > class ALLOC >
60  template < template < typename > class XALLOC >
63  const bool is_lossless,
65  const bool dynamic_dictionary,
67  const typename DBTranslator< ALLOC >::allocator_type& alloc) :
71  const std::size_t size = missing_symbols.size();
72 
73  if (size) {
74  // save the set of symbols representing the missing values
76  for (const auto& symbol: missing_symbols) {
78  }
79  }
80 
82  }
83 
84 
85  /// default constructor
86  template < template < typename > class ALLOC >
89  const bool is_lossless,
90  const bool dynamic_dictionary,
92  const typename DBTranslator< ALLOC >::allocator_type& alloc) :
97  }
98 
99 
100  /// copy constructor with a given allocator
101  template < template < typename > class ALLOC >
103  const DBTranslator< ALLOC >& from,
104  const typename DBTranslator< ALLOC >::allocator_type& alloc) :
110  }
111 
112 
113  /// copy constructor
114  template < template < typename > class ALLOC >
117 
118 
119  /// move constructor with a given allocator
120  template < template < typename > class ALLOC >
122  DBTranslator< ALLOC >&& from,
123  const typename DBTranslator< ALLOC >::allocator_type& alloc) :
130  }
131 
132 
133  /// move constructor
134  template < template < typename > class ALLOC >
137 
138 
139  /// destructor
140  template < template < typename > class ALLOC >
143  }
144 
145 
146  /// copy operator
147  template < template < typename > class ALLOC >
150  if (this != &from) {
157  }
158  return *this;
159  }
160 
161 
162  /// move operator
163  template < template < typename > class ALLOC >
171 
172  return *this;
173  }
174 
175 
176  /// alias for method translate
177  template < template < typename > class ALLOC >
179  return translate(str);
180  }
181 
182 
183  /// alias for method translateBack
184  template < template < typename > class ALLOC >
187  }
188 
189 
190  /// indicates whether the translator has an editable dictionary or not
191  template < template < typename > class ALLOC >
193  return is_dictionary_dynamic_;
194  }
195 
196 
197  /// sets/unset the editable dictionary mode
198  template < template < typename > class ALLOC >
201  }
202 
203 
204  /// returns the translation from database indices to input strings
205  template < template < typename > class ALLOC >
206  INLINE const Bijection< std::size_t, std::string,
207  ALLOC< std::pair< std::size_t, std::string > > >&
208  DBTranslator< ALLOC >::getDictionary () const {
209  return back_dico_;
210  }
211 
212 
213  /// returns the set of missing symbols taken into account by the translator
214  template < template < typename > class ALLOC >
215  INLINE const Set< std::string, ALLOC< std::string > >&
216  DBTranslator< ALLOC >::missingSymbols() const {
217  return missing_symbols_;
218  }
219 
220 
221  /// indicates whether a string corresponds to a missing symbol
222  template < template < typename > class ALLOC >
223  INLINE bool DBTranslator< ALLOC >::isMissingSymbol(const std::string& str) const {
224  return missing_symbols_.exists(str);
225  }
226 
227 
228  /// sets the name of the variable stored into the translator
229  template < template < typename > class ALLOC >
230  INLINE void DBTranslator< ALLOC >::setVariableName(const std::string& str) const {
231  const_cast< Variable* >(this->variable())->setName(str);
232  }
233 
234 
235  /// sets the name of the variable stored into the translator
236  template < template < typename > class ALLOC >
237  INLINE void DBTranslator< ALLOC >::setVariableDescription(const std::string& str) const {
238  const_cast< Variable* >(this->variable())->setDescription(str);
239  }
240 
241 
242  /// indicates whether a translated value corresponds to a missing value
243  template < template < typename > class ALLOC >
245  switch (val_type_) {
247  return value.discr_val == std::numeric_limits< std::size_t >::max();
248 
250  return value.cont_val == std::numeric_limits< float >::max();
251 
252  default:
254  "No missing value interpretation for this "
255  "translated value type");
256  }
257  }
258 
259 
260  } /* namespace learning */
261 
262 } /* namespace gum */
263 
264 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)