aGrUM
0.21.0
a C++ library for (probabilistic) graphical models
DBTranslatorSet_tpl.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4
* info_at_agrum_dot_org
5
*
6
* This library is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this library. If not, see <http://www.gnu.org/licenses/>.
18
*
19
*/
20
21
22
/** @file
23
* @brief The set of translators stored into a row filter
24
*
25
* @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26
*/
27
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
28
29
namespace
gum
{
30
31
namespace
learning
{
32
33
/// returns the allocator used by the translator set
34
template
<
template
<
typename
>
class
ALLOC >
35
typename
DBTranslatorSet<
ALLOC
>::
allocator_type
36
DBTranslatorSet
<
ALLOC
>::
getAllocator
()
const
{
37
return
_columns_
.
get_allocator
();
38
}
39
40
41
/// remove all the translators from the vector
42
template
<
template
<
typename
>
class
ALLOC
>
43
void
DBTranslatorSet
<
ALLOC
>::
clear
() {
44
ALLOC
<
DBTranslator
<
ALLOC
> >
allocator
(
this
->
getAllocator
());
45
for
(
auto
translator
:
_translators_
) {
46
allocator
.
destroy
(
translator
);
47
allocator
.
deallocate
(
translator
, 1);
48
}
49
50
_translators_
.
clear
();
51
_columns_
.
clear
();
52
_highest_column_
=
std
::
size_t
(0);
53
}
54
55
56
/// copy the content of another translator set that uses another allocator
57
template
<
template
<
typename
>
class
ALLOC
>
58
void
DBTranslatorSet
<
ALLOC
>::
_copy_
(
59
const
DBTranslatorSet
<
ALLOC
>&
from
,
60
const
typename
DBTranslatorSet
<
ALLOC
>::
allocator_type
&
alloc
) {
61
if
(
_translators_
.
size
() != 0)
clear
();
62
63
// resize the vectors used in the set. First, we reserve new memory. This
64
// will keep the DBTranslatorSet in a correct state, even if the memory
65
// allocation fails
66
const
std
::
size_t
size
=
from
.
_translators_
.
size
();
67
_translators_
.
reserve
(
size
);
68
_columns_
.
reserve
(
size
);
69
_translators_
.
resize
(
size
);
70
_columns_
.
resize
(
size
);
71
72
std
::
size_t
i
;
73
try
{
74
for
(
i
=
std
::
size_t
(0);
i
<
size
; ++
i
) {
75
_translators_
[
i
] =
from
.
_translators_
[
i
]->
clone
(
alloc
);
76
_columns_
[
i
] =
from
.
_columns_
[
i
];
77
}
78
}
catch
(...) {
79
_translators_
.
resize
(
i
);
80
clear
();
81
throw
;
82
}
83
84
_highest_column_
=
from
.
_highest_column_
;
85
}
86
87
88
/// default constructor
89
template
<
template
<
typename
>
class
ALLOC
>
90
INLINE
DBTranslatorSet
<
ALLOC
>::
DBTranslatorSet
(
91
const
typename
DBTranslatorSet
<
ALLOC
>::
allocator_type
&
alloc
) :
92
_translators_
(
alloc
),
93
_columns_
(
allocator_type
(
alloc
)) {
94
GUM_CONSTRUCTOR
(
DBTranslatorSet
);
95
}
96
97
98
/// copy constructor with a given allocator
99
template
<
template
<
typename
>
class
ALLOC
>
100
INLINE
DBTranslatorSet
<
ALLOC
>::
DBTranslatorSet
(
101
const
DBTranslatorSet
<
ALLOC
>&
from
,
102
const
typename
DBTranslatorSet
<
ALLOC
>::
allocator_type
&
alloc
) :
103
_translators_
(
alloc
),
104
_columns_
(
alloc
) {
105
_copy_
(
from
,
alloc
);
106
107
GUM_CONS_CPY
(
DBTranslatorSet
);
108
}
109
110
111
/// copy constructor
112
template
<
template
<
typename
>
class
ALLOC
>
113
INLINE
DBTranslatorSet
<
ALLOC
>::
DBTranslatorSet
(
const
DBTranslatorSet
<
ALLOC
>&
from
) :
114
DBTranslatorSet
<
ALLOC
>(
from
,
from
.
getAllocator
()) {}
115
116
117
/// move constructor with a given allocator
118
template
<
template
<
typename
>
class
ALLOC
>
119
INLINE
DBTranslatorSet
<
ALLOC
>::
DBTranslatorSet
(
120
DBTranslatorSet
<
ALLOC
>&&
from
,
121
const
typename
DBTranslatorSet
<
ALLOC
>::
allocator_type
&
alloc
) :
122
_translators_
(
std
::
move
(
from
.
_translators_
),
alloc
),
123
_columns_
(
std
::
move
(
from
.
_columns_
),
alloc
),
_highest_column_
(
from
.
_highest_column_
) {
124
GUM_CONS_MOV
(
DBTranslatorSet
);
125
}
126
127
128
/// move constructor
129
template
<
template
<
typename
>
class
ALLOC
>
130
INLINE
DBTranslatorSet
<
ALLOC
>::
DBTranslatorSet
(
DBTranslatorSet
<
ALLOC
>&&
from
) :
131
DBTranslatorSet
<
ALLOC
>(
from
,
from
.
getAllocator
()) {}
132
133
134
/// virtual copy constructor with a given allocator
135
template
<
template
<
typename
>
class
ALLOC
>
136
DBTranslatorSet
<
ALLOC
>*
DBTranslatorSet
<
ALLOC
>::
clone
(
137
const
typename
DBTranslatorSet
<
ALLOC
>::
allocator_type
&
alloc
)
const
{
138
ALLOC
<
DBTranslatorSet
<
ALLOC
> >
allocator
(
alloc
);
139
DBTranslatorSet
<
ALLOC
>*
set
=
allocator
.
allocate
(1);
140
try
{
141
allocator
.
construct
(
set
, *
this
,
alloc
);
142
}
catch
(...) {
143
allocator
.
deallocate
(
set
, 1);
144
throw
;
145
}
146
return
set
;
147
}
148
149
150
/// virtual copy constructor
151
template
<
template
<
typename
>
class
ALLOC
>
152
DBTranslatorSet
<
ALLOC
>*
DBTranslatorSet
<
ALLOC
>::
clone
()
const
{
153
return
clone
(
this
->
getAllocator
());
154
}
155
156
157
/// destructor
158
template
<
template
<
typename
>
class
ALLOC
>
159
INLINE
DBTranslatorSet
<
ALLOC
>::~
DBTranslatorSet
() {
160
clear
();
161
GUM_DESTRUCTOR
(
DBTranslatorSet
);
162
}
163
164
165
/// copy operator
166
template
<
template
<
typename
>
class
ALLOC
>
167
DBTranslatorSet
<
ALLOC
>&
168
DBTranslatorSet
<
ALLOC
>::
operator
=(
const
DBTranslatorSet
<
ALLOC
>&
from
) {
169
if
(
this
!= &
from
) {
170
clear
();
171
_copy_
(
from
,
this
->
getAllocator
());
172
}
173
174
return
*
this
;
175
}
176
177
178
/// move operator
179
template
<
template
<
typename
>
class
ALLOC
>
180
INLINE
DBTranslatorSet
<
ALLOC
>&
181
DBTranslatorSet
<
ALLOC
>::
operator
=(
DBTranslatorSet
<
ALLOC
>&&
from
) {
182
if
(
this
!= &
from
) {
183
clear
();
184
_translators_
=
std
::
move
(
from
.
_translators_
);
185
_columns_
=
std
::
move
(
from
.
_columns_
);
186
_highest_column_
=
from
.
_highest_column_
;
187
}
188
189
return
*
this
;
190
}
191
192
193
/// returns the ith translator
194
template
<
template
<
typename
>
class
ALLOC
>
195
INLINE
DBTranslator
<
ALLOC
>&
DBTranslatorSet
<
ALLOC
>::
operator
[](
const
std
::
size_t
k
) {
196
return
*(
_translators_
[
k
]);
197
}
198
199
200
/// returns the ith translator
201
template
<
template
<
typename
>
class
ALLOC
>
202
INLINE
const
DBTranslator
<
ALLOC
>&
203
DBTranslatorSet
<
ALLOC
>::
operator
[](
const
std
::
size_t
k
)
const
{
204
return
*(
_translators_
[
k
]);
205
}
206
207
208
/// inserts a new translator at the end of the translator set
209
template
<
template
<
typename
>
class
ALLOC
>
210
template
<
template
<
template
<
typename
>
class
>
class
Translator
>
211
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
insertTranslator
(
const
Translator
<
ALLOC
>&
translator
,
212
const
std
::
size_t
column
,
213
const
bool
unique_column
) {
214
// if the unique_column parameter is set to true and there exists already
215
// another translator that parses the column, raise a DuplicateElement
216
// exception
217
const
std
::
size_t
size
=
_translators_
.
size
();
218
if
(
unique_column
) {
219
for
(
std
::
size_t
i
=
std
::
size_t
(0);
i
<
size
; ++
i
) {
220
if
(
_columns_
[
i
] ==
column
)
221
GUM_ERROR
(
DuplicateElement
,
222
"There already exists a DBTranslator that parses Column"
<<
column
)
223
}
224
}
225
226
// reserve some place for the new translator
227
_translators_
.
reserve
(
size
+ 1);
228
_columns_
.
reserve
(
size
+ 1);
229
230
// create and add the new translator
231
ALLOC
<
DBTranslator
<
ALLOC
> >
allocator
(
this
->
getAllocator
());
232
DBTranslator
<
ALLOC
>*
new_translator
=
translator
.
clone
(
allocator
);
233
234
_translators_
.
resize
(
size
+ 1);
235
_columns_
.
resize
(
size
+ 1);
236
_translators_
[
size
] =
new_translator
;
237
_columns_
[
size
] =
column
;
238
239
// update the highest column
240
if
(
column
>
_highest_column_
)
_highest_column_
=
column
;
241
242
return
size
;
243
}
244
245
246
/// returns a new translator corresponding to a variable and some missing symbols
247
//template < template < typename > class ALLOC >
248
249
250
/// inserts a new translator for a given variable in the translator set
251
template
<
template
<
typename
>
class
ALLOC
>
252
template
<
template
<
typename
>
class
XALLOC
>
253
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
insertTranslator
(
254
const
Variable
&
var
,
255
const
std
::
size_t
column
,
256
const
std
::
vector
<
std
::
string
,
XALLOC
<
std
::
string
> >&
missing_symbols
,
257
const
bool
unique_column
) {
258
// create the translator, depending on the type of the variable
259
switch
(
var
.
varType
()) {
260
case
VarType
::
Labelized
: {
261
const
LabelizedVariable
&
xvar
=
static_cast
<
const
LabelizedVariable
& >(
var
);
262
DBTranslator4LabelizedVariable
<
ALLOC
>
translator
(
xvar
,
missing_symbols
);
263
return
insertTranslator
(
translator
,
column
,
unique_column
);
264
}
265
266
case
VarType
::
Integer
: {
267
const
IntegerVariable
&
xvar
=
static_cast
<
const
IntegerVariable
& >(
var
);
268
DBTranslator4IntegerVariable
<
ALLOC
>
translator
(
xvar
,
missing_symbols
);
269
return
insertTranslator
(
translator
,
column
,
unique_column
);
270
}
271
272
case
VarType
::
Discretized
: {
273
const
IDiscretizedVariable
&
xvar
=
static_cast
<
const
IDiscretizedVariable
& >(
var
);
274
DBTranslator4DiscretizedVariable
<
ALLOC
>
translator
(
xvar
,
missing_symbols
);
275
return
insertTranslator
(
translator
,
column
,
unique_column
);
276
}
277
278
case
VarType
::
Range
: {
279
const
RangeVariable
&
xvar
=
static_cast
<
const
RangeVariable
& >(
var
);
280
DBTranslator4RangeVariable
<
ALLOC
>
translator
(
xvar
,
missing_symbols
);
281
return
insertTranslator
(
translator
,
column
,
unique_column
);
282
}
283
284
case
VarType
::
Continuous
: {
285
const
IContinuousVariable
&
xvar
=
static_cast
<
const
IContinuousVariable
& >(
var
);
286
DBTranslator4ContinuousVariable
<
ALLOC
>
translator
(
xvar
,
missing_symbols
);
287
return
insertTranslator
(
translator
,
column
,
unique_column
);
288
}
289
290
default
:
291
GUM_ERROR
(
NotImplementedYet
,
292
"The insertion of the translator for Variable "
293
<<
var
.
name
()
294
<<
" is impossible because a translator "
295
"for such variable is not implemented yet"
)
296
}
297
}
298
299
300
/// inserts a new translator for a given variable in the translator set
301
template
<
template
<
typename
>
class
ALLOC
>
302
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
insertTranslator
(
const
Variable
&
var
,
303
const
std
::
size_t
column
,
304
const
bool
unique_column
) {
305
const
std
::
vector
<
std
::
string
,
ALLOC
<
std
::
string
> >
missing
;
306
return
this
->
insertTranslator
(
var
,
column
,
missing
,
unique_column
);
307
}
308
309
310
/// substitute a translator by another one
311
template
<
template
<
typename
>
class
ALLOC
>
312
template
<
template
<
template
<
typename
>
class
>
class
Translator
>
313
void
DBTranslatorSet
<
ALLOC
>::
substituteTranslator
(
const
Translator
<
ALLOC
>&
new_translator
,
314
const
std
::
size_t
pos
) {
315
// check that the translator to be substituted exsts
316
if
(
_translators_
.
size
() <
pos
) {
317
GUM_ERROR
(
OutOfBounds
,
318
"The translatorSet contains only "
<<
_translators_
.
size
()
319
<<
" translators. It is therefore impossible to substitute "
320
<<
"the translator at index "
<<
pos
);
321
}
322
323
// copy the new translator
324
ALLOC
<
DBTranslator
<
ALLOC
> >
alloc
(
this
->
getAllocator
());
325
DBTranslator
<
ALLOC
>*
translator
=
new_translator
.
clone
(
alloc
);
326
327
// remove the old translator
328
_translators_
[
pos
]->~
DBTranslator
<
ALLOC
>();
329
alloc
.
deallocate
(
_translators_
[
pos
], 1);
330
331
// insert the copy
332
_translators_
[
pos
] =
translator
;
333
}
334
335
336
/// erase the kth translator
337
template
<
template
<
typename
>
class
ALLOC
>
338
void
DBTranslatorSet
<
ALLOC
>::
eraseTranslator
(
const
std
::
size_t
k
,
const
bool
k_is_input_col
) {
339
ALLOC
<
DBTranslator
<
ALLOC
> >
allocator
(
this
->
getAllocator
());
340
const
std
::
size_t
nb_trans
=
_translators_
.
size
();
341
342
if
(!
k_is_input_col
) {
343
if
(
nb_trans
<
k
)
return
;
344
345
// remove the translator and its corresponding column
346
allocator
.
destroy
(
_translators_
[
k
]);
347
allocator
.
deallocate
(
_translators_
[
k
], 1);
348
349
const
std
::
size_t
colk
=
_columns_
[
k
];
350
_translators_
.
erase
(
_translators_
.
begin
() +
k
);
351
_columns_
.
erase
(
_columns_
.
begin
() +
k
);
352
353
// if the highest column index corresponded to the kth translator,
354
// we must recomput it
355
if
(
_highest_column_
==
colk
) {
356
_highest_column_
=
std
::
size_t
(0);
357
for
(
const
auto
col
:
_columns_
)
358
if
(
_highest_column_
<
col
)
_highest_column_
=
col
;
359
}
360
}
else
{
361
// remove all the translators parsing the kth column
362
auto
iter_trans
=
_translators_
.
rbegin
();
363
bool
translator_found
=
false
;
364
for
(
auto
iter_col
=
_columns_
.
rbegin
();
iter_col
!=
_columns_
.
rend
();
365
++
iter_col
, ++
iter_trans
) {
366
if
(*
iter_col
==
k
) {
367
// remove the translator and its corresponding column
368
allocator
.
destroy
(*
iter_trans
);
369
allocator
.
deallocate
(*
iter_trans
, 1);
370
371
_translators_
.
erase
((
iter_trans
+ 1).
base
());
372
_columns_
.
erase
((
iter_col
+ 1).
base
());
373
translator_found
=
true
;
374
}
375
}
376
377
// if the highest column index corresponded to one of the translators
378
// removed, we must recompute it
379
if
(
translator_found
&& (
k
==
_highest_column_
)) {
380
_highest_column_
=
std
::
size_t
(0);
381
for
(
const
auto
col
:
_columns_
)
382
if
(
_highest_column_
<
col
)
_highest_column_
=
col
;
383
}
384
}
385
}
386
387
388
/// ask the kth translator to translate a string in a row of the database
389
template
<
template
<
typename
>
class
ALLOC
>
390
template
<
template
<
typename
>
class
OTHER_ALLOC
>
391
INLINE
DBTranslatedValue
DBTranslatorSet
<
ALLOC
>::
translate
(
392
const
std
::
vector
<
std
::
string
,
OTHER_ALLOC
<
std
::
string
> >&
row
,
393
const
std
::
size_t
k
)
const
{
394
return
_translators_
[
k
]->
translate
(
row
[
_columns_
[
k
]]);
395
}
396
397
398
/// ask the kth translator to translate a string in a row of the database
399
template
<
template
<
typename
>
class
ALLOC
>
400
template
<
template
<
typename
>
class
OTHER_ALLOC
>
401
INLINE
DBTranslatedValue
DBTranslatorSet
<
ALLOC
>::
translateSafe
(
402
const
std
::
vector
<
std
::
string
,
OTHER_ALLOC
<
std
::
string
> >&
row
,
403
const
std
::
size_t
k
)
const
{
404
if
(
_translators_
.
size
() <=
k
)
405
GUM_ERROR
(
UndefinedElement
,
"Translator #"
<<
k
<<
" could not be found"
)
406
407
return
_translators_
[
k
]->
translate
(
row
[
_columns_
[
k
]]);
408
}
409
410
411
/// returns the original string that was translated into translated_val
412
template
<
template
<
typename
>
class
ALLOC
>
413
INLINE
std
::
string
414
DBTranslatorSet
<
ALLOC
>::
translateBack
(
const
DBTranslatedValue
translated_val
,
415
const
std
::
size_t
k
)
const
{
416
return
_translators_
[
k
]->
translateBack
(
translated_val
);
417
}
418
419
420
/// returns the original string that was translated into translated_val
421
template
<
template
<
typename
>
class
ALLOC
>
422
INLINE
std
::
string
423
DBTranslatorSet
<
ALLOC
>::
translateBackSafe
(
const
DBTranslatedValue
translated_val
,
424
const
std
::
size_t
k
)
const
{
425
if
(
_translators_
.
size
() <=
k
)
426
GUM_ERROR
(
UndefinedElement
,
"Translator #"
<<
k
<<
"could not be found"
)
427
428
return
_translators_
[
k
]->
translateBack
(
translated_val
);
429
}
430
431
432
// indicates whether the kth translator considers a translated_val
433
// as a missing value
434
template
<
template
<
typename
>
class
ALLOC
>
435
INLINE
bool
DBTranslatorSet
<
ALLOC
>::
isMissingValue
(
const
DBTranslatedValue
translated_val
,
436
const
std
::
size_t
k
)
const
{
437
return
_translators_
[
k
]->
isMissingValue
(
translated_val
);
438
}
439
440
441
// indicates whether the kth translator considers a translated_val
442
// as a missing value
443
template
<
template
<
typename
>
class
ALLOC
>
444
INLINE
bool
DBTranslatorSet
<
ALLOC
>::
isMissingValueSafe
(
const
DBTranslatedValue
translated_val
,
445
const
std
::
size_t
k
)
const
{
446
if
(
_translators_
.
size
() <=
k
)
447
GUM_ERROR
(
UndefinedElement
,
"Translator #"
<<
k
<<
"could not be found"
)
448
449
return
_translators_
[
k
]->
isMissingValue
(
translated_val
);
450
}
451
452
453
/// returns the kth translator
454
template
<
template
<
typename
>
class
ALLOC
>
455
INLINE
DBTranslator
<
ALLOC
>&
DBTranslatorSet
<
ALLOC
>::
translator
(
const
std
::
size_t
k
) {
456
return
*(
_translators_
[
k
]);
457
}
458
459
460
/// returns the kth translator
461
template
<
template
<
typename
>
class
ALLOC
>
462
INLINE
const
DBTranslator
<
ALLOC
>&
463
DBTranslatorSet
<
ALLOC
>::
translator
(
const
std
::
size_t
k
)
const
{
464
return
*(
_translators_
[
k
]);
465
}
466
467
468
/// returns the kth translator
469
template
<
template
<
typename
>
class
ALLOC
>
470
INLINE
DBTranslator
<
ALLOC
>&
DBTranslatorSet
<
ALLOC
>::
translatorSafe
(
const
std
::
size_t
k
) {
471
if
(
_translators_
.
size
() <=
k
)
472
GUM_ERROR
(
UndefinedElement
,
"Translator #"
<<
k
<<
"could not be found"
)
473
474
return
*(
_translators_
[
k
]);
475
}
476
477
478
/// returns the kth translator
479
template
<
template
<
typename
>
class
ALLOC
>
480
INLINE
const
DBTranslator
<
ALLOC
>&
481
DBTranslatorSet
<
ALLOC
>::
translatorSafe
(
const
std
::
size_t
k
)
const
{
482
if
(
_translators_
.
size
() <=
k
)
483
GUM_ERROR
(
UndefinedElement
,
"Translator #"
<<
k
<<
"could not be found"
)
484
485
return
*(
_translators_
[
k
]);
486
}
487
488
489
/// returns the domain size of the variables stored into the kth translator
490
template
<
template
<
typename
>
class
ALLOC
>
491
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
domainSize
(
const
std
::
size_t
k
)
const
{
492
return
_translators_
[
k
]->
domainSize
();
493
}
494
495
496
/// returns the domain size of the variables stored into the kth translator
497
template
<
template
<
typename
>
class
ALLOC
>
498
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
domainSizeSafe
(
const
std
::
size_t
k
)
const
{
499
if
(
_translators_
.
size
() <=
k
)
500
GUM_ERROR
(
UndefinedElement
,
"Variable #"
<<
k
<<
"could not be found"
)
501
502
return
_translators_
[
k
]->
domainSize
();
503
}
504
505
506
/// returns the variable stored into the kth translator
507
template
<
template
<
typename
>
class
ALLOC
>
508
INLINE
const
Variable
&
DBTranslatorSet
<
ALLOC
>::
variable
(
const
std
::
size_t
k
)
const
{
509
return
*(
_translators_
[
k
]->
variable
());
510
}
511
512
513
/// returns the variable stored into the kth translator
514
template
<
template
<
typename
>
class
ALLOC
>
515
INLINE
const
Variable
&
DBTranslatorSet
<
ALLOC
>::
variableSafe
(
const
std
::
size_t
k
)
const
{
516
if
(
_translators_
.
size
() <=
k
)
517
GUM_ERROR
(
UndefinedElement
,
"Variable #"
<<
k
<<
"could not be found"
)
518
519
return
*(
_translators_
[
k
]->
variable
());
520
}
521
522
523
// indicates whether a reordering is needed to make the kth translator
524
// sorted by lexicographical order
525
template
<
template
<
typename
>
class
ALLOC
>
526
INLINE
bool
DBTranslatorSet
<
ALLOC
>::
needsReordering
(
const
std
::
size_t
k
)
const
{
527
return
_translators_
[
k
]->
needsReordering
();
528
}
529
530
531
// indicates whether a reordering is needed to make the kth translator
532
// sorted by lexicographical order
533
template
<
template
<
typename
>
class
ALLOC
>
534
INLINE
bool
DBTranslatorSet
<
ALLOC
>::
needsReorderingSafe
(
const
std
::
size_t
k
)
const
{
535
if
(
_translators_
.
size
() <=
k
)
536
GUM_ERROR
(
UndefinedElement
,
"Variable #"
<<
k
<<
"could not be found"
)
537
538
return
_translators_
[
k
]->
needsReordering
();
539
}
540
541
542
// performs a reordering of the dictionary and returns a mapping
543
// from the old translated values to the new ones.
544
template
<
template
<
typename
>
class
ALLOC
>
545
INLINE
HashTable
<
std
::
size_t
,
std
::
size_t
,
ALLOC
<
std
::
pair
<
std
::
size_t
,
std
::
size_t
> > >
546
DBTranslatorSet
<
ALLOC
>::
reorder
(
const
std
::
size_t
k
) {
547
return
_translators_
[
k
]->
reorder
();
548
}
549
550
551
// performs a reordering of the dictionary and returns a mapping
552
// from the old translated values to the new ones.
553
template
<
template
<
typename
>
class
ALLOC
>
554
INLINE
HashTable
<
std
::
size_t
,
std
::
size_t
,
ALLOC
<
std
::
pair
<
std
::
size_t
,
std
::
size_t
> > >
555
DBTranslatorSet
<
ALLOC
>::
reorderSafe
(
const
std
::
size_t
k
) {
556
if
(
_translators_
.
size
() <=
k
)
557
GUM_ERROR
(
UndefinedElement
,
"Variable #"
<<
k
<<
"could not be found"
)
558
559
return
_translators_
[
k
]->
reorder
();
560
}
561
562
563
/** @brief returns the column of the input database that will be written
564
* in the kth column of the DatabaseTable */
565
template
<
template
<
typename
>
class
ALLOC
>
566
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
inputColumn
(
const
std
::
size_t
k
)
const
{
567
return
_columns_
[
k
];
568
}
569
570
571
/** @brief returns the column of the input database that will be written
572
* in the kth column of the DatabaseTable */
573
template
<
template
<
typename
>
class
ALLOC
>
574
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
inputColumnSafe
(
const
std
::
size_t
k
)
const
{
575
if
(
_translators_
.
size
() <=
k
)
576
GUM_ERROR
(
UndefinedElement
,
"Column #"
<<
k
<<
"could not be found"
)
577
578
return
_columns_
[
k
];
579
}
580
581
582
/// returns the largest input database column index read by the translators
583
template
<
template
<
typename
>
class
ALLOC
>
584
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
highestInputColumn
()
const
{
585
return
_highest_column_
;
586
}
587
588
589
/// returns the number of translators stored into the set
590
template
<
template
<
typename
>
class
ALLOC
>
591
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
nbTranslators
()
const
{
592
return
_columns_
.
size
();
593
}
594
595
596
/// returns the number of translators stored into the set
597
template
<
template
<
typename
>
class
ALLOC
>
598
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
size
()
const
{
599
return
_columns_
.
size
();
600
}
601
602
/// returns the set of translators
603
template
<
template
<
typename
>
class
ALLOC
>
604
INLINE
const
std
::
vector
<
DBTranslator
<
ALLOC
>*,
ALLOC
<
DBTranslator
<
ALLOC
>* > >&
605
DBTranslatorSet
<
ALLOC
>::
translators
()
const
{
606
return
_translators_
;
607
}
608
609
}
/* namespace learning */
610
611
}
/* namespace gum */
612
613
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:643
gum::learning::genericBNLearner::Database::Database
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
Definition:
genericBNLearner_tpl.h:31