aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
DBTranslatorSet_inl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40#pragma once
41
42
43#ifndef DOXYGEN_SHOULD_SKIP_THIS
44
46
47namespace gum {
48
49 namespace learning {
51 INLINE DBTranslatorSet::DBTranslatorSet() { GUM_CONSTRUCTOR(DBTranslatorSet); }
52
55 _copy_(from);
56
57 GUM_CONS_CPY(DBTranslatorSet);
58 }
59
62 _translators_(std::move(from._translators_)), _columns_(std::move(from._columns_)),
63 _highest_column_(from._highest_column_) {
64 GUM_CONS_MOV(DBTranslatorSet);
65 }
66
68 INLINE DBTranslatorSet* DBTranslatorSet::clone() const { return new DBTranslatorSet(*this); }
69
71 INLINE DBTranslatorSet::~DBTranslatorSet() {
72 clear();
73 GUM_DESTRUCTOR(DBTranslatorSet);
74 }
75
77 INLINE DBTranslatorSet& DBTranslatorSet::operator=(DBTranslatorSet&& from) {
78 if (this != &from) {
79 clear();
80 _translators_ = std::move(from._translators_);
81 _columns_ = std::move(from._columns_);
82 _highest_column_ = from._highest_column_;
83 }
84
85 return *this;
86 }
87
89 INLINE DBTranslator& DBTranslatorSet::operator[](const std::size_t k) {
90 return *(_translators_[k]);
91 }
92
94 INLINE const DBTranslator& DBTranslatorSet::operator[](const std::size_t k) const {
95 return *(_translators_[k]);
96 }
97
99 INLINE std::size_t DBTranslatorSet::insertTranslator(const Variable& var,
100 const std::size_t column,
101 const bool unique_column) {
102 const std::vector< std::string > missing;
103 return this->insertTranslator(var, column, missing, unique_column);
104 }
105
107 INLINE DBTranslatedValue DBTranslatorSet::translate(const std::vector< std::string >& row,
108 const std::size_t k) const {
109 return _translators_[k]->translate(row[_columns_[k]]);
110 }
111
113 INLINE DBTranslatedValue DBTranslatorSet::translateSafe(const std::vector< std::string >& row,
114 const std::size_t k) const {
115 if (_translators_.size() <= k)
116 GUM_ERROR(UndefinedElement, "Translator #" << k << " could not be found")
117
118 return _translators_[k]->translate(row[_columns_[k]]);
119 }
120
122 INLINE std::string DBTranslatorSet::translateBack(const DBTranslatedValue translated_val,
123 const std::size_t k) const {
124 return _translators_[k]->translateBack(translated_val);
125 }
126
128 INLINE std::string DBTranslatorSet::translateBackSafe(const DBTranslatedValue translated_val,
129 const std::size_t k) const {
130 if (_translators_.size() <= k)
131 GUM_ERROR(UndefinedElement, "Translator #" << k << "could not be found")
132
133 return _translators_[k]->translateBack(translated_val);
134 }
135
136 // indicates whether the kth translator considers a translated_val
137 // as a missing value
138 INLINE bool DBTranslatorSet::isMissingValue(const DBTranslatedValue translated_val,
139 const std::size_t k) const {
140 return _translators_[k]->isMissingValue(translated_val);
141 }
142
143 // indicates whether the kth translator considers a translated_val
144 // as a missing value
145 INLINE bool DBTranslatorSet::isMissingValueSafe(const DBTranslatedValue translated_val,
146 const std::size_t k) const {
147 if (_translators_.size() <= k)
148 GUM_ERROR(UndefinedElement, "Translator #" << k << "could not be found")
149
150 return _translators_[k]->isMissingValue(translated_val);
151 }
152
154 INLINE DBTranslator& DBTranslatorSet::translator(const std::size_t k) {
155 return *(_translators_[k]);
156 }
157
159 INLINE const DBTranslator& DBTranslatorSet::translator(const std::size_t k) const {
160 return *(_translators_[k]);
161 }
162
164 INLINE DBTranslator& DBTranslatorSet::translatorSafe(const std::size_t k) {
165 if (_translators_.size() <= k)
166 GUM_ERROR(UndefinedElement, "Translator #" << k << "could not be found")
167
168 return *(_translators_[k]);
169 }
170
172 INLINE const DBTranslator& DBTranslatorSet::translatorSafe(const std::size_t k) const {
173 if (_translators_.size() <= k)
174 GUM_ERROR(UndefinedElement, "Translator #" << k << "could not be found")
175
176 return *(_translators_[k]);
177 }
178
180 INLINE std::size_t DBTranslatorSet::domainSize(const std::size_t k) const {
181 return _translators_[k]->domainSize();
182 }
183
185 INLINE std::size_t DBTranslatorSet::domainSizeSafe(const std::size_t k) const {
186 if (_translators_.size() <= k)
187 GUM_ERROR(UndefinedElement, "Variable #" << k << "could not be found")
188
189 return _translators_[k]->domainSize();
190 }
191
193 INLINE const Variable& DBTranslatorSet::variable(const std::size_t k) const {
194 return *(_translators_[k]->variable());
195 }
196
198 INLINE const Variable& DBTranslatorSet::variableSafe(const std::size_t k) const {
199 if (_translators_.size() <= k)
200 GUM_ERROR(UndefinedElement, "Variable #" << k << "could not be found")
201
202 return *(_translators_[k]->variable());
203 }
204
205 // indicates whether a reordering is needed to make the kth translator
206 // sorted by lexicographical order
207 INLINE bool DBTranslatorSet::needsReordering(const std::size_t k) const {
208 return _translators_[k]->needsReordering();
209 }
210
211 // indicates whether a reordering is needed to make the kth translator
212 // sorted by lexicographical order
213 INLINE bool DBTranslatorSet::needsReorderingSafe(const std::size_t k) const {
214 if (_translators_.size() <= k)
215 GUM_ERROR(UndefinedElement, "Variable #" << k << "could not be found")
216
217 return _translators_[k]->needsReordering();
218 }
219
220 // performs a reordering of the dictionary and returns a mapping
221 // from the old translated values to the new ones.
222 INLINE HashTable< std::size_t, std::size_t > DBTranslatorSet::reorder(const std::size_t k) {
223 return _translators_[k]->reorder();
224 }
225
226 // performs a reordering of the dictionary and returns a mapping
227 // from the old translated values to the new ones.
228 INLINE HashTable< std::size_t, std::size_t > DBTranslatorSet::reorderSafe(const std::size_t k) {
229 if (_translators_.size() <= k)
230 GUM_ERROR(UndefinedElement, "Variable #" << k << "could not be found")
231
232 return _translators_[k]->reorder();
233 }
234
237 INLINE std::size_t DBTranslatorSet::inputColumn(const std::size_t k) const {
238 return _columns_[k];
239 }
240
243 INLINE std::size_t DBTranslatorSet::inputColumnSafe(const std::size_t k) const {
244 if (_translators_.size() <= k)
245 GUM_ERROR(UndefinedElement, "Column #" << k << "could not be found")
246
247 return _columns_[k];
248 }
249
251 INLINE std::size_t DBTranslatorSet::highestInputColumn() const { return _highest_column_; }
252
254 INLINE std::size_t DBTranslatorSet::nbTranslators() const { return _columns_.size(); }
255
257 INLINE std::size_t DBTranslatorSet::size() const { return _columns_.size(); }
258
260 INLINE const std::vector< DBTranslator* >& DBTranslatorSet::translators() const {
261 return _translators_;
262 }
263
264 } /* namespace learning */
265
266} /* namespace gum */
267
268#endif /* DOXYGEN_SHOULD_SKIP_THIS */
A class for storing several translators.
Exception : a looked-for element could not be found.
the class for packing together the translators used to preprocess the datasets
DBTranslatorSet()
default constructor
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.