CoNLL-U
Loading...
Searching...
No Matches
writer.hpp
1/*
2 * CoNLL-U - https://github.com/tugrulgungor/CoNLL-U
3 *
4 * Copyright (c) 2026. All rights reserved.
5 * Tuğrul Güngör - https://conll-u.tugrulgungor.me
6 *
7 * Distributed under the MIT License.
8 * https://opensource.org/license/mit/
9 */
10
14
15#ifndef TG_CONLLU_WRITER_HPP
16#define TG_CONLLU_WRITER_HPP 1
17
18#include "conllu/treebank.hpp"
19
20#include <filesystem>
21#include <ostream>
22
23namespace tg::conllu {
29 struct WriterOptions final {
34 };
35
41 class Writer final {
42 WriterOptions options_{};
43
44 [[nodiscard]] static std::error_code write_columns_(std::ostream &output, const Treebank *treebank) noexcept;
45 [[nodiscard]] std::error_code write_sentence_(std::ostream &output, const Sentence *sentence) const noexcept;
46 [[nodiscard]] static std::error_code write_token_(std::ostream &output, const Token *token) noexcept;
47 [[nodiscard]] std::error_code write_word_(std::ostream &output, const Word *word) const noexcept;
48
49 static std::ostream &write_(std::ostream &output) noexcept(false);
50
51 public:
59 constexpr Writer() noexcept = default;
64 explicit(true) constexpr Writer(WriterOptions options) noexcept;
76 [[nodiscard]] std::error_code write(const Treebank *treebank, std::ostream &&stream) const noexcept;
84 [[nodiscard]] std::error_code write_file(const Treebank *treebank,
85 const std::filesystem::path &path) const noexcept;
94 constexpr ~Writer() noexcept = default;
96 };
97} // namespace tg::conllu
98
99#include "conllu/impl/writer.ipp"
100
101#endif // TG_CONLLU_WRITER_HPP
A single sentence within a Treebank.
Definition sentence.hpp:35
A single token within a Sentence, or an empty node within a Token.
Definition token.hpp:43
In-memory representation of a CoNLL-U treebank.
Definition treebank.hpp:36
A multiword token: a contiguous span of two or more Tokens sharing a single surface form.
Definition word.hpp:28
constexpr Writer() noexcept=default
Default constructor. Initializes a writer with default options.
std::error_code write(const Treebank *treebank, std::ostream &&stream) const noexcept
Writes a treebank in CoNLL-U format to a stream.
std::error_code write_file(const Treebank *treebank, const std::filesystem::path &path) const noexcept
Serializes treebank in CoNLL-U format and writes it to the file at path.
Configuration options controlling how a Writer serializes a Treebank.
Definition writer.hpp:29
char empty_value_indicator
Character used to represent an empty field value (default: _).
Definition writer.hpp:33