aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
DBInitializerFromCSV.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
48
#ifndef GUM_LEARNING_DB_INITILIALIZER_FROM_CSV_H
49
#define GUM_LEARNING_DB_INITILIALIZER_FROM_CSV_H
50
51
#include <fstream>
52
#include <iostream>
53
#include <sstream>
54
#include <string>
55
#include <vector>
56
57
#include <
agrum/agrum.h
>
58
59
#include <
agrum/base/database/CSVParser.h
>
60
#include <
agrum/base/database/IDBInitializer.h
>
61
62
namespace
gum
{
63
64
namespace
learning
{
65
151
class
GUM_SHARED_PUBLIC
DBInitializerFromCSV
:
public
IDBInitializer
{
152
public
:
153
// ##########################################################################
155
// ##########################################################################
157
159
168
DBInitializerFromCSV
(
const
std::string filename,
169
bool
fileContainsNames =
true
,
170
const
std::string delimiter =
","
,
171
const
char
commentmarker =
'#'
,
172
const
char
quoteMarker =
'"'
);
173
175
177
DBInitializerFromCSV
(
const
DBInitializerFromCSV
& from);
178
180
DBInitializerFromCSV
(
DBInitializerFromCSV
&& from);
181
183
[[nodiscard]]
DBInitializerFromCSV
*
clone
()
const override
;
184
186
~DBInitializerFromCSV
()
override
;
187
189
190
191
// ##########################################################################
193
// ##########################################################################
194
196
198
200
DBInitializerFromCSV
&
operator=
(
const
DBInitializerFromCSV
& from);
201
203
205
DBInitializerFromCSV
&
operator=
(
DBInitializerFromCSV
&& from);
206
208
209
210
protected
:
212
std::vector< std::string >
variableNames_
() final;
213
215
const
std
::vector<
std
::
string
>&
currentStringRow_
() final;
216
218
bool
nextRow_
() final;
219
220
221
#ifndef DOXYGEN_SHOULD_SKIP_THIS
222
223
private
:
224
// the filename used for parsing
225
std::string _filename_;
226
227
// indicates the delimiter used within the CSV
228
std::string _delimiter_;
229
230
// indicates which character is a comment symbol in the CSV
231
char
_comment_marker_;
232
233
// indicates which character is a quote symbol in the CSV
234
char
_quote_marker_;
235
236
// indicates whether the first row of the file contains the names
237
bool
_first_row_has_names_;
238
239
// the input stream read by the parser
240
std::ifstream _input_stream_;
241
242
// the CSV parser used for the reading the CSV file
243
CSVParser
_parser_;
244
245
// the variables names, if the first row has names
246
std::vector< std::string > _var_names_;
247
248
#endif
/* DOXYGEN_SHOULD_SKIP_THIS */
249
};
250
251
}
/* namespace learning */
252
253
}
/* namespace gum */
254
256
#ifndef GUM_NO_INLINE
257
# include <
agrum/base/database/DBInitializerFromCSV_inl.h
>
258
#endif
/* GUM_NO_INLINE */
259
260
#endif
/* GUM_LEARNING_DB_INITILIALIZER_FROM_CSV_H */
CSVParser.h
Class for fast parsing of CSV file (never more than one line in application memory).
DBInitializerFromCSV_inl.h
The class for initializing DatabaseTables and RawDatabaseTables from CSV files.
IDBInitializer.h
The base class for initializing DatabaseTable and RawDatabaseTable instances from CSV files or SQL da...
agrum.h
gum::learning::CSVParser
Class for fast parsing of CSV file (never more than one line in application memory).
Definition
CSVParser.h:78
gum::learning::DBInitializerFromCSV::DBInitializerFromCSV
DBInitializerFromCSV(const DBInitializerFromCSV &from)
copy constructor
gum::learning::DBInitializerFromCSV::DBInitializerFromCSV
DBInitializerFromCSV(DBInitializerFromCSV &&from)
move constructor
gum::learning::DBInitializerFromCSV::currentStringRow_
const std::vector< std::string > & currentStringRow_() final
returns the content of the current row using strings
gum::learning::DBInitializerFromCSV::variableNames_
std::vector< std::string > variableNames_() final
returns the names of the variables
gum::learning::DBInitializerFromCSV::nextRow_
bool nextRow_() final
indicates whether there is a next row to read (and point on it)
gum::learning::DBInitializerFromCSV::~DBInitializerFromCSV
~DBInitializerFromCSV() override
destructor
gum::learning::DBInitializerFromCSV::DBInitializerFromCSV
DBInitializerFromCSV(const std::string filename, bool fileContainsNames=true, const std::string delimiter=",", const char commentmarker='#', const char quoteMarker='"')
default constructor
gum::learning::DBInitializerFromCSV::operator=
DBInitializerFromCSV & operator=(DBInitializerFromCSV &&from)
move operator
gum::learning::DBInitializerFromCSV::clone
DBInitializerFromCSV * clone() const override
virtual copy constructor
gum::learning::DBInitializerFromCSV::operator=
DBInitializerFromCSV & operator=(const DBInitializerFromCSV &from)
copy operator
gum::learning::IDBInitializer::IDBInitializer
IDBInitializer(const InputType type)
default constructor
gum::learning
include the inlined functions if necessary
Definition
CSVParser.h:55
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
std
STL namespace.
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0