aGrUM  0.20.3
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  /// 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) :
101  }
102 
103 
104  /// copy constructor
105  template < template < typename > class ALLOC >
108 
109 
110  /// move constructor with a given allocator
111  template < template < typename > class ALLOC >
113  DBTranslator< ALLOC >&& from,
114  const typename DBTranslator< ALLOC >::allocator_type& alloc) :
121  }
122 
123 
124  /// move constructor
125  template < template < typename > class ALLOC >
128 
129 
130  /// destructor
131  template < template < typename > class ALLOC >
134  }
135 
136 
137  /// copy operator
138  template < template < typename > class ALLOC >
141  if (this != &from) {
147  }
148  return *this;
149  }
150 
151 
152  /// move operator
153  template < template < typename > class ALLOC >
160 
161  return *this;
162  }
163 
164 
165  /// alias for method translate
166  template < template < typename > class ALLOC >
168  return translate(str);
169  }
170 
171 
172  /// alias for method translateBack
173  template < template < typename > class ALLOC >
176  }
177 
178 
179  /// indicates whether the translator has an editable dictionary or not
180  template < template < typename > class ALLOC >
182  return is_dictionary_dynamic_;
183  }
184 
185 
186  /// sets/unset the editable dictionary mode
187  template < template < typename > class ALLOC >
190  }
191 
192 
193  /// returns the set of missing symbols taken into account by the translator
194  template < template < typename > class ALLOC >
195  INLINE const Set< std::string, ALLOC< std::string > >&
196  DBTranslator< ALLOC >::missingSymbols() const {
197  return missing_symbols_;
198  }
199 
200 
201  /// indicates whether a string corresponds to a missing symbol
202  template < template < typename > class ALLOC >
203  INLINE bool DBTranslator< ALLOC >::isMissingSymbol(const std::string& str) const {
204  return missing_symbols_.exists(str);
205  }
206 
207 
208  /// sets the name of the variable stored into the translator
209  template < template < typename > class ALLOC >
210  INLINE void DBTranslator< ALLOC >::setVariableName(const std::string& str) const {
211  const_cast< Variable* >(this->variable())->setName(str);
212  }
213 
214 
215  /// sets the name of the variable stored into the translator
216  template < template < typename > class ALLOC >
217  INLINE void DBTranslator< ALLOC >::setVariableDescription(const std::string& str) const {
218  const_cast< Variable* >(this->variable())->setDescription(str);
219  }
220 
221 
222  /// indicates whether a translated value corresponds to a missing value
223  template < template < typename > class ALLOC >
225  switch (val_type_) {
227  return value.discr_val == std::numeric_limits< std::size_t >::max();
228 
230  return value.cont_val == std::numeric_limits< float >::max();
231 
232  default:
234  "No missing value interpretation for this "
235  "translated value type");
236  }
237  }
238 
239 
240  } /* namespace learning */
241 
242 } /* namespace gum */
243 
244 #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)