aGrUM 3.1.1
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-2026 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-2026 *
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
41#pragma once
42
43
44#include <agrum/base/database/DBTranslatorSet.h> // to ease IDE parser
45#ifndef DOXYGEN_SHOULD_SKIP_THIS
46
48
49namespace gum {
50
51 namespace learning {
53 INLINE DBTranslatorSet::DBTranslatorSet() { GUM_CONSTRUCTOR(DBTranslatorSet); }
54
57 _copy_(from);
58
59 GUM_CONS_CPY(DBTranslatorSet);
60 }
61
64 _translators_(std::move(from._translators_)), _columns_(std::move(from._columns_)),
65 _highest_column_(from._highest_column_) {
66 GUM_CONS_MOV(DBTranslatorSet);
67 }
68
70 INLINE DBTranslatorSet* DBTranslatorSet::clone() const { return new DBTranslatorSet(*this); }
71
73 INLINE DBTranslatorSet::~DBTranslatorSet() {
74 clear();
75 GUM_DESTRUCTOR(DBTranslatorSet);
76 }
77
79 INLINE DBTranslatorSet& DBTranslatorSet::operator=(DBTranslatorSet&& from) {
80 if (this != &from) {
81 clear();
82 _translators_ = std::move(from._translators_);
83 _columns_ = std::move(from._columns_);
84 _highest_column_ = from._highest_column_;
85 }
86
87 return *this;
88 }
89
91 INLINE DBTranslator& DBTranslatorSet::operator[](const std::size_t k) {
92 return *(_translators_[k]);
93 }
94
96 INLINE const DBTranslator& DBTranslatorSet::operator[](const std::size_t k) const {
97 return *(_translators_[k]);
98 }
99
101 INLINE std::size_t DBTranslatorSet::insertTranslator(const Variable& var,
102 const std::size_t column,
103 const bool unique_column) {
104 const std::vector< std::string > missing;
105 return this->insertTranslator(var, column, missing, unique_column);
106 }
107
109 INLINE DBTranslatedValue DBTranslatorSet::translate(const std::vector< std::string >& row,
110 const std::size_t k) const {
111 return _translators_[k]->translate(row[_columns_[k]]);
112 }
113
115 INLINE DBTranslatedValue DBTranslatorSet::translateSafe(const std::vector< std::string >& row,
116 const std::size_t k) const {
117 if (_translators_.size() <= k)
118 GUM_ERROR(UndefinedElement, "Translator #" << k << " could not be found")
119
120 return _translators_[k]->translate(row[_columns_[k]]);
121 }
122
124 INLINE std::string DBTranslatorSet::translateBack(const DBTranslatedValue translated_val,
125 const std::size_t k) const {
126 return _translators_[k]->translateBack(translated_val);
127 }
128
130 INLINE std::string DBTranslatorSet::translateBackSafe(const DBTranslatedValue translated_val,
131 const std::size_t k) const {
132 if (_translators_.size() <= k)
133 GUM_ERROR(UndefinedElement, "Translator #" << k << "could not be found")
134
135 return _translators_[k]->translateBack(translated_val);
136 }
137
138 // indicates whether the kth translator considers a translated_val
139 // as a missing value
140 INLINE bool DBTranslatorSet::isMissingValue(const DBTranslatedValue translated_val,
141 const std::size_t k) const {
142 return _translators_[k]->isMissingValue(translated_val);
143 }
144
145 // indicates whether the kth translator considers a translated_val
146 // as a missing value
147 INLINE bool DBTranslatorSet::isMissingValueSafe(const DBTranslatedValue translated_val,
148 const std::size_t k) const {
149 if (_translators_.size() <= k)
150 GUM_ERROR(UndefinedElement, "Translator #" << k << "could not be found")
151
152 return _translators_[k]->isMissingValue(translated_val);
153 }
154
156 INLINE DBTranslator& DBTranslatorSet::translator(const std::size_t k) {
157 return *(_translators_[k]);
158 }
159
161 INLINE const DBTranslator& DBTranslatorSet::translator(const std::size_t k) const {
162 return *(_translators_[k]);
163 }
164
166 INLINE DBTranslator& DBTranslatorSet::translatorSafe(const std::size_t k) {
167 if (_translators_.size() <= k)
168 GUM_ERROR(UndefinedElement, "Translator #" << k << "could not be found")
169
170 return *(_translators_[k]);
171 }
172
174 INLINE const DBTranslator& DBTranslatorSet::translatorSafe(const std::size_t k) const {
175 if (_translators_.size() <= k)
176 GUM_ERROR(UndefinedElement, "Translator #" << k << "could not be found")
177
178 return *(_translators_[k]);
179 }
180
182 INLINE std::size_t DBTranslatorSet::domainSize(const std::size_t k) const {
183 return _translators_[k]->domainSize();
184 }
185
187 INLINE std::size_t DBTranslatorSet::domainSizeSafe(const std::size_t k) const {
188 if (_translators_.size() <= k)
189 GUM_ERROR(UndefinedElement, "Variable #" << k << "could not be found")
190
191 return _translators_[k]->domainSize();
192 }
193
195 INLINE const Variable& DBTranslatorSet::variable(const std::size_t k) const {
196 return *(_translators_[k]->variable());
197 }
198
200 INLINE const Variable& DBTranslatorSet::variableSafe(const std::size_t k) const {
201 if (_translators_.size() <= k)
202 GUM_ERROR(UndefinedElement, "Variable #" << k << "could not be found")
203
204 return *(_translators_[k]->variable());
205 }
206
207 // indicates whether a reordering is needed to make the kth translator
208 // sorted by lexicographical order
209 INLINE bool DBTranslatorSet::needsReordering(const std::size_t k) const {
210 return _translators_[k]->needsReordering();
211 }
212
213 // indicates whether a reordering is needed to make the kth translator
214 // sorted by lexicographical order
215 INLINE bool DBTranslatorSet::needsReorderingSafe(const std::size_t k) const {
216 if (_translators_.size() <= k)
217 GUM_ERROR(UndefinedElement, "Variable #" << k << "could not be found")
218
219 return _translators_[k]->needsReordering();
220 }
221
222 // performs a reordering of the dictionary and returns a mapping
223 // from the old translated values to the new ones.
224 INLINE HashTable< std::size_t, std::size_t > DBTranslatorSet::reorder(const std::size_t k) {
225 return _translators_[k]->reorder();
226 }
227
228 // performs a reordering of the dictionary and returns a mapping
229 // from the old translated values to the new ones.
230 INLINE HashTable< std::size_t, std::size_t > DBTranslatorSet::reorderSafe(const std::size_t k) {
231 if (_translators_.size() <= k)
232 GUM_ERROR(UndefinedElement, "Variable #" << k << "could not be found")
233
234 return _translators_[k]->reorder();
235 }
236
239 INLINE std::size_t DBTranslatorSet::inputColumn(const std::size_t k) const {
240 return _columns_[k];
241 }
242
245 INLINE std::size_t DBTranslatorSet::inputColumnSafe(const std::size_t k) const {
246 if (_translators_.size() <= k)
247 GUM_ERROR(UndefinedElement, "Column #" << k << "could not be found")
248
249 return _columns_[k];
250 }
251
253 INLINE std::size_t DBTranslatorSet::highestInputColumn() const { return _highest_column_; }
254
256 INLINE std::size_t DBTranslatorSet::nbTranslators() const { return _columns_.size(); }
257
259 INLINE std::size_t DBTranslatorSet::size() const { return _columns_.size(); }
260
262 INLINE const std::vector< DBTranslator* >& DBTranslatorSet::translators() const {
263 return _translators_;
264 }
265
266 } /* namespace learning */
267
268} /* namespace gum */
269
270#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:76
include the inlined functions if necessary
Definition CSVParser.h:55
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.