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
lexicon_ngram
= 0x04,
// words of a lexicon ending here (SegmLexicon)
25
max_ngram_type
26
};
27
28
int8_t
m_offset
;
// from the current character
29
uint8_t
m_length
;
30
ngram_type_t
m_type
;
31
32
ngram_descr_t
(int8_t offset = 0, uint8_t length = 0,
ngram_type_t
type =
char_ngram
)
33
:
m_offset
(offset),
m_length
(length),
m_type
(type) {}
34
35
explicit
ngram_descr_t
(
const
std::string& serialized_form)
36
:
m_offset
(0),
m_length
(0),
m_type
(
char_ngram
)
37
{
38
from_string
(serialized_form);
39
}
40
41
friend
inline
bool
operator<
(
const
ngram_descr_t
& l,
const
ngram_descr_t
& r)
42
{
43
return
std::tie(l.
m_type
, l.
m_length
, l.
m_offset
) < std::tie(r.
m_type
, r.
m_length
, r.
m_offset
);
44
}
45
46
inline
bool
operator==
(
const
ngram_descr_t
& other)
47
{
48
return
(other.
m_type
==
m_type
) && (other.
m_length
==
m_length
) && (other.
m_offset
==
m_offset
);
49
}
50
51
std::string
to_string
()
const
52
{
53
std::ostringstream s;
54
s << (int)
m_type
<<
" "
<< (
int
)
m_length
<<
" "
<< (int)
m_offset
;
55
return
s.str();
56
}
57
58
void
from_string
(
const
std::string& str)
59
{
60
std::istringstream s(str);
61
int
temp = 0;
62
63
s >> temp;
64
assert(temp >= 0);
65
assert(temp <
ngram_descr_t::max_ngram_type
);
66
m_type
=
ngram_type_t
(temp);
67
68
s >> temp;
69
assert(temp > 0);
70
assert(temp < std::numeric_limits<uint8_t>::max());
71
m_length
= (uint8_t)temp;
72
73
s >> temp;
74
assert(temp > std::numeric_limits<int8_t>::min());
75
assert(temp < std::numeric_limits<int8_t>::max());
76
m_offset
= (int8_t)temp;
77
}
78
};
79
80
}
// namespace impl
81
}
// namespace segmentation
82
}
// namespace deeplima
83
84
#endif
deeplima::segmentation::impl
Definition
char_ngram.h:14
deeplima::segmentation
Definition
segmentation_eigen_inference_impl.h:22
deeplima
Edit rules for lemmatizing words absent from the lemma dictionary.
Definition
dependency_parser.h:28
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:32
deeplima::segmentation::impl::ngram_descr_t::m_offset
int8_t m_offset
Definition
char_ngram.h:28
deeplima::segmentation::impl::ngram_descr_t::m_type
ngram_type_t m_type
Definition
char_ngram.h:30
deeplima::segmentation::impl::ngram_descr_t::operator==
bool operator==(const ngram_descr_t &other)
Definition
char_ngram.h:46
deeplima::segmentation::impl::ngram_descr_t::to_string
std::string to_string() const
Definition
char_ngram.h:51
deeplima::segmentation::impl::ngram_descr_t::m_length
uint8_t m_length
Definition
char_ngram.h:29
deeplima::segmentation::impl::ngram_descr_t::ngram_descr_t
ngram_descr_t(const std::string &serialized_form)
Definition
char_ngram.h:35
deeplima::segmentation::impl::ngram_descr_t::operator<
friend bool operator<(const ngram_descr_t &l, const ngram_descr_t &r)
Definition
char_ngram.h:41
deeplima::segmentation::impl::ngram_descr_t::from_string
void from_string(const std::string &str)
Definition
char_ngram.h:58
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:25
deeplima::segmentation::impl::ngram_descr_t::lexicon_ngram
@ lexicon_ngram
Definition
char_ngram.h:24
deeplima
include
deeplima
segmentation
impl
char_ngram.h
Generated by
1.15.0