aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
DBTranslator4LabelizedVariable_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
49
50#include <utility>
51#include <vector>
52
55
56#ifndef DOXYGEN_SHOULD_SKIP_THIS
57
58namespace gum {
59
60 namespace learning {
61
65 DBTranslator(from), _variable_(from._variable_) {
66 GUM_CONS_CPY(DBTranslator4LabelizedVariable);
67 }
68
70 INLINE DBTranslator4LabelizedVariable::DBTranslator4LabelizedVariable(
71 DBTranslator4LabelizedVariable&& from) :
72 DBTranslator(std::move(from)), _variable_(std::move(from._variable_)) {
73 GUM_CONS_MOV(DBTranslator4LabelizedVariable);
74 }
75
77 INLINE DBTranslator4LabelizedVariable::~DBTranslator4LabelizedVariable() {
78 GUM_DESTRUCTOR(DBTranslator4LabelizedVariable);
79 }
80
82 INLINE std::string DBTranslator4LabelizedVariable::translateBack(
83 const DBTranslatedValue translated_val) const {
84 try {
85 return this->back_dico_.second(translated_val.discr_val);
86 } catch (Exception const&) {
87 // check if this is a missing value
88 if ((translated_val.discr_val == std::numeric_limits< std::size_t >::max())
89 && !this->missing_symbols_.empty())
90 // all missing values share the same sentinel: return first symbol as representative
91 return *(this->missing_symbols_.begin());
92 else
94 "The back translation of \"" << translated_val.discr_val
95 << "\" could not be found");
96 }
97 }
98
100 INLINE std::size_t DBTranslator4LabelizedVariable::domainSize() const {
101 return _variable_.domainSize();
102 }
103
105 INLINE const LabelizedVariable* DBTranslator4LabelizedVariable::variable() const {
106 return &_variable_;
107 }
108
110 INLINE DBTranslatedValue DBTranslator4LabelizedVariable::missingValue() const {
111 return DBTranslatedValue{std::numeric_limits< std::size_t >::max()};
112 }
113
114
115 } /* namespace learning */
116
117} /* namespace gum */
118
119
120#endif /* DOXYGEN_SHOULD_SKIP_THIS */
The class representing the original values of the cells of databases.
The databases' cell translators for labelized variables.
Error: An unknown label is found in the database.
The databases' cell translators for labelized variables.
DBTranslator4LabelizedVariable(const std::vector< std::string > &missing_symbols, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max())
default constructor without any initial variable
The base class for all the tabular database cell translators.
#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.