CoNLL-U
Loading...
Searching...
No Matches
tg::conllu::Treebank Class Referencefinal

In-memory representation of a CoNLL-U treebank. More...

#include <treebank.hpp>

Public Member Functions

Constructors
constexpr Treebank () noexcept=default
 Default constructor. Initializes an empty treebank.
constexpr Treebank (const Treebank &) noexcept=delete
 Copy construction is disabled.
constexpr Treebank (Treebank &&other) noexcept=delete
 Move construction is disabled.
Columns
constexpr const std::vector< std::string_view > & columns () const noexcept
 Column names, in declaration order.
constexpr std::size_t num_columns () const noexcept
 Number of columns in the treebank.
constexpr std::optional< std::size_t > get_column_pos (std::string_view name) const noexcept
 Looks up a column's position by name.
constexpr std::optional< std::string_view > get_column_name (std::size_t position) const noexcept
 Looks up a column's name by position.
constexpr std::expected< std::size_t, std::error_code > add_column (std::string_view name) noexcept
 Appends a new column, extending every existing token with an empty field for it.
Sentences
constexpr auto sentences () const noexcept
 View over the sentences, in treebank order.
constexpr std::size_t num_sentences () const noexcept
 Number of sentences in the treebank.
constexpr std::expected< Sentence *, std::error_code > add_sentence (std::string_view sent_id, std::string_view text=std::string_view()) noexcept
 Constructs and appends a new sentence.
constexpr std::optional< Sentence * > get_sentence_by_id (std::string_view sent_id) const noexcept
 Looks up a sentence by its identifier.
constexpr std::error_code remove_sentence (std::string_view sent_id) noexcept
 Removes the sentence with the given identifier.
constexpr std::error_code remove_sentence (const Sentence *sentence) noexcept
 Removes the given sentence.
State
constexpr bool empty () const noexcept
 Whether the treebank contains no sentences.
constexpr void clear () noexcept
 Removes all columns and sentences, resetting the treebank to its default-constructed state.
constexpr std::error_code validate () const noexcept
 Checks the treebank for structural inconsistencies.
Operators
constexpr Treebankoperator= (Treebank &&other) noexcept=delete
 Move assignment is disabled.
constexpr Treebankoperator= (const Treebank &) noexcept=delete
 Copy assignment is disabled.
Destructor
constexpr ~Treebank () noexcept=default
 Destructor.

Detailed Description

In-memory representation of a CoNLL-U treebank.

Member Function Documentation

◆ add_column()

std::expected< std::size_t, std::error_code > tg::conllu::Treebank::add_column ( std::string_view name)
constexprnoexcept

Appends a new column, extending every existing token with an empty field for it.

Parameters
[in]nameName of the column to add.
Returns
Position of the newly added column, or an error_code on failure.

◆ add_sentence()

std::expected< Sentence *, std::error_code > tg::conllu::Treebank::add_sentence ( std::string_view sent_id,
std::string_view text = std::string_view() )
nodiscardconstexprnoexcept

Constructs and appends a new sentence.

Parameters
[in]sent_idUnique identifier for the sentence.
[in]textOptional sentence text (# text metadata).
Returns
Pointer to the newly created sentence, or an error_code on failure.

◆ get_column_name()

std::optional< std::string_view > tg::conllu::Treebank::get_column_name ( std::size_t position) const
nodiscardconstexprnoexcept

Looks up a column's name by position.

Parameters
[in]positionColumn position to search for.
Returns
Column name, or std::nullopt if position is out of range.

◆ get_column_pos()

std::optional< std::size_t > tg::conllu::Treebank::get_column_pos ( std::string_view name) const
nodiscardconstexprnoexcept

Looks up a column's position by name.

Parameters
[in]nameColumn name to search for.
Returns
Position of the column, or std::nullopt if no such column exists.

◆ get_sentence_by_id()

std::optional< Sentence * > tg::conllu::Treebank::get_sentence_by_id ( std::string_view sent_id) const
nodiscardconstexprnoexcept

Looks up a sentence by its identifier.

Parameters
[in]sent_idSentence identifier to search for.
Returns
Pointer to the sentence, or std::nullopt if no such sentence exists.

◆ remove_sentence() [1/2]

std::error_code tg::conllu::Treebank::remove_sentence ( const Sentence * sentence)
constexprnoexcept

Removes the given sentence.

Parameters
[in]sentencePointer to the sentence to remove.
Returns
Empty error_code on success, or an error describing the failure (including if sentence is null or does not belong to this treebank).

◆ remove_sentence() [2/2]

std::error_code tg::conllu::Treebank::remove_sentence ( std::string_view sent_id)
constexprnoexcept

Removes the sentence with the given identifier.

Parameters
[in]sent_idIdentifier of the sentence to remove.
Returns
Empty error_code on success, or an error describing the failure.

◆ sentences()

auto tg::conllu::Treebank::sentences ( ) const
nodiscardconstexprnoexcept

View over the sentences, in treebank order.

Returns
A lazy view yielding a non-owning Sentence* for each sentence in the treebank.

◆ validate()

std::error_code tg::conllu::Treebank::validate ( ) const
nodiscardconstexprnoexcept

Checks the treebank for structural inconsistencies.

Returns
Empty error_code on success, or an error describing the first issue found.

The documentation for this class was generated from the following file: