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
15
namespace
deeplima
16
{
17
18
enum
token_flags_t
: uint8_t
19
{
20
none
= 0x00,
21
sentence_brk
= 0x01,
22
paragraph_brk
= 0x02,
23
multiword
= 0x04,
// surface token of a multiword token, to be expanded into sub-words
24
max_flags
25
};
26
27
namespace
impl
28
{
29
struct
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),
39
m_mwt_len
(0),
m_mwt_surface_idx
(0) { }
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
;
44
token_flags_t
m_flags
;
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
;
52
uint32_t
m_mwt_surface_idx
;
53
};
54
}
55
56
template
<
class
T=impl::token_t>
57
struct
token_buffer_t
:
public
std::vector<T>
58
{
59
protected
:
60
uint32_t
m_lock_count
;
61
62
public
:
63
typedef
std::vector<T>
Parent
;
64
typedef
T
token_t
;
65
66
token_buffer_t
()
67
:
m_lock_count
(0) { }
68
69
token_buffer_t
(
size_t
size)
70
:
Parent
(size),
71
m_lock_count
(0)
72
{
73
}
74
75
token_buffer_t
(
size_t
size,
const
T& val)
76
:
Parent
(size, val),
77
m_lock_count
(0)
78
{
79
}
80
81
82
inline
bool
locked
()
const
83
{
84
return
m_lock_count
> 0;
85
}
86
87
inline
void
lock
()
88
{
89
m_lock_count
++;
90
}
91
92
inline
void
unlock
()
93
{
94
assert(
m_lock_count
> 0);
95
m_lock_count
--;
96
}
97
};
98
99
}
// namespace deeplima
100
101
#endif
deeplima
Definition
dependency_parser.h:28
deeplima::token_flags_t
token_flags_t
Definition
token_type.h:19
deeplima::multiword
@ multiword
Definition
token_type.h:23
deeplima::max_flags
@ max_flags
Definition
token_type.h:24
deeplima::paragraph_brk
@ paragraph_brk
Definition
token_type.h:22
deeplima::sentence_brk
@ sentence_brk
Definition
token_type.h:21
deeplima::none
@ none
Definition
token_type.h:20
deeplima::impl::token_t
Definition
token_type.h:30
deeplima::impl::token_t::m_form_idx
uint32_t m_form_idx
Definition
token_type.h:43
deeplima::impl::token_t::m_flags
token_flags_t m_flags
Definition
token_type.h:44
deeplima::impl::token_t::eos
bool eos() const
Definition
token_type.h:32
deeplima::impl::token_t::m_mwt_len
uint8_t m_mwt_len
Definition
token_type.h:51
deeplima::impl::token_t::m_mwt_surface_idx
uint32_t m_mwt_surface_idx
Definition
token_type.h:52
deeplima::impl::token_t::token_t
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
deeplima::impl::token_t::m_offset
uint16_t m_offset
Definition
token_type.h:41
deeplima::impl::token_t::m_len
uint16_t m_len
Definition
token_type.h:42
deeplima::token_buffer_t
Definition
token_type.h:58
deeplima::token_buffer_t::token_buffer_t
token_buffer_t(size_t size)
Definition
token_type.h:69
deeplima::token_buffer_t::Parent
std::vector< T > Parent
Definition
token_type.h:63
deeplima::token_buffer_t::locked
bool locked() const
Definition
token_type.h:82
deeplima::token_buffer_t::m_lock_count
uint32_t m_lock_count
Definition
token_type.h:60
deeplima::token_buffer_t::token_buffer_t
token_buffer_t(size_t size, const T &val)
Definition
token_type.h:75
deeplima::token_buffer_t::unlock
void unlock()
Definition
token_type.h:92
deeplima::token_buffer_t::token_t
T token_t
Definition
token_type.h:64
deeplima::token_buffer_t::token_buffer_t
token_buffer_t()
Definition
token_type.h:66
deeplima::token_buffer_t::lock
void lock()
Definition
token_type.h:87
deeplima
include
deeplima
token_type.h
Generated by
1.9.8