aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
DBTranslator.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
50#ifndef GUM_LEARNING_DB_TRANSLATOR_H
51#define GUM_LEARNING_DB_TRANSLATOR_H
52
53#include <limits>
54#include <string>
55#include <utility>
56#include <vector>
57
58#include <agrum/agrum.h>
59
61#include <agrum/base/core/set.h>
64
65#include <string_view>
66
67namespace gum {
68
69 namespace learning {
70
71
138 public:
139 // ##########################################################################
141 // ##########################################################################
142
144
146
159 const bool is_lossless,
160 const std::vector< std::string >& missing_symbols,
161 const bool editable_dictionary = true,
162 std::size_t max_dico_entries = std::numeric_limits< std::size_t >::max());
163
165
176 const bool is_lossless,
177 const bool editable_dictionary = true,
178 std::size_t max_dico_entries = std::numeric_limits< std::size_t >::max());
179
182
185
187 [[nodiscard]] virtual DBTranslator* clone() const = 0;
188
190 virtual ~DBTranslator();
191
193
194
195 // ##########################################################################
197 // ##########################################################################
198
200
202 DBTranslatedValue operator<<(std::string_view str);
203
205 std::string operator>>(const DBTranslatedValue translated_val);
206
208
209
210 // ##########################################################################
212 // ##########################################################################
213
215
217
254 virtual DBTranslatedValue translate(std::string_view str) = 0;
255
257
268 virtual std::string translateBack(const DBTranslatedValue translated_val) const = 0;
269
271
280 virtual std::size_t domainSize() const = 0;
281
283 virtual bool hasEditableDictionary() const;
284
286 virtual void setEditableDictionaryMode(bool new_mode);
287
290
311 virtual bool needsReordering() const = 0;
312
326
329
331 bool isMissingSymbol(std::string_view str) const;
332
334 virtual const Variable* variable() const = 0;
335
337 void setVariableName(std::string_view str) const;
338
340 void setVariableDescription(std::string_view str) const;
341
343
349
351
357 bool isLossless() const;
358
360 bool isMissingValue(const DBTranslatedValue& val) const;
361
363 virtual DBTranslatedValue missingValue() const = 0;
364
366
367
368 protected:
369 // ##########################################################################
371 // ##########################################################################
372
374
377
380
382
385
388
390 std::size_t max_dico_entries_;
391
394
396
402
405 };
406
407
408 } /* namespace learning */
409
410} /* namespace gum */
411
413#ifndef GUM_NO_INLINE
415#endif /* GUM_NO_INLINE */
416
417#endif /* GUM_LEARNING_DB_TRANSLATOR_H */
The union class for storing the translated values in learning databases.
The base class for all the tabular databases' cell translators.
Set of pairs of elements with fast search for both elements.
The class for generic Hash Tables.
Definition hashTable.h:640
Base class for every random variable.
Definition variable.h:81
DBTranslator(DBTranslatedValueType val_type, const bool is_lossless, const std::vector< std::string > &missing_symbols, const bool editable_dictionary=true, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max())
default constructor
virtual std::string translateBack(const DBTranslatedValue translated_val) const =0
returns the original value for a given translation
Bijection< std::size_t, std::string > back_dico_
the bijection relating back translated values and their original strings.
virtual const Variable * variable() const =0
returns the variable stored into the translator
virtual std::size_t domainSize() const =0
returns the domain size of a variable corresponding to the translations
virtual DBTranslatedValue translate(std::string_view str)=0
returns the translation of a string
bool is_lossless_
indicates whether the translation is lossless (e.g., ranges) or not
void setVariableDescription(std::string_view str) const
sets the name of the variable stored into the translator
virtual bool needsReordering() const =0
indicates whether a reordering is needed to make the translations sorted
std::size_t max_dico_entries_
the maximum number of entries that the dictionary is allowed to contain
bool isMissingValue(const DBTranslatedValue &val) const
indicates whether a translated value corresponds to a missing value
DBTranslatedValueType val_type_
the type of the values translated by the translator
DBTranslator(const DBTranslator &from)
copy constructor
virtual void setEditableDictionaryMode(bool new_mode)
sets/unset the editable dictionary mode
virtual DBTranslator * clone() const =0
virtual copy constructor
std::string operator>>(const DBTranslatedValue translated_val)
alias for method translateBack
DBTranslatedValue operator<<(std::string_view str)
alias for method translate
Set< std::string > missing_symbols_
the set of missing symbols
void setVariableName(std::string_view str) const
sets the name of the variable stored into the translator
virtual const Bijection< std::size_t, std::string > & getDictionary() const
returns the translation from database indices to input strings
const Set< std::string > & missingSymbols() const
returns the set of missing symbols taken into account by the translator
DBTranslator(DBTranslator &&from)
move constructor
bool isLossless() const
returns a Boolean indicating whether the translation is lossless or not
virtual HashTable< std::size_t, std::size_t > reorder()=0
performs a reordering of the dictionary and returns a mapping from the old translated values to the n...
virtual ~DBTranslator()
destructor
virtual bool hasEditableDictionary() const
indicates whether the translator has an editable dictionary or not
bool is_dictionary_dynamic_
indicates whether the dictionary can be updated or not
virtual DBTranslatedValue missingValue() const =0
returns the translation of a missing value
DBTranslatedValueType getValType() const
returns the type of values handled by the translator
DBTranslator & operator=(const DBTranslator &from)
copy operator
DBTranslator(DBTranslatedValueType val_type, const bool is_lossless, const bool editable_dictionary=true, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max())
default constructor without missing symbols
DBTranslator & operator=(DBTranslator &&from)
move operator
bool isMissingSymbol(std::string_view str) const
indicates whether a string corresponds to a missing symbol
DBTranslatedValueType
The nature of the elements handled by translators (discrete, continuous).
include the inlined functions if necessary
Definition CSVParser.h:55
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Sets of elements (i.e.
The union class for storing the translated values in learning databases.
Base class for random variable.