LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
token_type.h
Go to the documentation of this file.
1// Copyright 2021 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#ifndef DEEPLIMA_TOKEN_TYPE_H
7#define DEEPLIMA_TOKEN_TYPE_H
8
9#include <cassert>
10#include <cstdlib>
11#include <cstddef>
12#include <vector>
13#include <stdint.h>
14
15namespace deeplima
16{
17
18enum token_flags_t : uint8_t
19{
20 none = 0x00,
23 multiword = 0x04, // surface token of a multiword token, to be expanded into sub-words
25};
26
27namespace impl
28{
29struct token_t
30{
31
32 inline bool eos() const
33 {
34 return m_flags & sentence_brk;
35 }
36
37 token_t(uint16_t offset = 0, uint16_t len = 0, uint32_t idx = 0, token_flags_t flags = token_flags_t::none)
38 : m_offset(offset), m_len(len), m_form_idx(idx), m_flags(flags),
40
41 uint16_t m_offset; // offset from previous token end
42 uint16_t m_len; // length of this token in bytes
43 uint32_t m_form_idx;
45
46 // Multiword-token metadata propagated from segmentation::token_pos. On the
47 // first sub-word of an expanded surface token, m_mwt_len is the number of
48 // sub-words and m_mwt_surface_idx the StringIndex id of the surface form;
49 // both are 0 on normal tokens and non-first sub-words. Lets the CoNLL-U
50 // dumper emit the UD "N-M surface" range line.
51 uint8_t m_mwt_len;
53};
54}
55
56template <class T=impl::token_t>
57struct token_buffer_t : public std::vector<T>
58{
59protected:
60 uint32_t m_lock_count;
61
62public:
63 typedef std::vector<T> Parent;
64 typedef T token_t;
65
68
69 token_buffer_t(size_t size)
70 : Parent(size),
72 {
73 }
74
75 token_buffer_t(size_t size, const T& val)
76 : Parent(size, val),
78 {
79 }
80
81
82 inline bool locked() const
83 {
84 return m_lock_count > 0;
85 }
86
87 inline void lock()
88 {
90 }
91
92 inline void unlock()
93 {
94 assert(m_lock_count > 0);
96 }
97};
98
99} // namespace deeplima
100
101#endif
@ paragraph_brk
Definition token_type.h:22
@ sentence_brk
Definition token_type.h:21
token_flags_t m_flags
Definition token_type.h:44
token_t(uint16_t offset=0, uint16_t len=0, uint32_t idx=0, token_flags_t flags=token_flags_t::none)
Definition token_type.h:37
token_buffer_t(size_t size)
Definition token_type.h:69
std::vector< T > Parent
Definition token_type.h:63
token_buffer_t(size_t size, const T &val)
Definition token_type.h:75