aGrUM 2.3.2
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-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
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
65namespace gum {
66
67 namespace learning {
68
69
136 public:
137 // ##########################################################################
139 // ##########################################################################
140
142
144
157 const bool is_lossless,
158 const std::vector< std::string >& missing_symbols,
159 const bool editable_dictionary = true,
160 std::size_t max_dico_entries = std::numeric_limits< std::size_t >::max());
161
163
174 const bool is_lossless,
175 const bool editable_dictionary = true,
176 std::size_t max_dico_entries = std::numeric_limits< std::size_t >::max());
177
180
183
185 virtual DBTranslator* clone() const = 0;
186
188 virtual ~DBTranslator();
189
191
192
193 // ##########################################################################
195 // ##########################################################################
196
198
200 DBTranslatedValue operator<<(const std::string& str);
201
203 std::string operator>>(const DBTranslatedValue translated_val);
204
206
207
208 // ##########################################################################
210 // ##########################################################################
211
213
215
252 virtual DBTranslatedValue translate(const std::string& str) = 0;
253
255
266 virtual std::string translateBack(const DBTranslatedValue translated_val) const = 0;
267
269
278 virtual std::size_t domainSize() const = 0;
279
281 virtual bool hasEditableDictionary() const;
282
284 virtual void setEditableDictionaryMode(bool new_mode);
285
288
309 virtual bool needsReordering() const = 0;
310
324
327
329 bool isMissingSymbol(const std::string& str) const;
330
332 virtual const Variable* variable() const = 0;
333
335 void setVariableName(const std::string& str) const;
336
338 void setVariableDescription(const std::string& str) const;
339
341
347
349
355 bool isLossless() const;
356
358 bool isMissingValue(const DBTranslatedValue& val) const;
359
361 virtual DBTranslatedValue missingValue() const = 0;
362
364
365
366 protected:
367 // ##########################################################################
369 // ##########################################################################
370
372
375
378
380
383
386
388 std::size_t max_dico_entries_;
389
392
394
400
403 };
404
405
406 } /* namespace learning */
407
408} /* namespace gum */
409
411#ifndef GUM_NO_INLINE
413#endif /* GUM_NO_INLINE */
414
415#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:637
Base class for every random variable.
Definition variable.h:79
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
bool is_lossless_
indicates whether the translation is lossless (e.g., ranges) or not
void setVariableName(const std::string &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 DBTranslatedValue translate(const std::string &str)=0
returns the translation of a string
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
Set< std::string > missing_symbols_
the set of missing symbols
bool isMissingSymbol(const std::string &str) const
indicates whether a string corresponds to a missing symbol
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
DBTranslatedValue operator<<(const std::string &str)
alias for method translate
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
void setVariableDescription(const std::string &str) const
sets the name of the variable stored into the translator
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
DBTranslatedValueType
The nature of the elements handled by translators (discrete, continuous).
include the inlined functions if necessary
Definition CSVParser.h:54
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.