aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
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-2025 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-2025 *
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
61
62namespace gum {
63
64 namespace learning {
65
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
178
181
183 virtual DBInitializerFromCSV* clone() const;
184
187
189
190
191 // ##########################################################################
193 // ##########################################################################
194
196
198
201
203
206
208
209
210 protected:
212 virtual std::vector< std::string > variableNames_() final;
213
215 virtual const std::vector< std::string >& currentStringRow_() final;
216
218 virtual 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
258#endif /* GUM_NO_INLINE */
259
260#endif /* GUM_LEARNING_DB_INITILIALIZER_FROM_CSV_H */
Class for fast parsing of CSV file (never more than one line in application memory).
The class for initializing DatabaseTables and RawDatabaseTables from CSV files.
The base class for initializing DatabaseTable and RawDatabaseTable instances from CSV files or SQL da...
Class for fast parsing of CSV file (never more than one line in application memory).
Definition CSVParser.h:77
DBInitializerFromCSV(const DBInitializerFromCSV &from)
copy constructor
DBInitializerFromCSV(DBInitializerFromCSV &&from)
move constructor
virtual std::vector< std::string > variableNames_() final
returns the names of the variables
virtual bool nextRow_() final
indicates whether there is a next row to read (and point on it)
DBInitializerFromCSV(const std::string filename, bool fileContainsNames=true, const std::string delimiter=",", const char commentmarker='#', const char quoteMarker='"')
default constructor
virtual const std::vector< std::string > & currentStringRow_() final
returns the content of the current row using strings
virtual ~DBInitializerFromCSV()
destructor
DBInitializerFromCSV & operator=(DBInitializerFromCSV &&from)
move operator
DBInitializerFromCSV & operator=(const DBInitializerFromCSV &from)
copy operator
virtual DBInitializerFromCSV * clone() const
virtual copy constructor
IDBInitializer(const InputType type)
default constructor
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.