LAL: Linear Arrangement Library 21.07.01
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
treebank_reader.hpp
1/*********************************************************************
2 *
3 * Linear Arrangement Library - A library that implements a collection
4 * algorithms for linear arrangments of graphs.
5 *
6 * Copyright (C) 2019 - 2021
7 *
8 * This file is part of Linear Arrangement Library. To see the full code
9 * visit the webpage:
10 * https://github.com/lluisalemanypuig/linear-arrangement-library.git
11 *
12 * Linear Arrangement Library is free software: you can redistribute it
13 * and/or modify it under the terms of the GNU Affero General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * Linear Arrangement Library is distributed in the hope that it will be
18 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
21 *
22 * You should have received a copy of the GNU Affero General Public License
23 * along with Linear Arrangement Library. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * Contact:
26 *
27 * LluĂ­s Alemany Puig (lalemany@cs.upc.edu)
28 * LARCA (Laboratory for Relational Algorithmics, Complexity and Learning)
29 * CQL (Complexity and Quantitative Linguistics Lab)
30 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
31 * Webpage: https://cqllab.upc.edu/people/lalemany/
32 *
33 * Ramon Ferrer i Cancho (rferrericancho@cs.upc.edu)
34 * LARCA (Laboratory for Relational Algorithmics, Complexity and Learning)
35 * CQL (Complexity and Quantitative Linguistics Lab)
36 * Office S124, Omega building
37 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
38 * Webpage: https://cqllab.upc.edu/people/rferrericancho/
39 *
40 ********************************************************************/
41
42#pragma once
43
44// C++ includes
45#include <fstream>
46#include <string>
47#include <vector>
48
49// lal includes
50#include <lal/definitions.hpp>
51#include <lal/graphs/rooted_tree.hpp>
52#include <lal/io/treebank_error.hpp>
53
54namespace lal {
55namespace io {
56
114public:
115 // MODIFIERS
116
128 (const std::string& file, const std::string& identifier = "") noexcept;
129
131 inline bool end() const noexcept { return m_no_more_trees; }
132
137 void next_tree() noexcept;
138
139 /* GETTERS */
140
147 inline size_t get_num_trees() const noexcept
148 { return m_num_trees; }
149
151 inline const std::string& get_identifier() const noexcept
152 { return m_treebank_identifier; }
153
155 inline const std::string& get_treebank_filename() const noexcept
156 { return m_treebank_file; }
157
160
162 inline head_vector get_head_vector() const noexcept
163 { return m_current_head_vector; }
164
172 inline bool is_open() const noexcept { return m_treebank.is_open(); }
173
174 /* SETTERS */
175
180 inline void set_normalise(bool v) noexcept
181 { m_normalise_tree = v; }
182
187 inline void set_calculate_size_subtrees(bool v) noexcept
189
196 inline void set_calculate_tree_type(bool v) noexcept
197 { m_calculate_tree_type = v; }
198
207 inline void set_identifier(const std::string& id) noexcept
208 { m_treebank_identifier = id; }
209
210private:
212 std::string m_treebank_identifier = "none";
214 std::string m_treebank_file = "none";
216 std::ifstream m_treebank;
217
219 size_t m_num_trees = 0;
221 std::string m_file_line;
224
226 bool m_normalise_tree = true;
232 bool m_no_more_trees = false;
233};
234
235} // -- namespace io
236} // -- namespace lal
Rooted tree graph class.
Definition rooted_tree.hpp:107
Treebank error report class.
Definition treebank_error.hpp:64
A reader for a single treebank file.
Definition treebank_reader.hpp:113
std::string m_treebank_file
Treebank's file name (with the full path).
Definition treebank_reader.hpp:214
bool is_open() const noexcept
Can the treebank be read?
Definition treebank_reader.hpp:172
bool m_calculate_tree_type
Calculate the type of tree of the generated tree.
Definition treebank_reader.hpp:230
size_t m_num_trees
Number of trees in the treebank.
Definition treebank_reader.hpp:219
std::string m_file_line
Current line.
Definition treebank_reader.hpp:221
void set_calculate_tree_type(bool v) noexcept
Should the tree be classified into types?
Definition treebank_reader.hpp:196
bool end() const noexcept
Returns whether there is another tree to be processed.
Definition treebank_reader.hpp:131
void next_tree() noexcept
Retrieves the next tree in the file.
head_vector get_head_vector() const noexcept
Returns the current head vector.
Definition treebank_reader.hpp:162
bool m_no_more_trees
Have all trees in the file been consumed?
Definition treebank_reader.hpp:232
void set_normalise(bool v) noexcept
Should trees be normalised?
Definition treebank_reader.hpp:180
const std::string & get_treebank_filename() const noexcept
Returns the name of the treebank file.
Definition treebank_reader.hpp:155
void set_calculate_size_subtrees(bool v) noexcept
Should the size of the subtrees be calculated?
Definition treebank_reader.hpp:187
treebank_error init(const std::string &file, const std::string &identifier="") noexcept
Initialises the treebank reader.
head_vector m_current_head_vector
Current head vector.
Definition treebank_reader.hpp:223
void set_identifier(const std::string &id) noexcept
Set this treebank's identifier string.
Definition treebank_reader.hpp:207
const std::string & get_identifier() const noexcept
Returns the identifier corresponding of the treebank.
Definition treebank_reader.hpp:151
std::string m_treebank_identifier
Identifier for the treebank.
Definition treebank_reader.hpp:212
size_t get_num_trees() const noexcept
Returns the number of trees processed so far.
Definition treebank_reader.hpp:147
bool m_calculate_size_subtrees
Calculate the size of the subtrees of the generated rooted tree.
Definition treebank_reader.hpp:228
graphs::rooted_tree get_tree() const noexcept
Returns the current tree.
std::ifstream m_treebank
Handler for main file reading.
Definition treebank_reader.hpp:216
bool m_normalise_tree
Normalise the current tree.
Definition treebank_reader.hpp:226
Main namespace of the library.
Definition definitions.hpp:48
std::vector< uint32_t > head_vector
A head vector representation of a (usually) rooted tree.
Definition definitions.hpp:114