aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
DBTranslator_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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  /// default constructor
52  template < template < typename > class ALLOC >
53  template < template < typename > class XALLOC >
57  const bool dynamic_dictionary,
59  const typename DBTranslator< ALLOC >::allocator_type& alloc) :
63  const std::size_t size = missing_symbols.size();
64 
65  if (size) {
66  // save the set of symbols representing the missing values
68  for (const auto& symbol: missing_symbols) {
70  }
71  }
72 
74  }
75 
76 
77  /// default constructor
78  template < template < typename > class ALLOC >
81  const bool dynamic_dictionary,
83  const typename DBTranslator< ALLOC >::allocator_type& alloc) :
88  }
89 
90 
91  /// copy constructor with a given allocator
92  template < template < typename > class ALLOC >
94  const DBTranslator< ALLOC >& from,
95  const typename DBTranslator< ALLOC >::allocator_type& alloc) :
102  }
103 
104 
105  /// copy constructor
106  template < template < typename > class ALLOC >
109 
110 
111  /// move constructor with a given allocator
112  template < template < typename > class ALLOC >
114  DBTranslator< ALLOC >&& from,
115  const typename DBTranslator< ALLOC >::allocator_type& alloc) :
122  }
123 
124 
125  /// move constructor
126  template < template < typename > class ALLOC >
129 
130 
131  /// destructor
132  template < template < typename > class ALLOC >
135  }
136 
137 
138  /// copy operator
139  template < template < typename > class ALLOC >
142  if (this != &from) {
148  }
149  return *this;
150  }
151 
152 
153  /// move operator
154  template < template < typename > class ALLOC >
162 
163  return *this;
164  }
165 
166 
167  /// alias for method translate
168  template < template < typename > class ALLOC >
170  DBTranslator< ALLOC >::operator<<(const std::string& str) {
171  return translate(str);
172  }
173 
174 
175  /// alias for method translateBack
176  template < template < typename > class ALLOC >
177  INLINE std::string
180  }
181 
182 
183  /// indicates whether the translator has an editable dictionary or not
184  template < template < typename > class ALLOC >
186  return is_dictionary_dynamic_;
187  }
188 
189 
190  /// sets/unset the editable dictionary mode
191  template < template < typename > class ALLOC >
194  }
195 
196 
197  /// returns the set of missing symbols taken into account by the translator
198  template < template < typename > class ALLOC >
199  INLINE const Set< std::string, ALLOC< std::string > >&
200  DBTranslator< ALLOC >::missingSymbols() const {
201  return missing_symbols_;
202  }
203 
204 
205  /// indicates whether a string corresponds to a missing symbol
206  template < template < typename > class ALLOC >
207  INLINE bool
208  DBTranslator< ALLOC >::isMissingSymbol(const std::string& str) const {
209  return missing_symbols_.exists(str);
210  }
211 
212 
213  /// sets the name of the variable stored into the translator
214  template < template < typename > class ALLOC >
215  INLINE void
216  DBTranslator< ALLOC >::setVariableName(const std::string& str) const {
217  const_cast< Variable* >(this->variable())->setName(str);
218  }
219 
220 
221  /// sets the name of the variable stored into the translator
222  template < template < typename > class ALLOC >
224  const std::string& str) const {
225  const_cast< Variable* >(this->variable())->setDescription(str);
226  }
227 
228 
229  /// indicates whether a translated value corresponds to a missing value
230  template < template < typename > class ALLOC >
232  const DBTranslatedValue& value) const {
233  switch (val_type_) {
235  return value.discr_val == std::numeric_limits< std::size_t >::max();
236 
238  return value.cont_val == std::numeric_limits< float >::max();
239 
240  default:
242  "No missing value interpretation for this "
243  "translated value type");
244  }
245  }
246 
247 
248  } /* namespace learning */
249 
250 } /* namespace gum */
251 
252 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)