LAL: Linear Arrangement Library 24.10.00
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 - 2024
7 *
8 * This file is part of Linear Arrangement Library. The full code is available
9 * at:
10 * https://github.com/LAL-project/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 (lluis.alemany.puig@upc.edu)
28 * LQMC (Quantitative, Mathematical, and Computational Linguisitcs)
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 * LQMC (Quantitative, Mathematical, and Computational Linguisitcs)
35 * CQL (Complexity and Quantitative Linguistics Lab)
36 * Office 220, 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
48// lal includes
49#include <lal/basic_types.hpp>
50#include <lal/graphs/rooted_tree.hpp>
51#include <lal/io/treebank_file_error.hpp>
52
53namespace lal {
54namespace io {
55
90public:
91 // MODIFIERS
92
104 (const std::string& treebank_filename, const std::string& treebank_id = "")
105 noexcept;
106
108 [[nodiscard]] bool end() const noexcept { return m_no_more_trees; }
109
114 void next_tree() noexcept;
115
116 /* GETTERS */
117
124 [[nodiscard]] std::size_t get_num_trees() const noexcept
125 { return m_num_trees; }
126
128 [[nodiscard]] const std::string& get_treebank_identifier() const noexcept
129 { return m_treebank_identifier; }
130
132 [[nodiscard]] const std::string& get_treebank_filename() const noexcept
133 { return m_treebank_file; }
134
136 [[nodiscard]] graphs::rooted_tree get_tree() const noexcept;
137
139 [[nodiscard]] head_vector get_head_vector() const noexcept
140 { return m_current_head_vector; }
141
149 [[nodiscard]] bool is_open() const noexcept { return m_treebank.is_open(); }
150
151 /* SETTERS */
152
157 void set_normalize(const bool v) noexcept {
159 }
160
165 void set_calculate_size_subtrees(const bool v) noexcept {
167 }
168
175 void set_calculate_tree_type(const bool v) noexcept {
177 }
178
187 void set_identifier(const std::string& id) noexcept
188 { m_treebank_identifier = id; }
189
190private:
192 std::string m_treebank_identifier = "none";
194 std::string m_treebank_file = "none";
196 std::ifstream m_treebank;
197
199 std::size_t m_num_trees = 0;
201 std::string m_current_line;
204
206 bool m_normalize_tree = true;
212 bool m_no_more_trees = false;
213};
214
215} // -- namespace io
216} // -- namespace lal
Rooted tree graph class.
Definition rooted_tree.hpp:109
Treebank file error report class.
Definition treebank_file_error.hpp:64
A reader for a single treebank file.
Definition treebank_reader.hpp:89
std::string m_treebank_file
Treebank's file name (with the full path).
Definition treebank_reader.hpp:194
bool is_open() const noexcept
Can the treebank be read?
Definition treebank_reader.hpp:149
bool m_calculate_tree_type
Calculate the type of tree of the generated tree.
Definition treebank_reader.hpp:210
bool end() const noexcept
Returns whether there is another tree to be processed.
Definition treebank_reader.hpp:108
void next_tree() noexcept
Retrieves the next tree in the file.
std::size_t get_num_trees() const noexcept
Returns the number of trees processed so far.
Definition treebank_reader.hpp:124
bool m_normalize_tree
Normalize the current tree.
Definition treebank_reader.hpp:206
const std::string & get_treebank_identifier() const noexcept
Returns the identifier corresponding of the treebank.
Definition treebank_reader.hpp:128
std::string m_current_line
Current line.
Definition treebank_reader.hpp:201
head_vector get_head_vector() const noexcept
Returns the current head vector.
Definition treebank_reader.hpp:139
bool m_no_more_trees
Have all trees in the file been consumed?
Definition treebank_reader.hpp:212
const std::string & get_treebank_filename() const noexcept
Returns the name of the treebank file.
Definition treebank_reader.hpp:132
head_vector m_current_head_vector
Current head vector.
Definition treebank_reader.hpp:203
std::size_t m_num_trees
Number of trees in the treebank.
Definition treebank_reader.hpp:199
void set_identifier(const std::string &id) noexcept
Set this treebank's identifier string.
Definition treebank_reader.hpp:187
void set_calculate_size_subtrees(const bool v) noexcept
Should the size of the subtrees be calculated?
Definition treebank_reader.hpp:165
void set_calculate_tree_type(const bool v) noexcept
Should the tree be classified into types?
Definition treebank_reader.hpp:175
treebank_file_error init(const std::string &treebank_filename, const std::string &treebank_id="") noexcept
Initializes the treebank reader.
std::string m_treebank_identifier
Identifier for the treebank.
Definition treebank_reader.hpp:192
void set_normalize(const bool v) noexcept
Should trees be normalized?
Definition treebank_reader.hpp:157
bool m_calculate_size_subtrees
Calculate the size of the subtrees of the generated rooted tree.
Definition treebank_reader.hpp:208
graphs::rooted_tree get_tree() const noexcept
Returns the current tree.
std::ifstream m_treebank
Handler for main file reading.
Definition treebank_reader.hpp:196
Main namespace of the library.
Definition basic_types.hpp:48
std::vector< uint64_t > head_vector
See Head vector page for further details.
Definition basic_types.hpp:58