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

A multiword token: a contiguous span of two or more Tokens sharing a single surface form. More...

#include <word.hpp>

Classes

struct  Range
 A closed, inclusive interval of Tokens' identifiers, spanning [first, last]. More...

Public Member Functions

Constructors
constexpr Word () noexcept=delete
 Default construction is disabled; words are created via Sentence::add_word.
Range
constexpr std::error_code set_range (Range range) noexcept
 Sets the token range covered by this word.
constexpr std::error_code set_range (TokenId first, TokenId last) noexcept
 Sets the token range covered by this word.
constexpr TokenId first_id () const noexcept
 Identifier of the first token in the word's range.
constexpr TokenId last_id () const noexcept
 Identifier of the last token in the word's range.
Form
constexpr std::optional< std::string_view > get_form () const noexcept
 Word form (surface form of the multiword token).
constexpr std::error_code set_form (const std::optional< std::string_view > &form) noexcept
 Sets the word form.
constexpr void unset_form () noexcept
 Unsets the word form.
Misc
constexpr std::optional< std::string_view > get_misc () const noexcept
 Word-level MISC field.
constexpr std::error_code set_misc (const std::optional< std::string_view > &misc) noexcept
 Sets the word-level MISC field.
constexpr void unset_misc () noexcept
 Unsets the word-level MISC field.
Typo
constexpr std::optional< bool > get_typo () const noexcept
 Whether the word is flagged as a typo.
constexpr void set_typo (std::optional< bool > typo) noexcept
 Sets whether the word is flagged as a typo.
constexpr void unset_typo () noexcept
 Unsets the typo flag.
Tokens
constexpr auto tokens () const noexcept
 View over the tokens covered by this word, in sentence order.
constexpr std::size_t num_tokens () const noexcept
 Number of tokens covered by this word.
constexpr bool contains_token (Token *token) const noexcept
 Checks whether a token belongs to this word.
constexpr bool contains_token_id (TokenId id) const noexcept
 Checks whether a token identifier belongs to this word.
State
constexpr std::error_code validate () const noexcept
 Checks the word for structural inconsistencies.
Destructor
constexpr ~Word () noexcept=default
 Destructor.

Detailed Description

A multiword token: a contiguous span of two or more Tokens sharing a single surface form.

Member Function Documentation

◆ contains_token()

bool tg::conllu::Word::contains_token ( Token * token) const
nodiscardconstexprnoexcept

Checks whether a token belongs to this word.

Parameters
[in]tokenToken to check.
Returns
True if token's identifier falls within this word's range.

◆ contains_token_id()

bool tg::conllu::Word::contains_token_id ( TokenId id) const
nodiscardconstexprnoexcept

Checks whether a token identifier belongs to this word.

Parameters
[in]idToken identifier to check.
Returns
True if id falls within this word's range.

◆ set_form()

std::error_code tg::conllu::Word::set_form ( const std::optional< std::string_view > & form)
constexprnoexcept

Sets the word form.

Parameters
[in]formNew form, or std::nullopt to unset it.
Returns
Empty error_code on success, or an error describing the failure.

◆ set_misc()

std::error_code tg::conllu::Word::set_misc ( const std::optional< std::string_view > & misc)
constexprnoexcept

Sets the word-level MISC field.

Parameters
[in]miscNew value, or std::nullopt to unset it.
Returns
Empty error_code on success, or an error describing the failure.

◆ set_range() [1/2]

std::error_code tg::conllu::Word::set_range ( Range range)
constexprnoexcept

Sets the token range covered by this word.

Parameters
[in]rangeNew range; must be valid for the owning sentence and must not overlap any other word in the sentence.
Returns
Empty error_code on success, or an error describing the failure.

◆ set_range() [2/2]

std::error_code tg::conllu::Word::set_range ( TokenId first,
TokenId last )
constexprnoexcept

Sets the token range covered by this word.

Parameters
[in]firstIdentifier of the first token in the range.
[in]lastIdentifier of the last token in the range.
Returns
Empty error_code on success, or an error describing the failure.

◆ set_typo()

void tg::conllu::Word::set_typo ( std::optional< bool > typo)
constexprnoexcept

Sets whether the word is flagged as a typo.

Parameters
[in]typoNew value, or std::nullopt to unset it.

◆ validate()

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

Checks the word 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: