LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
segmentation_impl.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_H
7#define DEEPLIMA_SEGMENTATION_IMPL_H
8
10
12
17
18// #include "config.h"
19
20#include <memory>
21
22#include "utf8_reader.h"
23#include "char_ngram_encoder.h"
26
27
28namespace deeplima
29{
30namespace segmentation
31{
32
34{
35public:
36 typedef std::function < bool (uint8_t* buffer,
37 int32_t& read,
38 int32_t max) > read_callback_t;
39
40 virtual void parse_from_stream(const read_callback_t fn) = 0;
41 virtual void register_handler(const segmentation_callback_t fn) = 0;
43 virtual void finalize() = 0;
44
48 virtual bool predicts_mwt() const { return false; }
49
50 virtual ~ISegmentation() { }
51};
52
53namespace eigen_impl
54{
57}
58
59namespace impl
60{
62
66
72{
73public:
74
76
77 // SegmentationImpl(
78 // const std::vector<ngram_descr_t>& ngram_descr,
79 // size_t threads,
80 // size_t buffer_size_per_thread
81 // );
82
83 virtual ~SegmentationImpl() = default;
84
85 virtual void load(const std::string& fn);
86
87 void init(size_t threads, size_t buffer_size_per_thread);
88
89 virtual void parse_from_stream(const read_callback_t fn) override;
90
91 virtual void register_handler(const segmentation_callback_t fn) override;
92
94 virtual void finalize() override;
95
100 virtual bool predicts_mwt() const override
101 {
102 const auto& dicts = this->get_output_str_dicts();
103 return !dicts.empty() && dicts[0].size() > size_t(segm_tag_t::max_segm_tag);
104 }
105
106protected:
107
108 void vectorize_timepoint(uint64_t timepoint);
109
110 void increment_timepoint(uint64_t& timepoint);
111
112 void send_results(int32_t slot_idx);
113
114 void send_next_results();
115
116 void acquire_slot();
117
118 void handle_timepoint();
119
120 void no_more_data();
121
122protected:
123 std::vector<uint8_t> m_char_len;
124
127 // The word list of the lexicon feature, <model>.lex, when the model uses it
128 std::shared_ptr<SegmLexicon> m_lexicon;
129
132
135
138};
139
140} // namespace impl
141} // namespace segmentation
142} // namespace deeplima
143
144#endif
Handles multithreading.
virtual void finalize()=0
Cleanup all remaining locks if any.
virtual void register_handler(const segmentation_callback_t fn)=0
std::function< bool(uint8_t *buffer, int32_t &read, int32_t max) > read_callback_t
virtual void parse_from_stream(const read_callback_t fn)=0
virtual bool predicts_mwt() const
Whether this segmenter predicts multiword-token surfaces (sets the token_flags_t::multiword flag).
virtual void parse_from_stream(const read_callback_t fn) override
virtual bool predicts_mwt() const override
MWT-aware iff the model has more than the base segmentation tag classes (i.e.
virtual void register_handler(const segmentation_callback_t fn) override
virtual void finalize() override
Cleanup all remaining locks if any.
void init(size_t threads, size_t buffer_size_per_thread)
virtual void load(const std::string &fn)
DictEmbdVectorizer< EmbdUInt64FloatHolder, EmbdUInt64Float, eigen_wrp::EigenMatrixXf > EmbdVectorizer
impl::SegmentationInferenceWrapper< BiRnnEigenInferenceForSegmentation > Model
CharNgramEncoder< Utf8Reader<> > CharNgramEncoderFromUtf8
RnnSequenceClassifier< eigen_impl::Model, eigen_impl::EmbdVectorizer, uint8_t > SegmentationClassifier
SegmentationDecoder OutputDecoder
CharNgramEncoderFromUtf8 InputEncoder
std::function< void(const std::vector< token_pos > &tokens, uint32_t len) > segmentation_callback_t
Edit rules for lemmatizing words absent from the lemma dictionary.