aGrUM
0.20.3
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
/// inserts a new translator for a given variable in the translator set
247
template
<
template
<
typename
>
class
ALLOC
>
248
template
<
template
<
typename
>
class
XALLOC
>
249
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
insertTranslator
(
250
const
Variable
&
var
,
251
const
std
::
size_t
column
,
252
const
std
::
vector
<
std
::
string
,
XALLOC
<
std
::
string
> >&
missing_symbols
,
253
const
bool
unique_column
) {
254
// create the translatator, depending on the type of the variable
255
switch
(
var
.
varType
()) {
256
case
VarType
::
Labelized
: {
257
const
LabelizedVariable
&
xvar
=
static_cast
<
const
LabelizedVariable
& >(
var
);
258
DBTranslator4LabelizedVariable
<
ALLOC
>
translator
(
xvar
,
missing_symbols
);
259
return
insertTranslator
(
translator
,
column
,
unique_column
);
260
}
261
262
case
VarType
::
Discretized
: {
263
const
IDiscretizedVariable
&
xvar
=
static_cast
<
const
IDiscretizedVariable
& >(
var
);
264
DBTranslator4DiscretizedVariable
<
ALLOC
>
translator
(
xvar
,
missing_symbols
);
265
return
insertTranslator
(
translator
,
column
,
unique_column
);
266
}
267
268
case
VarType
::
Range
: {
269
const
RangeVariable
&
xvar
=
static_cast
<
const
RangeVariable
& >(
var
);
270
DBTranslator4RangeVariable
<
ALLOC
>
translator
(
xvar
,
missing_symbols
);
271
return
insertTranslator
(
translator
,
column
,
unique_column
);
272
}
273
274
case
VarType
::
Continuous
: {
275
const
IContinuousVariable
&
xvar
=
static_cast
<
const
IContinuousVariable
& >(
var
);
276
DBTranslator4ContinuousVariable
<
ALLOC
>
translator
(
xvar
,
missing_symbols
);
277
return
insertTranslator
(
translator
,
column
,
unique_column
);
278
}
279
280
default
:
281
GUM_ERROR
(
NotImplementedYet
,
282
"The insertion of the translator for Variable "
283
<<
var
.
name
()
284
<<
" is impossible because a translator "
285
"for such variable is not implemented yet"
)
286
}
287
}
288
289
290
/// inserts a new translator for a given variable in the translator set
291
template
<
template
<
typename
>
class
ALLOC
>
292
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
insertTranslator
(
const
Variable
&
var
,
293
const
std
::
size_t
column
,
294
const
bool
unique_column
) {
295
const
std
::
vector
<
std
::
string
,
ALLOC
<
std
::
string
> >
missing
;
296
return
this
->
insertTranslator
(
var
,
column
,
missing
,
unique_column
);
297
}
298
299
300
/// erase the kth translator
301
template
<
template
<
typename
>
class
ALLOC
>
302
void
DBTranslatorSet
<
ALLOC
>::
eraseTranslator
(
const
std
::
size_t
k
,
const
bool
k_is_input_col
) {
303
ALLOC
<
DBTranslator
<
ALLOC
> >
allocator
(
this
->
getAllocator
());
304
const
std
::
size_t
nb_trans
=
_translators_
.
size
();
305
306
if
(!
k_is_input_col
) {
307
if
(
nb_trans
<
k
)
return
;
308
309
// remove the translator and its corresponding column
310
allocator
.
destroy
(
_translators_
[
k
]);
311
allocator
.
deallocate
(
_translators_
[
k
], 1);
312
313
const
std
::
size_t
colk
=
_columns_
[
k
];
314
_translators_
.
erase
(
_translators_
.
begin
() +
k
);
315
_columns_
.
erase
(
_columns_
.
begin
() +
k
);
316
317
// if the highest column index corresponded to the kth translator,
318
// we must recomput it
319
if
(
_highest_column_
==
colk
) {
320
_highest_column_
=
std
::
size_t
(0);
321
for
(
const
auto
col
:
_columns_
)
322
if
(
_highest_column_
<
col
)
_highest_column_
=
col
;
323
}
324
}
else
{
325
// remove all the translators parsing the kth column
326
auto
iter_trans
=
_translators_
.
rbegin
();
327
bool
translator_found
=
false
;
328
for
(
auto
iter_col
=
_columns_
.
rbegin
();
iter_col
!=
_columns_
.
rend
();
329
++
iter_col
, ++
iter_trans
) {
330
if
(*
iter_col
==
k
) {
331
// remove the translator and its corresponding column
332
allocator
.
destroy
(*
iter_trans
);
333
allocator
.
deallocate
(*
iter_trans
, 1);
334
335
_translators_
.
erase
((
iter_trans
+ 1).
base
());
336
_columns_
.
erase
((
iter_col
+ 1).
base
());
337
translator_found
=
true
;
338
}
339
}
340
341
// if the highest column index corresponded to one of the translators
342
// removed, we must recompute it
343
if
(
translator_found
&& (
k
==
_highest_column_
)) {
344
_highest_column_
=
std
::
size_t
(0);
345
for
(
const
auto
col
:
_columns_
)
346
if
(
_highest_column_
<
col
)
_highest_column_
=
col
;
347
}
348
}
349
}
350
351
352
/// ask the kth translator to translate a string in a row of the database
353
template
<
template
<
typename
>
class
ALLOC
>
354
template
<
template
<
typename
>
class
OTHER_ALLOC
>
355
INLINE
DBTranslatedValue
DBTranslatorSet
<
ALLOC
>::
translate
(
356
const
std
::
vector
<
std
::
string
,
OTHER_ALLOC
<
std
::
string
> >&
row
,
357
const
std
::
size_t
k
)
const
{
358
return
_translators_
[
k
]->
translate
(
row
[
_columns_
[
k
]]);
359
}
360
361
362
/// ask the kth translator to translate a string in a row of the database
363
template
<
template
<
typename
>
class
ALLOC
>
364
template
<
template
<
typename
>
class
OTHER_ALLOC
>
365
INLINE
DBTranslatedValue
DBTranslatorSet
<
ALLOC
>::
translateSafe
(
366
const
std
::
vector
<
std
::
string
,
OTHER_ALLOC
<
std
::
string
> >&
row
,
367
const
std
::
size_t
k
)
const
{
368
if
(
_translators_
.
size
() <=
k
)
369
GUM_ERROR
(
UndefinedElement
,
"Translator #"
<<
k
<<
" could not be found"
)
370
371
return
_translators_
[
k
]->
translate
(
row
[
_columns_
[
k
]]);
372
}
373
374
375
/// returns the original string that was translated into translated_val
376
template
<
template
<
typename
>
class
ALLOC
>
377
INLINE
std
::
string
378
DBTranslatorSet
<
ALLOC
>::
translateBack
(
const
DBTranslatedValue
translated_val
,
379
const
std
::
size_t
k
)
const
{
380
return
_translators_
[
k
]->
translateBack
(
translated_val
);
381
}
382
383
384
/// returns the original string that was translated into translated_val
385
template
<
template
<
typename
>
class
ALLOC
>
386
INLINE
std
::
string
387
DBTranslatorSet
<
ALLOC
>::
translateBackSafe
(
const
DBTranslatedValue
translated_val
,
388
const
std
::
size_t
k
)
const
{
389
if
(
_translators_
.
size
() <=
k
)
390
GUM_ERROR
(
UndefinedElement
,
"Translator #"
<<
k
<<
"could not be found"
)
391
392
return
_translators_
[
k
]->
translateBack
(
translated_val
);
393
}
394
395
396
// indicates whether the kth translator considers a translated_val
397
// as a missing value
398
template
<
template
<
typename
>
class
ALLOC
>
399
INLINE
bool
DBTranslatorSet
<
ALLOC
>::
isMissingValue
(
const
DBTranslatedValue
translated_val
,
400
const
std
::
size_t
k
)
const
{
401
return
_translators_
[
k
]->
isMissingValue
(
translated_val
);
402
}
403
404
405
// indicates whether the kth translator considers a translated_val
406
// as a missing value
407
template
<
template
<
typename
>
class
ALLOC
>
408
INLINE
bool
DBTranslatorSet
<
ALLOC
>::
isMissingValueSafe
(
const
DBTranslatedValue
translated_val
,
409
const
std
::
size_t
k
)
const
{
410
if
(
_translators_
.
size
() <=
k
)
411
GUM_ERROR
(
UndefinedElement
,
"Translator #"
<<
k
<<
"could not be found"
)
412
413
return
_translators_
[
k
]->
isMissingValue
(
translated_val
);
414
}
415
416
417
/// returns the kth translator
418
template
<
template
<
typename
>
class
ALLOC
>
419
INLINE
DBTranslator
<
ALLOC
>&
DBTranslatorSet
<
ALLOC
>::
translator
(
const
std
::
size_t
k
) {
420
return
*(
_translators_
[
k
]);
421
}
422
423
424
/// returns the kth translator
425
template
<
template
<
typename
>
class
ALLOC
>
426
INLINE
const
DBTranslator
<
ALLOC
>&
427
DBTranslatorSet
<
ALLOC
>::
translator
(
const
std
::
size_t
k
)
const
{
428
return
*(
_translators_
[
k
]);
429
}
430
431
432
/// returns the kth translator
433
template
<
template
<
typename
>
class
ALLOC
>
434
INLINE
DBTranslator
<
ALLOC
>&
DBTranslatorSet
<
ALLOC
>::
translatorSafe
(
const
std
::
size_t
k
) {
435
if
(
_translators_
.
size
() <=
k
)
436
GUM_ERROR
(
UndefinedElement
,
"Translator #"
<<
k
<<
"could not be found"
)
437
438
return
*(
_translators_
[
k
]);
439
}
440
441
442
/// returns the kth translator
443
template
<
template
<
typename
>
class
ALLOC
>
444
INLINE
const
DBTranslator
<
ALLOC
>&
445
DBTranslatorSet
<
ALLOC
>::
translatorSafe
(
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
]);
450
}
451
452
453
/// returns the domain size of the variables stored into the kth translator
454
template
<
template
<
typename
>
class
ALLOC
>
455
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
domainSize
(
const
std
::
size_t
k
)
const
{
456
return
_translators_
[
k
]->
domainSize
();
457
}
458
459
460
/// returns the domain size of the variables stored into the kth translator
461
template
<
template
<
typename
>
class
ALLOC
>
462
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
domainSizeSafe
(
const
std
::
size_t
k
)
const
{
463
if
(
_translators_
.
size
() <=
k
)
464
GUM_ERROR
(
UndefinedElement
,
"Variable #"
<<
k
<<
"could not be found"
)
465
466
return
_translators_
[
k
]->
domainSize
();
467
}
468
469
470
/// returns the variable stored into the kth translator
471
template
<
template
<
typename
>
class
ALLOC
>
472
INLINE
const
Variable
&
DBTranslatorSet
<
ALLOC
>::
variable
(
const
std
::
size_t
k
)
const
{
473
return
*(
_translators_
[
k
]->
variable
());
474
}
475
476
477
/// returns the variable stored into the kth translator
478
template
<
template
<
typename
>
class
ALLOC
>
479
INLINE
const
Variable
&
DBTranslatorSet
<
ALLOC
>::
variableSafe
(
const
std
::
size_t
k
)
const
{
480
if
(
_translators_
.
size
() <=
k
)
481
GUM_ERROR
(
UndefinedElement
,
"Variable #"
<<
k
<<
"could not be found"
)
482
483
return
*(
_translators_
[
k
]->
variable
());
484
}
485
486
487
// indicates whether a reordering is needed to make the kth translator
488
// sorted by lexicographical order
489
template
<
template
<
typename
>
class
ALLOC
>
490
INLINE
bool
DBTranslatorSet
<
ALLOC
>::
needsReordering
(
const
std
::
size_t
k
)
const
{
491
return
_translators_
[
k
]->
needsReordering
();
492
}
493
494
495
// indicates whether a reordering is needed to make the kth translator
496
// sorted by lexicographical order
497
template
<
template
<
typename
>
class
ALLOC
>
498
INLINE
bool
DBTranslatorSet
<
ALLOC
>::
needsReorderingSafe
(
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
]->
needsReordering
();
503
}
504
505
506
// performs a reordering of the dictionary and returns a mapping
507
// from the old translated values to the new ones.
508
template
<
template
<
typename
>
class
ALLOC
>
509
INLINE
HashTable
<
std
::
size_t
,
std
::
size_t
,
ALLOC
<
std
::
pair
<
std
::
size_t
,
std
::
size_t
> > >
510
DBTranslatorSet
<
ALLOC
>::
reorder
(
const
std
::
size_t
k
) {
511
return
_translators_
[
k
]->
reorder
();
512
}
513
514
515
// performs a reordering of the dictionary and returns a mapping
516
// from the old translated values to the new ones.
517
template
<
template
<
typename
>
class
ALLOC
>
518
INLINE
HashTable
<
std
::
size_t
,
std
::
size_t
,
ALLOC
<
std
::
pair
<
std
::
size_t
,
std
::
size_t
> > >
519
DBTranslatorSet
<
ALLOC
>::
reorderSafe
(
const
std
::
size_t
k
) {
520
if
(
_translators_
.
size
() <=
k
)
521
GUM_ERROR
(
UndefinedElement
,
"Variable #"
<<
k
<<
"could not be found"
)
522
523
return
_translators_
[
k
]->
reorder
();
524
}
525
526
527
/** @brief returns the column of the input database that will be written
528
* in the kth column of the DatabaseTable */
529
template
<
template
<
typename
>
class
ALLOC
>
530
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
inputColumn
(
const
std
::
size_t
k
)
const
{
531
return
_columns_
[
k
];
532
}
533
534
535
/** @brief returns the column of the input database that will be written
536
* in the kth column of the DatabaseTable */
537
template
<
template
<
typename
>
class
ALLOC
>
538
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
inputColumnSafe
(
const
std
::
size_t
k
)
const
{
539
if
(
_translators_
.
size
() <=
k
)
540
GUM_ERROR
(
UndefinedElement
,
"Column #"
<<
k
<<
"could not be found"
)
541
542
return
_columns_
[
k
];
543
}
544
545
546
/// returns the largest input database column index read by the translators
547
template
<
template
<
typename
>
class
ALLOC
>
548
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
highestInputColumn
()
const
{
549
return
_highest_column_
;
550
}
551
552
553
/// returns the number of translators stored into the set
554
template
<
template
<
typename
>
class
ALLOC
>
555
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
nbTranslators
()
const
{
556
return
_columns_
.
size
();
557
}
558
559
560
/// returns the number of translators stored into the set
561
template
<
template
<
typename
>
class
ALLOC
>
562
INLINE
std
::
size_t
DBTranslatorSet
<
ALLOC
>::
size
()
const
{
563
return
_columns_
.
size
();
564
}
565
566
/// returns the set of translators
567
template
<
template
<
typename
>
class
ALLOC
>
568
INLINE
const
std
::
vector
<
DBTranslator
<
ALLOC
>*,
ALLOC
<
DBTranslator
<
ALLOC
>* > >&
569
DBTranslatorSet
<
ALLOC
>::
translators
()
const
{
570
return
_translators_
;
571
}
572
573
}
/* namespace learning */
574
575
}
/* namespace gum */
576
577
#
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