15#ifndef TG_CONLLU_WORD_HPP
16#define TG_CONLLU_WORD_HPP 1
18#include "conllu/token.hpp"
48 [[nodiscard]]
constexpr std::size_t
count() const noexcept;
66 [[nodiscard]] constexpr
bool equals(
Range range) const noexcept;
71 [[nodiscard]] constexpr
bool is_valid() const noexcept;
82 std::optional<std::string> form_{std::nullopt};
83 std::optional<std::string> misc_{std::nullopt};
84 std::optional<bool> typo_{std::nullopt};
86 Sentence* sentence_{
nullptr};
88 explicit(
true)
constexpr Word(Sentence* sentence)
noexcept;
90 friend class Sentence;
101 constexpr Word() noexcept = delete;
137 [[nodiscard]] constexpr std::optional<std::string_view>
get_form() const noexcept;
143 constexpr std::error_code
set_form(const std::optional<std::string_view>& form) noexcept;
156 [[nodiscard]] constexpr std::optional<std::string_view>
get_misc() const noexcept;
162 constexpr std::error_code
set_misc(const std::optional<std::string_view>& misc) noexcept;
175 [[nodiscard]] constexpr std::optional<
bool>
get_typo() const noexcept;
180 constexpr
void set_typo(std::optional<
bool> typo) noexcept;
193 [[nodiscard]] constexpr auto
tokens() const noexcept;
197 [[nodiscard]] constexpr std::
size_t num_tokens() const noexcept;
219 [[nodiscard]] constexpr std::error_code
validate() const noexcept;
228 constexpr ~Word() noexcept = default;
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
constexpr std::error_code validate() const noexcept
Checks the word for structural inconsistencies.
constexpr Word() noexcept=delete
Default construction is disabled; words are created via Sentence::add_word.
constexpr std::error_code set_form(const std::optional< std::string_view > &form) noexcept
Sets the word form.
constexpr std::error_code set_misc(const std::optional< std::string_view > &misc) noexcept
Sets the word-level MISC field.
constexpr TokenId last_id() const noexcept
Identifier of the last token in the word's range.
constexpr void set_typo(std::optional< bool > typo) noexcept
Sets whether the word is flagged as a typo.
constexpr std::optional< std::string_view > get_form() const noexcept
Word form (surface form of the multiword token).
constexpr void unset_misc() noexcept
Unsets the word-level MISC field.
constexpr void unset_typo() noexcept
Unsets the typo flag.
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.
constexpr std::size_t num_tokens() const noexcept
Number of tokens covered by this word.
constexpr auto tokens() const noexcept
View over the tokens covered by this word, in sentence order.
constexpr std::error_code set_range(Range range) noexcept
Sets the token range covered by this word.
constexpr std::optional< bool > get_typo() const noexcept
Whether the word is flagged as a typo.
constexpr std::optional< std::string_view > get_misc() const noexcept
Word-level MISC field.
constexpr void unset_form() noexcept
Unsets the word form.
constexpr TokenId first_id() const noexcept
Identifier of the first token in the word's range.
std::uint64_t TokenId
Identifier for a token or empty node within a sentence.
Definition token.hpp:36
A closed, inclusive interval of Tokens' identifiers, spanning [first, last].
Definition word.hpp:34
constexpr bool is_valid() const noexcept
Checks whether the range is well-formed on its own.
constexpr bool equals(Range range) const noexcept
Checks whether this range has the same bounds as another range.
TokenId first
Identifier of the first token in the range.
Definition word.hpp:38
constexpr std::size_t count() const noexcept
Number of tokens covered by the range.
constexpr bool overlaps(Range range) const noexcept
Checks whether this range shares any token identifier with another range.
TokenId last
Identifier of the last token in the range.
Definition word.hpp:42
constexpr bool contains(TokenId id) const noexcept
Checks whether a token identifier falls within the range.