LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
char_ngram.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_SEGMENTATION_IMPL_CHAR_NGRAM_H
7
#define DEEPLIMA_SEGMENTATION_IMPL_CHAR_NGRAM_H
8
9
namespace
deeplima
10
{
11
namespace
segmentation
12
{
13
namespace
impl
14
{
15
16
struct
ngram_descr_t
17
{
18
enum
ngram_type_t
: uint8_t
19
{
20
char_ngram
= 0x00,
21
type_ngram
= 0x01,
22
len_ngram
= 0x02,
23
script_ngram
= 0x03,
24
max_ngram_type
25
};
26
27
int8_t
m_offset
;
// from the current character
28
uint8_t
m_length
;
29
ngram_type_t
m_type
;
30
31
ngram_descr_t
(int8_t offset = 0, uint8_t length = 0,
ngram_type_t
type =
char_ngram
)
32
:
m_offset
(offset),
m_length
(length),
m_type
(type) {}
33
34
explicit
ngram_descr_t
(
const
std::string& serialized_form)
35
:
m_offset
(0),
m_length
(0),
m_type
(
char_ngram
)
36
{
37
from_string
(serialized_form);
38
}
39
40
friend
inline
bool
operator<
(
const
ngram_descr_t
& l,
const
ngram_descr_t
& r)
41
{
42
return
std::tie(l.
m_type
, l.
m_length
, l.
m_offset
) < std::tie(r.
m_type
, r.
m_length
, r.
m_offset
);
43
}
44
45
inline
bool
operator==
(
const
ngram_descr_t
& other)
46
{
47
return
(other.
m_type
==
m_type
) && (other.
m_length
==
m_length
) && (other.
m_offset
==
m_offset
);
48
}
49
50
std::string
to_string
()
const
51
{
52
std::ostringstream s;
53
s << (int)
m_type
<<
" "
<< (
int
)
m_length
<<
" "
<< (int)
m_offset
;
54
return
s.str();
55
}
56
57
void
from_string
(
const
std::string& str)
58
{
59
std::istringstream s(str);
60
int
temp = 0;
61
62
s >> temp;
63
assert(temp >= 0);
64
assert(temp <
ngram_descr_t::max_ngram_type
);
65
m_type
=
ngram_type_t
(temp);
66
67
s >> temp;
68
assert(temp > 0);
69
assert(temp < std::numeric_limits<uint8_t>::max());
70
m_length
= (uint8_t)temp;
71
72
s >> temp;
73
assert(temp > std::numeric_limits<int8_t>::min());
74
assert(temp < std::numeric_limits<int8_t>::max());
75
m_offset
= (int8_t)temp;
76
}
77
};
78
79
}
// namespace impl
80
}
// namespace segmentation
81
}
// namespace deeplima
82
83
#endif
deeplima
Definition
dependency_parser.h:28
deeplima::segmentation::impl::ngram_descr_t
Definition
char_ngram.h:17
deeplima::segmentation::impl::ngram_descr_t::ngram_descr_t
ngram_descr_t(int8_t offset=0, uint8_t length=0, ngram_type_t type=char_ngram)
Definition
char_ngram.h:31
deeplima::segmentation::impl::ngram_descr_t::m_offset
int8_t m_offset
Definition
char_ngram.h:27
deeplima::segmentation::impl::ngram_descr_t::m_type
ngram_type_t m_type
Definition
char_ngram.h:29
deeplima::segmentation::impl::ngram_descr_t::operator==
bool operator==(const ngram_descr_t &other)
Definition
char_ngram.h:45
deeplima::segmentation::impl::ngram_descr_t::to_string
std::string to_string() const
Definition
char_ngram.h:50
deeplima::segmentation::impl::ngram_descr_t::m_length
uint8_t m_length
Definition
char_ngram.h:28
deeplima::segmentation::impl::ngram_descr_t::ngram_descr_t
ngram_descr_t(const std::string &serialized_form)
Definition
char_ngram.h:34
deeplima::segmentation::impl::ngram_descr_t::operator<
friend bool operator<(const ngram_descr_t &l, const ngram_descr_t &r)
Definition
char_ngram.h:40
deeplima::segmentation::impl::ngram_descr_t::from_string
void from_string(const std::string &str)
Definition
char_ngram.h:57
deeplima::segmentation::impl::ngram_descr_t::ngram_type_t
ngram_type_t
Definition
char_ngram.h:19
deeplima::segmentation::impl::ngram_descr_t::len_ngram
@ len_ngram
Definition
char_ngram.h:22
deeplima::segmentation::impl::ngram_descr_t::char_ngram
@ char_ngram
Definition
char_ngram.h:20
deeplima::segmentation::impl::ngram_descr_t::type_ngram
@ type_ngram
Definition
char_ngram.h:21
deeplima::segmentation::impl::ngram_descr_t::script_ngram
@ script_ngram
Definition
char_ngram.h:23
deeplima::segmentation::impl::ngram_descr_t::max_ngram_type
@ max_ngram_type
Definition
char_ngram.h:24
deeplima
include
deeplima
segmentation
impl
char_ngram.h
Generated by
1.9.8