56#ifndef DOXYGEN_SHOULD_SKIP_THIS
64 template <
typename GUM_SCALAR >
66 const DiscretizedVariable< GUM_SCALAR >& var,
67 const std::vector< std::string >& missing_symbols,
68 std::size_t max_dico_entries) :
74 _variable_(var.name(), var.description()) {
76 if (var.domainSize() > max_dico_entries) {
77 GUM_ERROR(SizeError,
"the dictionary induced by the variable is too large")
81 const auto& ticks = var.ticks();
82 for (
const auto tick: ticks) {
83 _variable_.addTick((
float)tick);
87 const auto lower_bound = (float)ticks[0];
88 const auto upper_bound = (float)ticks.back();
92 for (
auto iter = this->missing_symbols_.beginSafe(); iter != this->missing_symbols_.endSafe();
94 if (DBCell::isReal(*iter)) {
95 const float missing_val = std::stof(*iter);
96 if ((missing_val >= lower_bound) && (missing_val <= upper_bound)) {
97 this->missing_symbols_.erase(iter);
103 std::size_t size = 0;
104 for (
const auto& label: var.labels()) {
110 if (this->missing_symbols_.exists(label)) { this->missing_symbols_.erase(label); }
117 _real_variable_ = var.clone();
119 GUM_CONSTRUCTOR(DBTranslator4DiscretizedVariable);
123 template <
typename GUM_SCALAR >
124 DBTranslator4DiscretizedVariable::DBTranslator4DiscretizedVariable(
125 const DiscretizedVariable< GUM_SCALAR >& var,
126 std::size_t max_dico_entries) :
127 DBTranslator(DBTranslatedValueType::
DISCRETE, false, false, max_dico_entries),
128 _variable_(var.name(), var.description()) {
130 if (var.domainSize() > max_dico_entries) {
131 GUM_ERROR(SizeError,
"the dictionary induced by the variable is too large")
135 const auto& ticks = var.ticks();
136 for (
const auto tick: ticks) {
137 _variable_.addTick((
float)tick);
141 std::size_t size = 0;
142 for (
const auto& label: var.labels()) {
143 this->back_dico_.insert(size, label);
148 _real_variable_ = var.clone();
150 GUM_CONSTRUCTOR(DBTranslator4DiscretizedVariable);
The class representing the original values of the cells of databases.
The databases' cell translators for discretized variables.
void insert(const T1 &first, const T2 &second)
DBTranslator4DiscretizedVariable(const DiscretizedVariable< GUM_SCALAR > &var, const std::vector< std::string > &missing_symbols, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max())
default constructor with a discretized variable as translator
The base class for all the tabular database cell translators.
Bijection< std::size_t, std::string > back_dico_
the bijection relating back translated values and their original strings.
DBTranslatedValueType
The nature of the elements handled by translators (discrete, continuous).
include the inlined functions if necessary
gum is the global namespace for all aGrUM entities