LAL: Linear Arrangement Library 21.07.01
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
treebank_collection_processor.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#if defined DEBUG
46#include <cassert>
47#endif
48#include <vector>
49#include <string>
50#include <tuple>
51#include <array>
52
53// lal includes
54#include <lal/io/treebank_error.hpp>
55#include <lal/io/process_treebank_base.hpp>
56
57namespace lal {
58namespace io {
59
129public:
130 // SETTERS
131
136 void set_join_files(bool v) noexcept { m_join_files = v; }
137
139 inline void set_number_threads(size_t n_threads) noexcept {
140#if defined DEBUG
141 assert(n_threads != 0);
142#endif
143 m_num_threads = n_threads;
144 }
145
146 // GETTERS
147
149 size_t get_num_errors() const noexcept
150 { return m_errors_from_processing.size(); }
151
157 const treebank_error& get_error_type(size_t i) const noexcept
158 { return std::get<0>(m_errors_from_processing[i]); }
159
166 const std::string& get_error_treebank_filename(size_t i) const noexcept
167 { return std::get<1>(m_errors_from_processing[i]); }
168
175 const std::string& get_error_treebank_name(size_t i) const noexcept
176 { return std::get<2>(m_errors_from_processing[i]); }
177
178 // PROCESS THE TREEBANK COLLECTION
179
190 const std::string& main_file,
191 const std::string& output_directory
192 )
193 noexcept;
194
223 treebank_error process(const std::string& result_filename = "") noexcept;
224
225private:
227 std::vector<std::string> m_all_individual_treebank_names;
228
230 bool m_join_files = true;
231
233 size_t m_num_threads = 1;
234
236 std::vector<std::tuple<treebank_error, std::string, std::string>>
238
239private:
245 treebank_error join_all_files(const std::string& resname) const
246 noexcept;
247
248private:
250 std::string m_out_dir = "none";
252 std::string m_main_file = "none";
253};
254
270inline
272 const std::string& treebank_collection_main_file,
273 const std::string& output_directory,
274 std::size_t num_threads = 1
275)
276noexcept
277{
279 auto err = tbcolproc.init(treebank_collection_main_file, output_directory);
280 tbcolproc.set_number_threads(num_threads);
281 if (err.get_error_type() != treebank_error_type::no_error) {
282 return err;
283 }
284 return tbcolproc.process();
285}
286
287} // -- namespace io
288} // -- namespace lal
The processor base class.
Definition process_treebank_base.hpp:60
Automatic processing of treebank collections.
Definition treebank_collection_processor.hpp:128
void set_join_files(bool v) noexcept
Join the resulting files into a single file.
Definition treebank_collection_processor.hpp:136
treebank_error init(const std::string &main_file, const std::string &output_directory) noexcept
Initialise the processor with a new collection.
bool m_join_files
Join the files into a single file.
Definition treebank_collection_processor.hpp:230
void set_number_threads(size_t n_threads) noexcept
Set the number of threads.
Definition treebank_collection_processor.hpp:139
std::vector< std::tuple< treebank_error, std::string, std::string > > m_errors_from_processing
Set of errors resulting from processing the treebank collection.
Definition treebank_collection_processor.hpp:237
treebank_error join_all_files(const std::string &resname) const noexcept
Joins all resulting files into a single file.
const std::string & get_error_treebank_name(size_t i) const noexcept
Get the treebank's name for where the ith error happened.
Definition treebank_collection_processor.hpp:175
size_t get_num_errors() const noexcept
Returns the number of errors that arised during processing.
Definition treebank_collection_processor.hpp:149
std::vector< std::string > m_all_individual_treebank_names
The list of names of the treebanks.
Definition treebank_collection_processor.hpp:227
treebank_error process(const std::string &result_filename="") noexcept
Process the treebank collection.
std::string m_main_file
File containing the list of languages and their treebanks.
Definition treebank_collection_processor.hpp:252
const treebank_error & get_error_type(size_t i) const noexcept
Get the ith error.
Definition treebank_collection_processor.hpp:157
std::string m_out_dir
Output directory.
Definition treebank_collection_processor.hpp:250
const std::string & get_error_treebank_filename(size_t i) const noexcept
Get the treebank's file name where the ith error happened.
Definition treebank_collection_processor.hpp:166
size_t m_num_threads
Number of threads to use.
Definition treebank_collection_processor.hpp:233
Treebank error report class.
Definition treebank_error.hpp:64
@ no_error
No error occurred.
treebank_error process_treebank_collection(const std::string &treebank_collection_main_file, const std::string &output_directory, std::size_t num_threads=1) noexcept
Automatically process a treebank collection.
Definition treebank_collection_processor.hpp:271
Main namespace of the library.
Definition definitions.hpp:48